mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 23:34:24 +01:00
opt.: use json_serializable
This commit is contained in:
@@ -1,11 +1,14 @@
|
||||
import 'package:hive_flutter/hive_flutter.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'private_key_info.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
@HiveType(typeId: 1)
|
||||
class PrivateKeyInfo {
|
||||
@HiveField(0)
|
||||
final String id;
|
||||
@JsonKey(name: 'private_key')
|
||||
@HiveField(1)
|
||||
final String key;
|
||||
|
||||
@@ -14,6 +17,11 @@ class PrivateKeyInfo {
|
||||
required this.key,
|
||||
});
|
||||
|
||||
factory PrivateKeyInfo.fromJson(Map<String, dynamic> json) =>
|
||||
_$PrivateKeyInfoFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$PrivateKeyInfoToJson(this);
|
||||
|
||||
String? get type {
|
||||
final lines = key.split('\n');
|
||||
if (lines.length < 2) {
|
||||
@@ -26,15 +34,4 @@ class PrivateKeyInfo {
|
||||
}
|
||||
return splited[1];
|
||||
}
|
||||
|
||||
PrivateKeyInfo.fromJson(Map<String, dynamic> json)
|
||||
: id = json['id'].toString(),
|
||||
key = json['private_key'].toString();
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final data = <String, String>{};
|
||||
data['id'] = id;
|
||||
data['private_key'] = key;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user