defines.dart 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import 'package:fis_common/logger/logger.dart';
  2. import 'package:flutter/foundation.dart';
  3. import 'package:get/get.dart';
  4. import '../store/modules/app.dart';
  5. import '../store/store.dart';
  6. typedef AsyncVoidCallback = Future<void> Function();
  7. extension RxExt<T> on Rx<T> {
  8. /// 更新值
  9. void updateValue(T newValue) {
  10. if (newValue != value) {
  11. value = newValue;
  12. }
  13. }
  14. }
  15. abstract class FControllerBase extends GetxController {
  16. final AppState appState = Store.app;
  17. bool get busy => appState.busy;
  18. set busy(v) => appState.busy = v;
  19. void setBusy(String text) => appState.setBusy(text);
  20. void cancelBusy() => busy = false;
  21. Future<void> busyHandle(AsyncVoidCallback callback, {String? text}) async {
  22. if (text != null) {
  23. setBusy(text);
  24. } else {
  25. busy = true;
  26. }
  27. try {
  28. await callback();
  29. } catch (e) {
  30. logger.e("Unhandled page busy error", e);
  31. }
  32. busy = false;
  33. }
  34. @override
  35. void onReady() {
  36. super.onReady();
  37. busy = true;
  38. onLoad().then((_) {
  39. busy = false;
  40. });
  41. }
  42. @protected
  43. Future<void> onLoad() async {}
  44. }