初始化项目
This commit is contained in:
34
lib/controller/main_bottom/main_page_controller.dart
Normal file
34
lib/controller/main_bottom/main_page_controller.dart
Normal file
@@ -0,0 +1,34 @@
|
||||
import 'package:ef/ef.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'main_page_controller.g.dart'; // 由json_serializable自动生成的部分
|
||||
|
||||
@JsonSerializable()
|
||||
class MainPageModel {
|
||||
int currentIndex = 0;
|
||||
MainPageModel();
|
||||
|
||||
// 从JSON反序列化时的异常处理
|
||||
|
||||
factory MainPageModel.fromJson(Map<String, dynamic> json) {
|
||||
try {
|
||||
return _$MainPageModelFromJson(json);
|
||||
} catch (e) {
|
||||
// 在实际应用中,应该有更细致的异常处理策略和错误日志
|
||||
return MainPageModel(); // 或者返回一个带有错误信息的特定DeviceInfoModel实例
|
||||
}
|
||||
}
|
||||
|
||||
// 序列化为JSON时的异常处理
|
||||
Map<String, dynamic> toJson() => _$MainPageModelToJson(this);
|
||||
}
|
||||
|
||||
class MainPageController extends GetControllerEx<MainPageModel> {
|
||||
MainPageController() {
|
||||
attr = GetModel(MainPageModel()).obs;
|
||||
}
|
||||
|
||||
resetParm() {
|
||||
model.currentIndex = 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user