feedback_controller.dart 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:injectable/injectable.dart';
  3. import 'package:keyboard/base/base_controller.dart';
  4. import 'package:keyboard/data/repository/account_repository.dart';
  5. import 'package:get/get.dart';
  6. import '../../resource/string.gen.dart';
  7. import '../../utils/error_handler.dart';
  8. import '../../utils/toast_util.dart';
  9. @injectable
  10. class FeedbackController extends BaseController {
  11. final RxString _phone = ''.obs;
  12. final RxString _content = "".obs;
  13. get phone => _phone.value;
  14. get content => _content.value;
  15. final AccountRepository accountRepository;
  16. FeedbackController(this.accountRepository);
  17. onPhoneChanged(String phone) {
  18. _phone.value = phone;
  19. }
  20. onContentChanged(String content) {
  21. _content.value = content;
  22. }
  23. backClick() {
  24. debugPrint("backClick");
  25. Get.back();
  26. }
  27. submitClick() {
  28. if (_content.value.isEmpty) {
  29. ToastUtil.show(StringName.feedbackContentEmpty);
  30. return;
  31. }
  32. if (_phone.value.isEmpty) {
  33. ToastUtil.show(StringName.feedbackPhoneEmpty);
  34. return;
  35. }
  36. accountRepository
  37. .complaintSubmit(_phone.value, _content.value)
  38. .then((data) {
  39. ToastUtil.show(StringName.feedbackSubmitSuccess);
  40. Get.back();
  41. })
  42. .catchError((error) {
  43. ErrorHandler.toastError(error);
  44. });
  45. }
  46. }