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

UTF encoding and character set in golang

heatmap.js图片热点热力图插件

Huawei ENSP simulator configures ACL access control list

Render function and virtual DOM

maya灯建模

福昕PDF编辑器v10.1.8绿色版

B站视频 声音很小——解决办法

Routing configuration and connectivity test of Huawei simulator ENSP

The video sound of station B is very low - solution

Introduction to pressure measurement of JMeter
随机推荐
Day24:文件系统
Daily question -leetcode1200- minimum absolute difference - array - sort
TweenMax表情按钮js特效
Liu Jincheng won the 2022 China e-commerce industry innovation Figure Award
华为模拟器ensp常用命令
【C语言】符号的深度理解
At the right time, the Guangzhou station of the city chain science and Technology Strategy Summit was successfully held
Hwinfo hardware detection tool v7.26 green version
杰理之AD 系列 MIDI 功能说明【篇】
FastDfs的快速入门,三分钟带你上传下载文件到云服务器
Embedded TC test case
JS卡牌样式倒计时天数
Le module minidom écrit et analyse XML
为什么说不变模式可以提高性能
CAD中能显示打印不显示
改善机器视觉系统的方法
五子棋 上班摸鱼工具 可局域网/人机
华为模拟器ensp的路由配置以及连通测试
多模輸入事件分發機制詳解
Jerry's ad series MIDI function description [chapter]