|
- typedef Future InitMethod();
-
- class Application {
- // 初始化方法
- static List<InitMethod> _initMethods = List();
-
- ///有标签的方法用于没有页面的第三模块调用
- static Map<String, InitMethod> _initStringMethods = 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 doStringMethod(String type){
- if(_initStringMethods.containsKey(type)){
- print("存在方法"+type);
- _initStringMethods[type]();
- }else{
- print("不存在方法"+type);
- }
- }
- }
|