//展示网页数据
class MyWebView extends StatefulWidget {
String url;
String title;
MyWebView({Key key, @required this.url, @required this.title});
@override
createState() => _PageState(url: url, title: title);
}
class _PageState extends State<MyWebView> {
String url;
String title;
_PageState({Key key, @required this.url, @required this.title});
final _key = UniqueKey();
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: _setTitle(context),
body: Column(
children: [
Expanded(
child: WebView(
key: _key,
javascriptMode: JavascriptMode.unrestricted,
initialUrl: url))
],
));
}
_setTitle(context) {
return new AppBar(
brightness: Brightness.light,
title:
new Text(title, style: TextStyle(color: Colors.black, fontSize: 20)),
elevation: 1,
leading: new IconButton(
icon: new Icon(
Icons.arrow_back_ios,
color: Colors.black,
),
onPressed: () {
Navigator.pop(context);
}),
backgroundColor: Colors.white,
centerTitle: true,
);
}
}
flutter webview
最新推荐文章于 2025-10-12 08:21:37 发布
本文深入探讨了Flutter中WebView组件的实现细节,展示了如何通过MyWebView类加载并展示网页数据,包括设置初始URL、使用无限制的JavaScript模式以及构建包含标题栏和WebView主体的应用布局。
1461

被折叠的 条评论
为什么被折叠?



