基础库
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 

62 rindas
1.6 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 Future doStringMethod(String type) {
  28. if (_initStringMethods.containsKey(type)) {
  29. print("存在方法" + type);
  30. return _initStringMethods[type]();
  31. }
  32. print("不存在方法" + type);
  33. return Future(() => false);
  34. }
  35. static addStringParamsMethod({String type, StringParamsMethod method}) {
  36. if (type == null || method == null) {
  37. return;
  38. }
  39. _initStringParamsMethods[type] = method;
  40. }
  41. static Future doStringParamsMethod(String type, {Map<String, dynamic> data}) {
  42. if (_initStringParamsMethods.containsKey(type)) {
  43. print("存在方法" + type);
  44. return _initStringParamsMethods[type](data);
  45. }
  46. print("不存在方法" + type);
  47. return Future(() => false);
  48. }
  49. }