setting_controller.dart 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
  2. import 'package:get/get.dart';
  3. import 'package:plugin_platform/engine/directory/directory_util.dart';
  4. import 'package:shared/utils/util.dart';
  5. import 'package:widgets/dialog/app_default_dialog.dart';
  6. import 'setting_state.dart';
  7. class SettingController extends GetxController {
  8. final SettingState state = SettingState();
  9. /// 退出登录的弹窗
  10. Future<void> showLogoutDialog() async {
  11. SmartDialog.show(
  12. usePenetrate: false,
  13. keepSingle :true,
  14. builder: (context) =>
  15. AppDefaultDialog(
  16. "你确定你要退出登录吗?".tr,
  17. confirmAction: () {
  18. // 调用接口退出登录
  19. _userLogout();
  20. },
  21. ),
  22. );
  23. }
  24. /// 调用接口退出登录
  25. void _userLogout() async {
  26. // SmartDialog.showLoading();
  27. // HttpResult result = await mainRepository.userLogout();
  28. // SmartDialog.dismiss(status: SmartStatus.loading);
  29. //
  30. // //处理数据
  31. // if (result.isSuccess) {
  32. // Log.d("退出登录 => 成功");
  33. // UserService.to.handleLogoutParams();
  34. // Get.offAllNamed(RouterPath.AUTH_LOGIN); //关闭全部页面进入登录页面,不能改
  35. // } else {
  36. // Log.d("退出登录 => 失败:${result.errorMsg}");
  37. // }
  38. }
  39. @override
  40. void onReady() {
  41. super.onReady();
  42. calculateCacheSize();
  43. }
  44. //计算当前 App 的 Cache 缓存
  45. void calculateCacheSize() async {
  46. final size = await DirectoryUtil.getAppCacheSize();
  47. state.appSize = DirectoryUtil.formatBytes(size);
  48. update();
  49. }
  50. //清除缓存
  51. void clearCache() async {
  52. SmartDialog.show(
  53. usePenetrate: false,
  54. builder: (context) => AppDefaultDialog(
  55. "你确定你要清除应用缓存吗?".tr,
  56. confirmAction: () async {
  57. await DirectoryUtil.clearAppCache();
  58. state.appSize = '0 B';
  59. update();
  60. },
  61. ),
  62. );
  63. }
  64. }