webView 在 Flutter 中不起作用 [ERROR:flutter/lib/ui/ui_dart_state.cc(157)]



我在pubspec.yamlwebview_flutter: ^0.3.19+8中添加我使用Flutter版本1.12.13+修补程序.8

这是我的代码

import 'package:webview_flutter/webview_flutter.dart';
void main() => runApp(MaterialApp(
home: app(),
));
class app extends StatefulWidget {
@override
_appState createState() => _appState();
}
class _appState extends State<app> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('App mobile'),
),
body: Container(
constraints: BoxConstraints(maxHeight: 500),
child: WebView(
initialUrl: "https://google.com",
),
)
);
}
}

但在运行并单击white模拟器屏幕后,在选项卡"运行"中,我有这个。。。

E/flutter ( 9570): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: PlatformException(error, java.lang.IllegalStateException: Sending touch to an unknown view with id: 1
E/flutter ( 9570):  at io.flutter.plugin.platform.PlatformViewsController$1.onTouch(PlatformViewsController.java:206)
E/flutter ( 9570):  at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.touch(PlatformViewsChannel.java:168)
...

我将感谢任何帮助。。。

我用过这个,而且效果很好,我想你错过了使用controller

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';
class WebViewScreen extends StatefulWidget {
final String title;
final String selectedUrl;
WebViewScreen({@required this.title, @required this.selectedUrl});
@override
_WebViewScreenState createState() => _WebViewScreenState();
}
class _WebViewScreenState extends State<WebViewScreen> {
Completer<WebViewController> _controller = Completer<WebViewController>();
bool isLoading = true;
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: WebView(
initialUrl: widget.selectedUrl,
onWebViewCreated: (WebViewController webViewController) {
_controller.complete(webViewController);
},
),
);
}
}

请检查"android.permission.INTERNET";如果您在发布模式中遇到此错误,则在Manifest文件中的权限。

最新更新