defines.dart 966 B

1234567891011121314151617181920212223242526272829303132333435
  1. import 'package:get/get.dart';
  2. ///状态模块构建函数声明
  3. typedef StateModuleBuilder<T extends StateModuleBase> = T Function();
  4. ///持久化状态
  5. abstract class PersistentalbeState {
  6. /// 转换为持久存储Json
  7. Map<String, dynamic> toPersistenceJson();
  8. /// 接收持久存储Json
  9. Future<void> acceptPersistenceJson(Map<String, dynamic> map);
  10. }
  11. ///对持久化的map支撑字典进行相关扩展
  12. extension PersistentPropPickerEx on Map<String, dynamic> {
  13. void pickPersistentProp(String key, void Function(dynamic value) fn) {
  14. if (!containsKey(key)) return;
  15. final value = this[key];
  16. if (value == null) return;
  17. fn(value);
  18. }
  19. void pickPersistentProps(Map<String, void Function(dynamic value)> fnMaps) {
  20. for (var key in fnMaps.keys) {
  21. pickPersistentProp(key, (value) {
  22. fnMaps[key]?.call(value);
  23. });
  24. }
  25. }
  26. }
  27. abstract class StateModuleBase extends GetxService
  28. implements PersistentalbeState {}