mine_controller.dart 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import 'package:flutter/rendering.dart';
  2. import 'package:get/get.dart';
  3. import 'package:get/get_core/src/get_main.dart';
  4. import 'package:injectable/injectable.dart';
  5. import 'package:keyboard/base/base_controller.dart';
  6. import 'package:keyboard/module/about/about_page.dart';
  7. import 'package:keyboard/module/feedback/feedback_page.dart';
  8. import '../../data/consts/error_code.dart';
  9. import '../../data/repository/account_repository.dart';
  10. import '../../resource/string.gen.dart';
  11. import '../../utils/http_handler.dart';
  12. import '../../utils/toast_util.dart';
  13. import '../store/store_page.dart';
  14. @injectable
  15. class MineController extends BaseController {
  16. final AccountRepository accountRepository;
  17. MineController(this.accountRepository);
  18. bool get isLogin => accountRepository.isLogin.value;
  19. String? get phone => accountRepository.loginPhoneNum.value;
  20. String getUserName() {
  21. if (isLogin || phone != null && phone!.length > 4) {
  22. return '${StringName.mineAccountLoggedDesc}${phone!.substring(phone!.length - 4)}';
  23. } else {
  24. return StringName.mineAccountNoLogin;
  25. }
  26. }
  27. clickVip() {
  28. debugPrint('clickVip');
  29. StorePage.start();
  30. }
  31. clickOnlineCustomerService() {
  32. debugPrint('clickOnlineCustomerService');
  33. accountRepository
  34. .loginUserLogin("11223344551", "1122")
  35. .then((data) {
  36. Get.back();
  37. ToastUtil.show(StringName.loginSuccess);
  38. })
  39. .catchError((error) {
  40. if (error is LoginTooOftenException) {
  41. ToastUtil.show(StringName.loginTooOftenToast);
  42. return;
  43. }
  44. if (error is ServerErrorException) {
  45. if (error.code == ErrorCode.verificationCodeError) {
  46. ToastUtil.show(StringName.loginVerificationCodeErrorToast);
  47. } else {
  48. ToastUtil.show(error.message);
  49. }
  50. } else {
  51. ToastUtil.show(StringName.loginFailedToast);
  52. }
  53. });
  54. }
  55. clickTutorials() {
  56. debugPrint('clickTutorials');
  57. }
  58. clickPersonalProfile() {
  59. debugPrint('clickPersonalProfile');
  60. accountRepository.setUserInfo(name: "老铁",birthday: "2021-03-17",gender: 1,hobbies: ["a","b","c"],characters: ["测试"]);
  61. }
  62. clickFeedback() {
  63. debugPrint('clickFeedback');
  64. FeedbackPage.start();
  65. }
  66. clickAboutUs() {
  67. debugPrint('clickAboutUs');
  68. AboutPage.start();
  69. }
  70. }