import 'package:flutter/cupertino.dart';
import 'package:hive_flutter/adapters.dart';
import 'hive.dart';
@HiveType(typeId: 1)
class MClient {
@HiveField(0)
String? clientId;
@HiveField(1)
String? host;
@HiveField(2)
String? port;
@HiveField(3)
String? user;
@HiveField(4)
String? password;
MClient({this.clientId, this.host, this.port, this.user, this.password});
}
class MClientAdapter extends TypeAdapter<MClient> {
@override
final typeId = 0;
@override
MClient read(BinaryReader reader) {
return MClient()
..clientId = reader.read()
..host = reader.read()
..password = reader.read()
..user = reader.read()
..password = reader.read();
}
@override
void write(BinaryWriter writer, MClient obj) {
writer.write(obj.clientId);
writer.write(obj.host);
writer.write(obj.port);
writer.write(obj.user);
writer.write(obj.password);
}
}
void clientCreate(clientId, host, port, user, password) {
var cc = MClient(
clientId: clientId,
host: host,
port: port,
user: user,
password: password);
MClients.put(clientId, cc);
}
MClient? clientGet(clientId) {
if (MClients.get(clientId) != null) {
var cc1 = MClients.get(clientId);
return cc1;
} else {
return null;
}
}
List<MClient> clientGetList() {
var res = MClients.values.toList();
List<MClient> cc = res.cast<MClient>();
debugPrint("查到list: $cc");
return cc;
}
void clientDel(clientId) {
MClients.delete(clientId);
}