defines.dart 1.2 KB

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