From da167fd67e21b2cff12c21c8647411bcb77226bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cyanghuaxuan=E2=80=9D?= <“646903573@qq.com”> Date: Wed, 21 Apr 2021 20:16:07 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E6=B7=BB=E5=8A=A0=E8=B7=B3=E8=BD=AC?= =?UTF-8?q?=E5=8E=9F=E7=94=9Fwebview=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/workspace.xml | 39 ++++++++++++++++++++++----------------- lib/util/application.dart | 36 ++++++++++++++++++++++++++++-------- lib/util/router_util.dart | 11 +++++++---- 3 files changed, 57 insertions(+), 29 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index e7c17d5..16d70ea 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -20,16 +20,10 @@ - - - - - - - - + + + + + + + + + + - @@ -478,7 +479,6 @@ - @@ -489,7 +489,6 @@ - @@ -500,7 +499,6 @@ - @@ -508,10 +506,6 @@ - - - - @@ -519,8 +513,19 @@ - + + + + + + + + + + + + diff --git a/lib/util/application.dart b/lib/util/application.dart index 6ee6174..4db473d 100644 --- a/lib/util/application.dart +++ b/lib/util/application.dart @@ -1,5 +1,7 @@ typedef Future InitMethod(); +typedef Future StringParamsMethod(data); + class Application { // 初始化方法 static List _initMethods = List(); @@ -7,6 +9,8 @@ class Application { ///有标签的方法用于没有页面的第三模块调用 static Map _initStringMethods = Map(); + static Map _initStringParamsMethods = Map(); + static Future init() async { for (InitMethod method in _initMethods) { await method(); @@ -20,22 +24,38 @@ class Application { } static addStringMethod({String type, InitMethod method}) { - if(type==null||method==null){ + if (type == null || method == null) { return; } _initStringMethods[type] = method; } - static bool hasStringMethod(String type){ - return _initStringMethods.containsKey(type); + static bool hasStringMethod(String type) { + return _initStringMethods.containsKey(type); } - static doStringMethod(String type){ - if(_initStringMethods.containsKey(type)){ - print("存在方法"+type); + static doStringMethod(String type) { + if (_initStringMethods.containsKey(type)) { + print("存在方法" + type); _initStringMethods[type](); - }else{ - print("不存在方法"+type); + } else { + print("不存在方法" + type); + } + } + + static addStringParamsMethod({String type , StringParamsMethod method}) { + if (type == null || method == null) { + return; + } + _initStringParamsMethods[type] = method; + } + + static doStringParamsMethod(String type, {Map data}) { + if (_initStringParamsMethods.containsKey(type)) { + print("存在方法" + type); + _initStringParamsMethods[type](data); + } else { + print("不存在方法" + type); } } } diff --git a/lib/util/router_util.dart b/lib/util/router_util.dart index 9f0edbc..97e1bc9 100644 --- a/lib/util/router_util.dart +++ b/lib/util/router_util.dart @@ -16,7 +16,6 @@ class RouterUtil { * data 额外参数 * */ static Future route(SkipModel skipModel, Map data, BuildContext context) async { - if (skipModel.skipIdentifier == null || skipModel.skipIdentifier == '') { print('skipIdentifier 参数不存在,无法跳转页面'); return Future.error('skipIdentifier 参数不存在,无法跳转页面'); @@ -37,8 +36,7 @@ class RouterUtil { } if (skipModel?.requiredTaobaoAuth == '1') { - UserInfoModel user = - await Provider.of(context, listen: false).getUserInfoModel(); + UserInfoModel user = await Provider.of(context, listen: false).getUserInfoModel(); if (!user?.isTBAuth ?? false) { TaobaoAuth.auth(context); return; @@ -47,7 +45,7 @@ class RouterUtil { // webView if (skipModel?.skipIdentifier == 'pub.flutter.url') { - this.openWebview(skipModel?.url, context); + RouterUtil.openWebview(skipModel?.url, context); return; } @@ -86,9 +84,14 @@ class RouterUtil { Logger.error('跳转链接不能为空'); return Future.error('跳转链接不能为空'); } + SkipModel model = SkipModel(); model.skipIdentifier = 'pub.flutter.url'; model.url = url; + if (Platform.isAndroid) { + Application.doStringParamsMethod("openUrl", data: {"url": model.url}); + return null; + } RouterUtil.route(model, model.toJson(), context); }