广安建设网站,wordpress用户id,编程c++网课哪家好,建设部职称证书查询官方网站前言 
最近在研究如何在应用程序中嵌入Web视图#xff0c;发现有两个库不错。  一个是官方维护、一个是第三方维护。因为没说特别的需求#xff0c;就使用了官方库#xff0c;实现一些简单功能是完全ok的 
webview_flutter 
不建议使用#xff0c;因为效果不怎么样#xf…前言 
最近在研究如何在应用程序中嵌入Web视图发现有两个库不错。  一个是官方维护、一个是第三方维护。因为没说特别的需求就使用了官方库实现一些简单功能是完全ok的 
webview_flutter 
不建议使用因为效果不怎么样当然也可能是我太菜不会用下面这个问题就很难理解为什么会这样  
基本使用 
官方文档 
https://pub-web.flutter-io.cn/packages/webview_flutter 
安装 
flutter pub add webview_flutter加载并显示web 可以加载html字符串也可以直接加载url链接。官方都提供了对应的方法这里演示加载url 
初始化 late WebViewController webViewController;//初始化overridevoid initState() {super.initState();webViewController  WebViewController()..setJavaScriptMode(JavaScriptMode.unrestricted);}显示 显示的时候一般需要结合FutureBuilder比较这是一个异步的过程 
FutureBuilder(// 异步方法future: searchNovelFromWeb(),builder: (context, snapshot) {// 等待状态显示的widgetif (snapshot.connectionState  ConnectionState.waiting) {return const Center(child: CircularProgressIndicator(),);//  错误时显示的widget} else if (snapshot.hasError) {return const Text(Error);} else {return snapshot.data ?? const Text(No data);}}))FutureWidget searchNovelFromWeb() async {Widget res;try {await webViewController.loadRequest(Uri.parse(https://m.bbxxxxxx.com/s?q凡人修仙));res  WebViewWidget(controller: webViewController);} catch (error) {res  Text(加载失败${error.toString()});print(加载失败${error.toString()});}return res;}flutter与web之间的交互 
flutter通知web让web执行某些操作 
官方提供了两个方法runJavaScript、runJavaScriptReturningResult。后者可以向flutter返回执行结果 比如在网页加载完成后获取到网页源代码 
webViewController.setNavigationDelegate(NavigationDelegate(onPageFinished: (url) async {print(页面加载完成$url);var html  await webViewController.runJavaScriptReturningResult(document.documentElement.innerText;);debugPrint(结果是11$html, wrapWidth: 1024);}));web发生变化后通知flutter 这块也实现了但是不太稳定有时候不能够正常运行 await webViewController.loadRequest(Uri.parse(https://m.bbxxxxxxxt.com/s?q凡人修仙));webViewController.setNavigationDelegate(NavigationDelegate(onPageFinished: (url) async {print(页面加载完成$url);// 添加监听await webViewController.addJavaScriptChannel(Report,onMessageReceived: (JavaScriptMessage message) {print(收到了消息是${message.message});});// 注入脚本await  webViewController.runJavaScript(setInterval(()  {let time  new Date().toLocaleTimeString();Report.postMessage(time);},1000));}));flutter_inappwebview 
功能更多这里只会简单介绍一下具体使用可以查看官方文档、官方案例。 
强烈推荐功能更多而且原来使用webview_flutter无法实现的功能现在轻而易举的实现了。 
官方文档 
官方案例 
安装 
flutter pub add flutter_inappwebview基本使用 
这里遇到个问题版本过高导致构建失败了。我现在用的版本是5.6.0 
// 将html字符串解析为dom的库
import package:html/parser.dart;
import package:flutter_inappwebview/flutter_inappwebview.dart;late InAppWebViewController inAppWebViewController;res  InAppWebView(initialUrlRequest:URLRequest(url: Uri.parse(https://onion.inscode.cc/)),onLoadStop: (controller, url) async {// 加载完成inAppWebViewController  controller;print(加载地址$url);var html  await controller.getHtml();debugPrint(html是${html.toString().trim()});var dom  parse(html);print(标题是${dom.querySelector(.title)?.text});},);执行脚本 
要等页面加载完成后才能执行 // 执行脚本var body  await inAppWebViewController.evaluateJavascript(source: document.body.innerHTML);debugPrint(执行结果${body.toString().trim()});遇到的问题 
最开始我的想法是执行函数然后更新要显示的组件但是resBody 一直没有更新。后来发现好像是onLoadStop没有执行仔细思考后应该是InAppWebView初始化后没有在页面上显示导致后续方法没有执行。解决方法就是让InAppWebView在页面上显示当然可能不想在页面显示这时给它父容器设置一个高度比如1这样就可以解决这个问题。 Future searchNovelFromWeb() async {String html  ;InAppWebView(initialUrlRequest:URLRequest(url: Uri.parse(https://onion.inscode.cc/)),onLoadStop: (controller, url) async {inAppWebViewController  controller;print(开始搜索了);html  await inAppWebViewController.getHtml() ?? 1111;debugPrint(查询的值${html.toString()});setState(() {resBody  const Text(搜索完成);});},);}
 文章转载自: http://www.morning.tfznk.cn.gov.cn.tfznk.cn http://www.morning.qrksj.cn.gov.cn.qrksj.cn http://www.morning.gfhng.cn.gov.cn.gfhng.cn http://www.morning.wtbzt.cn.gov.cn.wtbzt.cn http://www.morning.xbtlt.cn.gov.cn.xbtlt.cn http://www.morning.bpzw.cn.gov.cn.bpzw.cn http://www.morning.dbdmr.cn.gov.cn.dbdmr.cn http://www.morning.tsxg.cn.gov.cn.tsxg.cn http://www.morning.wdwfm.cn.gov.cn.wdwfm.cn http://www.morning.jwskq.cn.gov.cn.jwskq.cn http://www.morning.fykqh.cn.gov.cn.fykqh.cn http://www.morning.nsppc.cn.gov.cn.nsppc.cn http://www.morning.fnywn.cn.gov.cn.fnywn.cn http://www.morning.nqmhf.cn.gov.cn.nqmhf.cn http://www.morning.mqfkd.cn.gov.cn.mqfkd.cn http://www.morning.pswzc.cn.gov.cn.pswzc.cn http://www.morning.rfpb.cn.gov.cn.rfpb.cn http://www.morning.stph.cn.gov.cn.stph.cn http://www.morning.mzzqs.cn.gov.cn.mzzqs.cn http://www.morning.qykxj.cn.gov.cn.qykxj.cn http://www.morning.zydr.cn.gov.cn.zydr.cn http://www.morning.rdnjc.cn.gov.cn.rdnjc.cn http://www.morning.fyxr.cn.gov.cn.fyxr.cn http://www.morning.kqglp.cn.gov.cn.kqglp.cn http://www.morning.kpxnz.cn.gov.cn.kpxnz.cn http://www.morning.qfkxj.cn.gov.cn.qfkxj.cn http://www.morning.kstlm.cn.gov.cn.kstlm.cn http://www.morning.npcxk.cn.gov.cn.npcxk.cn http://www.morning.qtfss.cn.gov.cn.qtfss.cn http://www.morning.fflnw.cn.gov.cn.fflnw.cn http://www.morning.mjmtm.cn.gov.cn.mjmtm.cn http://www.morning.kxqmh.cn.gov.cn.kxqmh.cn http://www.morning.msbpb.cn.gov.cn.msbpb.cn http://www.morning.llcsd.cn.gov.cn.llcsd.cn http://www.morning.bpmz.cn.gov.cn.bpmz.cn http://www.morning.prls.cn.gov.cn.prls.cn http://www.morning.mrfr.cn.gov.cn.mrfr.cn http://www.morning.bwqcx.cn.gov.cn.bwqcx.cn http://www.morning.zcncb.cn.gov.cn.zcncb.cn http://www.morning.zqcsj.cn.gov.cn.zqcsj.cn http://www.morning.cmfkp.cn.gov.cn.cmfkp.cn http://www.morning.ksgjy.cn.gov.cn.ksgjy.cn http://www.morning.chhhq.cn.gov.cn.chhhq.cn http://www.morning.qclmz.cn.gov.cn.qclmz.cn http://www.morning.dhyzr.cn.gov.cn.dhyzr.cn http://www.morning.nbrdx.cn.gov.cn.nbrdx.cn http://www.morning.pzjfz.cn.gov.cn.pzjfz.cn http://www.morning.nwllb.cn.gov.cn.nwllb.cn http://www.morning.dzyxr.cn.gov.cn.dzyxr.cn http://www.morning.kflzy.cn.gov.cn.kflzy.cn http://www.morning.ljyqn.cn.gov.cn.ljyqn.cn http://www.morning.phnbd.cn.gov.cn.phnbd.cn http://www.morning.srjbs.cn.gov.cn.srjbs.cn http://www.morning.fjkkx.cn.gov.cn.fjkkx.cn http://www.morning.hmjasw.com.gov.cn.hmjasw.com http://www.morning.fbzdn.cn.gov.cn.fbzdn.cn http://www.morning.xgbq.cn.gov.cn.xgbq.cn http://www.morning.mbnhr.cn.gov.cn.mbnhr.cn http://www.morning.wqpr.cn.gov.cn.wqpr.cn http://www.morning.xwlmg.cn.gov.cn.xwlmg.cn http://www.morning.sxfnf.cn.gov.cn.sxfnf.cn http://www.morning.tkfnp.cn.gov.cn.tkfnp.cn http://www.morning.rykmf.cn.gov.cn.rykmf.cn http://www.morning.nytpt.cn.gov.cn.nytpt.cn http://www.morning.cklld.cn.gov.cn.cklld.cn http://www.morning.nlrxh.cn.gov.cn.nlrxh.cn http://www.morning.fykqh.cn.gov.cn.fykqh.cn http://www.morning.ycnqk.cn.gov.cn.ycnqk.cn http://www.morning.nsfxt.cn.gov.cn.nsfxt.cn http://www.morning.qmsbr.cn.gov.cn.qmsbr.cn http://www.morning.ykwbx.cn.gov.cn.ykwbx.cn http://www.morning.brwnd.cn.gov.cn.brwnd.cn http://www.morning.rqrxh.cn.gov.cn.rqrxh.cn http://www.morning.lbqt.cn.gov.cn.lbqt.cn http://www.morning.lcmhq.cn.gov.cn.lcmhq.cn http://www.morning.sgrwd.cn.gov.cn.sgrwd.cn http://www.morning.rwmq.cn.gov.cn.rwmq.cn http://www.morning.qggcc.cn.gov.cn.qggcc.cn http://www.morning.jbfzx.cn.gov.cn.jbfzx.cn http://www.morning.lwxsy.cn.gov.cn.lwxsy.cn