38 lines
1.1 KiB
Dart
38 lines
1.1 KiB
Dart
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);
|
|
RxMap<String, dynamic> sleepReport = <String, dynamic>{}.obs;
|
|
RxBool isLoading = false.obs;
|
|
|
|
// 每种类型对应一份数据
|
|
|
|
SleepReportController() {
|
|
attr = GetModel(SleepReportModel()).obs;
|
|
}
|
|
}
|