|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- typedef Future InitMethod();
-
- typedef Future StringParamsMethod(data);
-
- class Application {
- // 初始化方法
- static List<InitMethod> _initMethods = List();
-
- ///有标签的方法用于没有页面的第三模块调用
- static Map<String, InitMethod> _initStringMethods = Map();
-
- static Map<String, StringParamsMethod> _initStringParamsMethods = Map();
-
- static Future init() async {
- for (InitMethod method in _initMethods) {
- await method();
- }
-
- return Future.delayed(Duration.zero);
- }
-
- static addMethod(InitMethod method) {
- _initMethods.add(method);
- }
-
- static addStringMethod({String type, InitMethod method}) {
- if (type == null || method == null) {
- return;
- }
- _initStringMethods[type] = method;
- }
-
- static bool hasStringMethod(String type) {
- return _initStringMethods.containsKey(type);
- }
-
- static Future doStringMethod(String type) {
- if (_initStringMethods.containsKey(type)) {
- print("存在方法" + type);
- return _initStringMethods[type]();
- }
- print("不存在方法" + type);
- return Future(() => false);
- }
-
- static addStringParamsMethod({String type, StringParamsMethod method}) {
- if (type == null || method == null) {
- return;
- }
- _initStringParamsMethods[type] = method;
- }
-
- static Future doStringParamsMethod(String type, {Map<String, dynamic> data}) {
- if (_initStringParamsMethods.containsKey(type)) {
- print("存在方法" + type);
- return _initStringParamsMethods[type](data);
- }
- print("不存在方法" + type);
- return Future(() => false);
- }
- }
|