setting_controller.dart 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import 'package:get/get.dart';
  2. import '../../../../config/translations/strings_enum.dart';
  3. import '../../../../utils/awesome_notifications_helper.dart';
  4. import '../../../controllers/api_controller.dart';
  5. import '../../../dialog/loading/loading_dialog.dart';
  6. class SettingController extends GetxController {
  7. final apiController = Get.find<ApiController>();
  8. // 自动重连开关
  9. final _autoReconnect = true.obs;
  10. bool get autoReconnect => _autoReconnect.value;
  11. set autoReconnect(bool value) => _autoReconnect.value = value;
  12. final _pushNotifications = false.obs;
  13. bool get pushNotifications => _pushNotifications.value;
  14. set pushNotifications(bool value) => _pushNotifications.value = value;
  15. @override
  16. void onInit() {
  17. super.onInit();
  18. _initPushNotifications();
  19. }
  20. Future<void> _initPushNotifications() async {
  21. pushNotifications =
  22. await AwesomeNotificationsHelper.checkNotificationPermission();
  23. }
  24. Future<void> showNotificationConfigPage() async {
  25. await AwesomeNotificationsHelper.showNotificationConfigPage();
  26. _initPushNotifications();
  27. }
  28. // 处理退出登录
  29. Future<void> handleLogout() async {
  30. await LoadingDialog.show(
  31. context: Get.context!,
  32. loadingText: Strings.loggingOut.tr,
  33. successText: Strings.logoutSuccessful.tr,
  34. onRequest: () async {
  35. // 执行你的异步请求
  36. await apiController.logout();
  37. },
  38. onSuccess: () {
  39. // 成功后的操作
  40. Get.back();
  41. },
  42. );
  43. }
  44. // 处理删除账户
  45. Future<void> handleDeleteAccount() async {
  46. await LoadingDialog.show(
  47. context: Get.context!,
  48. loadingText: Strings.deletingAccount.tr,
  49. successText: Strings.deleteAccountSuccessful.tr,
  50. onRequest: () async {
  51. // 执行你的异步请求
  52. await apiController.deleteAccount();
  53. },
  54. onSuccess: () {
  55. // 成功后的操作
  56. Get.back();
  57. },
  58. );
  59. }
  60. }