Open yecheng223 opened 3 years ago
_onStateChanged = _flutterWebViewPlugin.onStateChanged.listen(_webViewStateChanged);
void _webViewStateChanged(WebViewStateChanged event) { switch (event.type) { case WebViewState.startLoad: _onPageStart(event.url); break; case WebViewState.finishLoad: _onPageEnd(event.url); break; case WebViewState.shouldStart: wtPrint("_webviewplugin eventurl : ${event.url}"); if (Platform.isAndroid) { return; } String prefix = "https://wx.tenpay.com/cgi-bin/mmpayweb-bin/checkmweb"; if (event.url.startsWith(prefix)) { Uri uri = WTRouter().parseURLScheme(urlStr: event.url)!; Map<String, String> par = Map.from(uri.queryParameters); if (par['redirect_url'] == null || (par['redirect_url']!.contains("h5.canyahn.cn") && !par['redirect_url']!.startsWith(GlobalField.scheme))) { par['redirect_url'] = GlobalField.scheme + "web?url=${WTEncryptUtil.urlEncode(par['redirect_url'])}"; String url = uri.replace(queryParameters: par).toString(); _flutterWebViewPlugin.stopLoading(); _flutterWebViewPlugin .reloadUrl(url, headers: {"Referer": GlobalField.scheme}); } return; } break; case WebViewState.abortLoad: wtPrint("_webviewplugin abortLoad : ${event.url}"); if (_isPageInApp(event.url)) { _openPageInApp(event.url); } else { String url = event.url; if (Platform.isIOS && url.contains("alipay://alipayclient/")) { url = Uri.decodeFull(url); List list = url.split("?"); String json = list.last; Map<String, dynamic> map = jsonDecode(json); map['fromAppUrlScheme'] = GlobalField.scheme; json = jsonEncode(map); list.last = Uri.encodeFull(json); url = list.join("?"); WTRouter.openApp(schemeUrl: url); } else { routerOpenUrl(context: context, urlStr: event.url); } } break; } }
me too,onStateChanged don't work
_onStateChanged = _flutterWebViewPlugin.onStateChanged.listen(_webViewStateChanged);
void _webViewStateChanged(WebViewStateChanged event) { switch (event.type) { case WebViewState.startLoad: _onPageStart(event.url); break; case WebViewState.finishLoad: _onPageEnd(event.url); break; case WebViewState.shouldStart: wtPrint("_webviewplugin eventurl : ${event.url}"); if (Platform.isAndroid) { return; } String prefix = "https://wx.tenpay.com/cgi-bin/mmpayweb-bin/checkmweb"; if (event.url.startsWith(prefix)) { Uri uri = WTRouter().parseURLScheme(urlStr: event.url)!; Map<String, String> par = Map.from(uri.queryParameters); if (par['redirect_url'] == null || (par['redirect_url']!.contains("h5.canyahn.cn") && !par['redirect_url']!.startsWith(GlobalField.scheme))) { par['redirect_url'] = GlobalField.scheme + "web?url=${WTEncryptUtil.urlEncode(par['redirect_url'])}"; String url = uri.replace(queryParameters: par).toString(); _flutterWebViewPlugin.stopLoading(); _flutterWebViewPlugin .reloadUrl(url, headers: {"Referer": GlobalField.scheme}); } return; } break; case WebViewState.abortLoad: wtPrint("_webviewplugin abortLoad : ${event.url}"); if (_isPageInApp(event.url)) { _openPageInApp(event.url); } else { String url = event.url; if (Platform.isIOS && url.contains("alipay://alipayclient/")) { url = Uri.decodeFull(url); List list = url.split("?");
String json = list.last;
Map<String, dynamic> map = jsonDecode(json);
map['fromAppUrlScheme'] = GlobalField.scheme;
json = jsonEncode(map);
list.last = Uri.encodeFull(json);
url = list.join("?");
WTRouter.openApp(schemeUrl: url);
} else {
routerOpenUrl(context: context, urlStr: event.url);
}
}
break;
}
}