When I install my app on iOS devices with iOS 14+ the app crashes the moment the user goes to a page with webview inside.
The error is
Runner[654:91182] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSTaggedPointerString count]: unrecognized selector sent to instance 0xb0f5a9dc7811cf31'
The code I use is:
on the main page when the user presses a button:
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => SecondPage(url)),
);
the Second page has webview:
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'),
),
);
}
}
and the webview is:
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!');
},
);
}
}
Every suggestion will be highly appreciated.
This is a Flutter bug, the flutter devs is working on this: https://github.com/flutter/flutter/issues/67213#issuecomment-705066599