我安装了webview_flutter。我也运行了pub get。另外,我添加了导入“package:webview_flutter/webview_flutter. dart”。但实际上我不能在flutter中使用WebView小部件。这是我的代码。WebView发生了找不到错误。
import 'dart:io'; // Add this import.
import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';
class WebViewExample extends StatefulWidget {
@override
_WebViewExampleState createState() => _WebViewExampleState();
}
class _WebViewExampleState extends State<WebViewExample> {
@override
void initState() {}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('WebView Example'),
),
body: Builder(builder: (BuildContext context){
return WebView(
initialUrl: 'https://flutter.dev',
);
}),
);
}
}
2条答案
按热度按时间jmo0nnb31#
您需要一个WebViewWidget和一个WebViewController
参见enter link description here
jw5wzhpr2#
1-Webview在Android上支持SDK 19+,在IOS上支持SDK 9.0+,因此请在SDK管理器中检查您的SDK版本并进行更新...然后在您的Android Build Gradle中检查minSdkVersion
也可能是网络问题...
2-在实际设备上测试它,如果它工作正常,那么如果您使用的是虚拟设备,则需要进行以下修改
按Windows -〉搜索查看网络连接-〉右键单击您的网络-〉属性-〉单击TCP IPv4 -〉属性-〉选中使用以下DNS服务器-〉更改为8.8.8.8作为第一个DNS服务器,更改为0.0.0.0作为第二个DNS服务器