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