Files
flutter_server_box/lib/data/model/server/private_key_info.dart
lollipopkit🏳️‍⚧️ 7ce3854392 opt.: use json_serializable
2024-08-15 16:44:13 +08:00

38 lines
830 B
Dart

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;
const PrivateKeyInfo({
required this.id,
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) {
return null;
}
final firstLine = lines[0];
final splited = firstLine.split(RegExp(r'\s+'));
if (splited.length < 2) {
return null;
}
return splited[1];
}
}