当前位置:网站首页>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);
},
),
);
边栏推荐
猜你喜欢

IIC (STM32)

UTF encoding and character set in golang

多模輸入事件分發機制詳解

偷窃他人漏洞报告变卖成副业,漏洞赏金平台出“内鬼”
![[wechat applet] collaborative work and release](/img/14/2658cf0ba6be9432c74b2490e53d05.png)
[wechat applet] collaborative work and release

MP3是如何诞生的?

Explication détaillée du mécanisme de distribution des événements d'entrée multimodes

LambdaQueryWrapper用法

解析互联网时代的创客教育技术

Routing configuration and connectivity test of Huawei simulator ENSP
随机推荐
FastDfs的快速入门,三分钟带你上传下载文件到云服务器
2021 CCPC Harbin B. magical subsequence (thinking question)
杰理之AD 系列 MIDI 功能说明【篇】
Google colab踩坑
杰理之AD 系列 MIDI 功能说明【篇】
Difference between ApplicationContext and beanfactory (MS)
redis RDB AOF
【微服务|SCG】Predicate的使用
[ 每周译Go ] 《How to Code in Go》系列文章上线了!!
PS竖排英文和数字文字怎么改变方向(变竖直显示)
TCP三次握手,四次挥手,你真的了解吗?
redis发布订阅的使用
华为ensp模拟器 配置ACL访问控制列表
D3.js+Three.js数据可视化3d地球js特效
Introduction to pressure measurement of JMeter
每日一题-LeetCode1200-最小绝对差-数组-排序
测试用例 (TC)
宝塔 7.9.2 宝塔控制面板绕过 手机绑定认证 绕过官方认证
Huawei simulator ENSP common commands
B站视频 声音很小——解决办法