当前位置:网站首页>Flutter WebView示例
Flutter WebView示例
2022-07-04 20:35:00 【海阔天空6688】
加载url
final Completer<WebViewController> _controller = Completer<WebViewController>();
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,
],
),
);
}
加载html字符串
String html = """
<!DOCTYPE html>
<html>
<head><meta name="viewport" content="width=device-width, initial-scale=1.0"></head>
<body>
<p>html字符串加载</p>
</body>
</html>
""";
return Scaffold(
appBar: AppBar(title: Text(widget.messageItem.title)),
body: WebView(
javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (WebViewController controller) {
controller.loadHtmlString(html);
},
),
);
边栏推荐
- Jerry's ad series MIDI function description [chapter]
- Advantages of RFID warehouse management system solution
- LambdaQueryWrapper用法
- 杰理之AD 系列 MIDI 功能说明【篇】
- Jerry added the process of turning off the touch module before turning it off [chapter]
- 刘锦程荣获2022年度中国电商行业创新人物奖
- async await 在map中使用
- In the release version, the random white screen does not display the content after opening the shutter
- UTF encoding and character set in golang
- Kubeadm初始化报错:[ERROR CRI]: container runtime is not running
猜你喜欢
随机推荐
Redis transaction
华为模拟器ensp的路由配置以及连通测试
面试官:说说XSS攻击是什么?
[solution] paddlepaddle 2 X call static graph mode
Detailed explanation of multi-mode input event distribution mechanism
OMS系统实战的三两事
Jerry's ad series MIDI function description [chapter]
Day24: file system
heatmap.js图片热点热力图插件
JS卡牌样式倒计时天数
奋斗正当时,城链科技战略峰会广州站圆满召开
杰理之AD 系列 MIDI 功能说明【篇】
Jerry's ad series MIDI function description [chapter]
2021 CCPC 哈尔滨 B. Magical Subsequence(思维题)
类方法和类变量的使用
A quick start to fastdfs takes you three minutes to upload and download files to the ECS
TCP三次握手,四次挥手,你真的了解吗?
Day24:文件系统
Le module minidom écrit et analyse XML
宝塔 7.9.2 宝塔控制面板绕过 手机绑定认证 绕过官方认证









