基础库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

62 lines
1.5 KiB

  1. typedef Future InitMethod();
  2. typedef Future StringParamsMethod(data);
  3. class Application {
  4. // 初始化方法
  5. static List<InitMethod> _initMethods = List();
  6. ///有标签的方法用于没有页面的第三模块调用
  7. static Map<String, InitMethod> _initStringMethods = Map();
  8. static Map<String, StringParamsMethod> _initStringParamsMethods = Map();
  9. static Future init() async {
  10. for (InitMethod method in _initMethods) {
  11. await method();
  12. }
  13. return Future.delayed(Duration.zero);
  14. }
  15. static addMethod(InitMethod method) {
  16. _initMethods.add(method);
  17. }
  18. static addStringMethod({String type, InitMethod method}) {
  19. if (type == null || method == null) {
  20. return;
  21. }
  22. _initStringMethods[type] = method;
  23. }
  24. static bool hasStringMethod(String type) {
  25. return _initStringMethods.containsKey(type);
  26. }
  27. static doStringMethod(String type) {
  28. if (_initStringMethods.containsKey(type)) {
  29. print("存在方法" + type);
  30. _initStringMethods[type]();
  31. } else {
  32. print("不存在方法" + type);
  33. }
  34. }
  35. static addStringParamsMethod({String type , StringParamsMethod method}) {
  36. if (type == null || method == null) {
  37. return;
  38. }
  39. _initStringParamsMethods[type] = method;
  40. }
  41. static doStringParamsMethod(String type, {Map<String, dynamic> data}) {
  42. if (_initStringParamsMethods.containsKey(type)) {
  43. print("存在方法" + type);
  44. _initStringParamsMethods[type](data);
  45. } else {
  46. print("不存在方法" + type);
  47. }
  48. }
  49. }