fluttercommunity / flutter_webview_plugin

Community WebView Plugin - Allows Flutter to communicate with a native WebView.
https://pub.dev/packages/flutter_webview_plugin
Other
1.48k stars 929 forks source link

升级0.4.0后flutterWebViewPlugin.onStateChanged.listen设置回调不生效 #934

Open yecheng223 opened 2 years ago

yecheng223 commented 2 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; } }

coreki commented 2 years ago

me too,onStateChanged don't work

tulioccalazans commented 2 years ago

me too,onStateChanged don't work

solomoapp commented 1 year ago

me too,onStateChanged don't work