更新
This commit is contained in:
33
lib/controller/sleep/sleep_report_controller.dart
Normal file
33
lib/controller/sleep/sleep_report_controller.dart
Normal file
@@ -0,0 +1,33 @@
|
||||
import 'package:ef/ef.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'sleep_report_controller.g.dart'; // 由json_serializable自动生成的部分
|
||||
|
||||
@JsonSerializable()
|
||||
class SleepReportModel {
|
||||
int? type = 1; //报告类型 1:日报 2.周报 3.月报
|
||||
|
||||
SleepReportModel();
|
||||
|
||||
// 从JSON反序列化时的异常处理
|
||||
|
||||
factory SleepReportModel.fromJson(Map<String, dynamic> json) {
|
||||
try {
|
||||
return _$SleepReportModelFromJson(json);
|
||||
} catch (e) {
|
||||
// 在实际应用中,应该有更细致的异常处理策略和错误日志
|
||||
return SleepReportModel(); // 或者返回一个带有错误信息的特定DeviceInfoModel实例
|
||||
}
|
||||
}
|
||||
|
||||
// 序列化为JSON时的异常处理
|
||||
Map<String, dynamic> toJson() => _$SleepReportModelToJson(this);
|
||||
}
|
||||
|
||||
class SleepReportController extends GetControllerEx<SleepReportModel> {
|
||||
|
||||
Rx<DateTime?> selectedDate = Rx<DateTime?>(null);
|
||||
SleepReportController() {
|
||||
attr = GetModel(SleepReportModel()).obs;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user