更新页面
This commit is contained in:
33
lib/controller/person/person_controller.dart
Normal file
33
lib/controller/person/person_controller.dart
Normal file
@@ -0,0 +1,33 @@
|
||||
import 'package:ef/ef.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'person_controller.g.dart'; // 由json_serializable自动生成的部分
|
||||
|
||||
@JsonSerializable()
|
||||
class PersonModel {
|
||||
int read = 1;
|
||||
|
||||
DateTime? birthday;//是否不再提示教程 0 不再提示 1 需要提示
|
||||
|
||||
PersonModel();
|
||||
|
||||
// 从JSON反序列化时的异常处理
|
||||
|
||||
factory PersonModel.fromJson(Map<String, dynamic> json) {
|
||||
try {
|
||||
return _$PersonModelFromJson(json);
|
||||
} catch (e) {
|
||||
// 在实际应用中,应该有更细致的异常处理策略和错误日志
|
||||
return PersonModel(); // 或者返回一个带有错误信息的特定DeviceInfoModel实例
|
||||
}
|
||||
}
|
||||
|
||||
// 序列化为JSON时的异常处理
|
||||
Map<String, dynamic> toJson() => _$PersonModelToJson(this);
|
||||
}
|
||||
|
||||
class PersonController extends GetControllerEx<PersonModel> {
|
||||
PersonController() {
|
||||
attr = GetModel(PersonModel()).obs;
|
||||
}
|
||||
}
|
||||
19
lib/controller/person/person_controller.g.dart
Normal file
19
lib/controller/person/person_controller.g.dart
Normal file
@@ -0,0 +1,19 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'person_controller.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
PersonModel _$PersonModelFromJson(Map<String, dynamic> json) => PersonModel()
|
||||
..read = (json['read'] as num).toInt()
|
||||
..birthday = json['birthday'] == null
|
||||
? null
|
||||
: DateTime.parse(json['birthday'] as String);
|
||||
|
||||
Map<String, dynamic> _$PersonModelToJson(PersonModel instance) =>
|
||||
<String, dynamic>{
|
||||
'read': instance.read,
|
||||
'birthday': instance.birthday?.toIso8601String(),
|
||||
};
|
||||
Reference in New Issue
Block a user