Flutter ------- WebView加载网页
在Flutter 加载网页?也是有WebView的哦,和Android一样
1.添加依赖
dependencies:
flutter_webview_plugin: ^0.2.1+2
2.导入库
import 'import 'package:flutter_webview_plugin/flutter_webview_plugin.dart'; //导入前需要配置
效果图:
代码:
import 'package:flutter/material.dart'; import 'package:flutter_webview_plugin/flutter_webview_plugin.dart'; class WebMain extends StatelessWidget { @override Widget build(BuildContext context) { List<Widget> titleContent = []; titleContent.add(new Text( "关于我们", style: new TextStyle(color: Colors.white), )); titleContent.add(new Container(width: 50.0)); // WebviewScaffold是插件提供的组件,用于在页面上显示一个WebView并加载URL return new WebviewScaffold( url:"https://blog.csdn.net/dickyqie", // 登录的URL appBar: new AppBar( title: new Row( mainAxisAlignment: MainAxisAlignment.center, children: titleContent, ), iconTheme: new IconThemeData(color: Colors.white), ), withZoom: true, // 允许网页缩放 withLocalStorage: true, // 允许LocalStorage withJavascript: true, // 允许执行js代码 ); } }
WebView库 详细的说明文档
https://pub.dev/packages/flutter_webview_plugin