defines.dart 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import 'package:fis_common/logger/logger.dart';
  2. import 'package:fis_ui/interface/interactive_container.dart';
  3. import 'package:flutter/foundation.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:get/get.dart';
  6. import 'package:vitalapp/architecture/utils/prompt_box.dart';
  7. import '../store/modules/app.dart';
  8. import '../store/store.dart';
  9. typedef AsyncVoidCallback = Future<void> Function();
  10. extension RxExt<T> on Rx<T> {
  11. /// 更新值
  12. void updateValue(T newValue) {
  13. if (newValue != value) {
  14. value = newValue;
  15. }
  16. }
  17. }
  18. abstract class FControllerBase extends GetxController {
  19. final AppState appState = Store.app;
  20. bool get busy => appState.busy;
  21. set busy(v) => appState.busy = v;
  22. void setBusy(String text) => appState.setBusy(text);
  23. void cancelBusy() => busy = false;
  24. Future<void> busyHandle(AsyncVoidCallback callback, {String? text}) async {
  25. if (text != null) {
  26. setBusy(text);
  27. } else {
  28. busy = true;
  29. }
  30. try {
  31. await callback();
  32. } catch (e) {
  33. logger.e("Unhandled page busy error", e);
  34. }
  35. busy = false;
  36. }
  37. /// toast提示
  38. void toast(String message) => PromptBox.toast(message);
  39. @override
  40. void onReady() {
  41. super.onReady();
  42. busy = true;
  43. onLoad().then((_) {
  44. busy = false;
  45. });
  46. }
  47. @protected
  48. Future<void> onLoad() async {}
  49. }
  50. /// 虚拟页面组件
  51. class FVirtualPageWidget extends Container implements FInteractiveContainer {
  52. /// 仅限全局场景使用
  53. static final FVirtualPageWidget global = FVirtualPageWidget("Global");
  54. late final String _pageName;
  55. FVirtualPageWidget(String name) {
  56. _pageName = name;
  57. }
  58. @override
  59. String get pageName => _pageName;
  60. }