目录
一、集成webview_flutter
二、配置
三、WebView
四、flutter run
一、集成webview_flutter
pubspec.yaml 中 添加webview_flutter: ^0.3.9+1,并同步 packages get。
在相应的 .dart 文件中添加引用 import 'package:webview_flutter/webview_flutter.dart'。
dependencies:
flutter:
sdk: flutter
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
webview_flutter: ^0.3.9+1
二、配置
1、iOS配置
需要在Info.plist中添加io.flutter.embedded_views_preview。
<key>io.flutter.embedded_views_preview</key>
<string>YES</string>
2、Android配置
需要在AndroidManifest.xml中添加网络权限。
<uses-permission android:name="android.permission.INTERNET" />
三、WebView
import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';
class IndexPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('网络加载H5页面'),
),
body: Center(
child: WebView(
initialUrl: "https://xxbc.gitee.io/",
)
)
);
}
}