You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.6 KiB
59 lines
1.6 KiB
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
import '../../../data/services/network/api.dart';
|
|
|
|
class FeedbackController extends GetxController {
|
|
final TextEditingController feedbackController = TextEditingController();
|
|
//final TextEditingController contactController = TextEditingController();
|
|
|
|
final RxBool isSubmitting = false.obs;
|
|
final GlobalKey<FormState> formKey = GlobalKey<FormState>();
|
|
|
|
@override
|
|
void onClose() {
|
|
feedbackController.dispose();
|
|
//contactController.dispose();
|
|
super.onClose();
|
|
}
|
|
|
|
// 提交反馈
|
|
Future<void> submitFeedback() async {
|
|
if (!formKey.currentState!.validate()) {
|
|
return;
|
|
}
|
|
|
|
isSubmitting.value = true;
|
|
|
|
try {
|
|
final feedbackText = feedbackController.text;
|
|
Map<String, dynamic> data = {
|
|
"message": feedbackText, // 反馈内容
|
|
};
|
|
|
|
final response = await Api.feedback(data);
|
|
|
|
if (response != null) {
|
|
Get.back(); // 返回上一页
|
|
Get.snackbar(
|
|
'success'.tr, // 成功
|
|
'feedbackSubmitSuccess'.tr, // 反馈提交成功
|
|
snackPosition: SnackPosition.BOTTOM,
|
|
backgroundColor: Colors.green.withOpacity(0.7),
|
|
colorText: Colors.white,
|
|
margin: const EdgeInsets.all(10),
|
|
);
|
|
}
|
|
} catch (e) {
|
|
Get.snackbar(
|
|
'error'.tr, // 错误
|
|
'feedbackSubmitFailed'.tr, // 反馈提交失败
|
|
snackPosition: SnackPosition.BOTTOM,
|
|
backgroundColor: Colors.red.withOpacity(0.7),
|
|
colorText: Colors.white,
|
|
margin: const EdgeInsets.all(10),
|
|
);
|
|
} finally {
|
|
isSubmitting.value = false;
|
|
}
|
|
}
|
|
}
|
|
|