controller.dart 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import 'package:app_settings/app_settings.dart';
  2. import 'package:get/get.dart';
  3. import '../../../common/routers/index.dart';
  4. import '../../../common/services/index.dart';
  5. import '../../../common/utils/index.dart';
  6. import '../../../common/widgets/index.dart';
  7. import 'index.dart';
  8. class SettingsController extends GetxController {
  9. SettingsController();
  10. final state = SettingsState();
  11. final eventBus = EventBus();
  12. final _eventId = 'Settings';
  13. /// 在 widget 内存中分配后立即调用。
  14. @override
  15. void onInit() {
  16. super.onInit();
  17. }
  18. /// 在 onInit() 之后调用 1 帧。这是进入的理想场所
  19. @override
  20. void onReady() {
  21. eventBus.on(EventBus.avatarUpdateMsg, _eventId, (arg) {
  22. OLogger.d('修改头像后刷新');
  23. state.dn = O2ApiManager.instance.o2User?.distinguishedName ?? '';
  24. });
  25. eventBus.on(EventBus.mySignatureUpdateMsg, _eventId, (arg) {
  26. OLogger.d('修改签名后刷新');
  27. state.personSign = O2ApiManager.instance.o2User?.signature ?? '';
  28. });
  29. state.personName = O2ApiManager.instance.o2User?.name ?? '';
  30. state.personSign = O2ApiManager.instance.o2User?.signature ?? '';
  31. super.onReady();
  32. }
  33. /// 在 [onDelete] 方法之前调用。
  34. @override
  35. void onClose() {
  36. eventBus.off(EventBus.avatarUpdateMsg, _eventId);
  37. eventBus.off(EventBus.mySignatureUpdateMsg, _eventId);
  38. super.onClose();
  39. }
  40. /// dispose 释放内存
  41. @override
  42. void dispose() {
  43. super.dispose();
  44. }
  45. ///
  46. /// 消息通知设置
  47. ///
  48. void clickOpenNotifySettings() {
  49. if (GetPlatform.isMobile) {
  50. AppSettings.openNotificationSettings();
  51. }
  52. }
  53. void clickLogs() {
  54. Get.toNamed(O2OARoutes.homeSettingsLogs);
  55. }
  56. void clickAbout() {
  57. Get.toNamed(O2OARoutes.homeSettingsAbout);
  58. }
  59. void longPressAbout() async {
  60. final isDebugger = SharedPreferenceService.to.getBool(SharedPreferenceService.webviewDebuggerKey);
  61. await SharedPreferenceService.to.putBool(SharedPreferenceService.webviewDebuggerKey, !isDebugger);
  62. if (isDebugger) {
  63. Loading.toast('common_debugger_close'.tr);
  64. } else {
  65. Loading.toast('common_debugger_open'.tr);
  66. }
  67. }
  68. /// 通用
  69. gotoCommon() {
  70. Get.toNamed(O2OARoutes.homeSettingsCommon);
  71. }
  72. ///
  73. /// 退出登录
  74. ///
  75. void clickLogout() async {
  76. OLogger.d("退出登录");
  77. O2UI.showConfirm(Get.context, 'settings_logout_confirm_message'.tr, okPressed: ()=> O2Utils.logout());
  78. }
  79. }