final Completer加载html字符串_controller = Completer (); int _progressValue = 0; @override void initState() { super.initState(); // Enable hybrid composition. if (Device.isAndroid) { WebView.platform = SurfaceAndroidWebView(); } } @override Widget build(BuildContext context) { return Scaffold( body: Stack( children: [ WebView( initialUrl: "https://www.baidu.com", javascriptMode: JavascriptMode.unrestricted, allowsInlineMediaPlayback: true, onWebViewCreated: (WebViewController webViewController) { _controller.complete(webViewController); }, onProgress: (int progress) { debugPrint('WebView is loading (progress : $progress%)'); setState(() { _progressValue = progress; }); }, ), if (_progressValue != 100) LinearProgressIndicator( value: _progressValue / 100, backgroundColor: Colors.transparent, minHeight: 2, ) else Gaps.empty, ], ), ); }
String html = """
html字符串加载
""";
return Scaffold(
appBar: AppBar(title: Text(widget.messageItem.title)),
body: WebView(
javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (WebViewController controller) {
controller.loadHtmlString(html);
},
),
);



