|
|
@ -8,10 +8,10 @@ import 'package:problem_check_system/data/models/enum_model.dart'; |
|
|
|
import 'package:problem_check_system/data/models/image_metadata_model.dart'; |
|
|
|
import 'package:problem_check_system/data/models/image_metadata_model.dart'; |
|
|
|
import 'dart:io'; |
|
|
|
import 'dart:io'; |
|
|
|
import 'package:problem_check_system/data/models/problem_model.dart'; |
|
|
|
import 'package:problem_check_system/data/models/problem_model.dart'; |
|
|
|
import 'problem_controller.dart'; |
|
|
|
import 'package:problem_check_system/data/repositories/problem_repository.dart'; |
|
|
|
|
|
|
|
|
|
|
|
class ProblemFormController extends GetxController { |
|
|
|
class ProblemFormController extends GetxController { |
|
|
|
final ProblemController problemController; |
|
|
|
final ProblemRepository problemRepository; |
|
|
|
final TextEditingController descriptionController = TextEditingController(); |
|
|
|
final TextEditingController descriptionController = TextEditingController(); |
|
|
|
final TextEditingController locationController = TextEditingController(); |
|
|
|
final TextEditingController locationController = TextEditingController(); |
|
|
|
final RxList<XFile> selectedImages = <XFile>[].obs; |
|
|
|
final RxList<XFile> selectedImages = <XFile>[].obs; |
|
|
@ -21,7 +21,7 @@ class ProblemFormController extends GetxController { |
|
|
|
Problem? _currentProblem; |
|
|
|
Problem? _currentProblem; |
|
|
|
|
|
|
|
|
|
|
|
// 使用依赖注入,便于测试 |
|
|
|
// 使用依赖注入,便于测试 |
|
|
|
ProblemFormController({required this.problemController}); |
|
|
|
ProblemFormController({required this.problemRepository}); |
|
|
|
|
|
|
|
|
|
|
|
/// 初始化方法,用于加载现有问题数据 |
|
|
|
/// 初始化方法,用于加载现有问题数据 |
|
|
|
void init(Problem? problem) { |
|
|
|
void init(Problem? problem) { |
|
|
@ -153,7 +153,7 @@ class ProblemFormController extends GetxController { |
|
|
|
creationTime: DateTime.now(), // 更新编辑时间 |
|
|
|
creationTime: DateTime.now(), // 更新编辑时间 |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
await problemController.updateProblem(updatedProblem); |
|
|
|
await problemRepository.updateProblem(updatedProblem); |
|
|
|
Get.back(result: true); // 返回成功结果 |
|
|
|
Get.back(result: true); // 返回成功结果 |
|
|
|
Get.snackbar('成功', '问题已更新'); |
|
|
|
Get.snackbar('成功', '问题已更新'); |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -163,10 +163,9 @@ class ProblemFormController extends GetxController { |
|
|
|
location: locationController.text, |
|
|
|
location: locationController.text, |
|
|
|
imageUrls: imagePaths, |
|
|
|
imageUrls: imagePaths, |
|
|
|
creationTime: DateTime.now(), |
|
|
|
creationTime: DateTime.now(), |
|
|
|
syncStatus: SyncStatus.synced, |
|
|
|
|
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
await problemController.addProblem(problem); |
|
|
|
await problemRepository.insertProblem(problem); |
|
|
|
Get.back(result: true); // 返回成功结果 |
|
|
|
Get.back(result: true); // 返回成功结果 |
|
|
|
Get.snackbar('成功', '问题已保存'); |
|
|
|
Get.snackbar('成功', '问题已保存'); |
|
|
|
} |
|
|
|
} |
|
|
|