Files
flutter_server_box/lib/data/model/server/server_private_info.dart
lollipopkit 5a5e2fd1d1 #73 fix & opt.
- fix: reorder list default drag
- opt.: android home widget grey text
2023-07-20 18:26:17 +08:00

61 lines
1.4 KiB
Dart

import 'package:hive_flutter/hive_flutter.dart';
part 'server_private_info.g.dart';
@HiveType(typeId: 3)
class ServerPrivateInfo {
@HiveField(0)
late String name;
@HiveField(1)
late String ip;
@HiveField(2)
late int port;
@HiveField(3)
late String user;
@HiveField(4)
late String pwd;
@HiveField(5)
String? pubKeyId;
@HiveField(6)
List<String>? tags;
late String id;
ServerPrivateInfo({
required this.name,
required this.ip,
required this.port,
required this.user,
required this.pwd,
this.pubKeyId,
this.tags,
}) : id = '$name<$user@$ip:$port>';
ServerPrivateInfo.fromJson(Map<String, dynamic> json) {
name = json["name"].toString();
ip = json["ip"].toString();
port = int.tryParse(json["port"]) ?? 22;
user = json["user"].toString();
pwd = json["authorization"].toString();
pubKeyId = json["pubKeyId"]?.toString();
id = '$user@$ip:$port';
tags = json["tags"]?.cast<String>();
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
data["name"] = name;
data["ip"] = ip;
data["port"] = port;
data["user"] = user;
data["authorization"] = pwd;
data["pubKeyId"] = pubKeyId;
data["tags"] = tags;
return data;
}
bool shouldReconnect(ServerPrivateInfo old) {
return id != old.id || pwd != old.pwd || pubKeyId != old.pubKeyId;
}
}