webview可以跳轉到h5,可以也可以自定義
#flutter官方webview
webview_flutter: ^0.3.10
///初始化webview显示 Widget _showWebView(BuildContext context) { return WebView( initialUrl: widget.url,///初始化url javascriptMode: JavascriptMode.unrestricted,///JS执行模式 onWebViewCreated: (WebViewController webViewController) {///在WebView创建完成后调用,只会被调用一次 // // _controller.complete(webViewController); }, javascriptChannels: <JavascriptChannel>[///JS和Flutter通信的Channel; _alertJavascriptChannel(context), ].toSet(), navigationDelegate: (NavigationRequest request) {//路由委托(可以通过在此处拦截url实现JS调用Flutter部分); ///通过拦截url来实现js与flutter交互 if (request.url.startsWith(‘js://webview‘)) { Fluttertoast.showToast(msg:‘JS调用了Flutter By navigationDelegate‘); print(‘blocking navigation to $request}‘); return NavigationDecision.prevent;///阻止路由替换,不能跳转,因为这是js交互给我们发送的消息 } return NavigationDecision.navigate;///允许路由替换 }, onPageFinished: (String url) {///页面加载完成回调 setState(() { _loading = false; }); print(‘Page finished loading: $url‘); }, ); }
更詳細的使用方法請訪問pub.dev