问题描述
当我在装有iOS 14+的iOS设备上安装我的应用程序时,该应用程序崩溃的原因是用户转到其中带有Webview的页面。
错误是
Runner [654:91182] ***由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'-[NSTaggedPointerString count]:无法识别的选择器已发送至实例0xb0f5a9dc7811cf31'
我使用的代码是:
用户按下按钮时,在主页上的:
Navigator.push(
context,MaterialPageRoute(
builder: (context) => SecondPage(url)),);
第二页具有网络视图:
class SecondPage extends StatefulWidget {
SecondPage(this.payload);
final String payload;
@override
State<StatefulWidget> createState() => SecondPageState();
}
class SecondPageState extends State<SecondPage> {
String _payload;
@override
void initState() {
super.initState();
_payload = widget.payload;
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: MyWebView(
title: "Narrative App",selectedUrl: 'http://iot-center.de/user/adv/$_payload'),),);
}
}
和网络视图是:
class MyWebView extends StatefulWidget {
final String title;
final String selectedUrl;
MyWebView({
@required this.title,@required this.selectedUrl,});
@override
_MyWebViewState createState() => _MyWebViewState();
}
class _MyWebViewState extends State<MyWebView> {
WebViewController _controller;
final _key = UniqueKey();
bool _isLoadingPage;
@override
void initState() {
super.initState();
if (Platform.isAndroid) WebView.platform = SurfaceAndroidWebView();
_isLoadingPage = true;
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.lightBlue,title: Text(widget.title),body: Stack(
children: <Widget>[
WebView(
key: _key,initialUrl: widget.selectedUrl,javascriptMode: JavascriptMode.unrestricted,onWebViewCreated: (WebViewController webViewController) {
this._controller = webViewController;
},onPageFinished: (url) {
setState(() {
_isLoadingPage = false;
});
},_isLoadingPage
? Container(
alignment: FractionalOffset.center,child: CircularProgressIndicator(
backgroundColor: Colors.lightBlue,)
: Container(),],floatingActionButton: favoriteButton(),);
}
Widget favoriteButton() {
return FloatingActionButton(
child: Icon(Icons.share),onPressed: () {
Share.share('Check out this ${widget.selectedUrl}',subject: 'Look what I found!');
},);
}
}
每个建议都会受到高度赞赏。
解决方法
这是Flutter的错误,Flutter开发人员正在对此进行处理: https://github.com/flutter/flutter/issues/67213#issuecomment-705066599