`I am developing a Flutter application that includes a payment flow using webview_flutter. The WebView is used to load an external payment page where users can complete their transactions.
The implementation works perfectly on Android devices and the iOS emulator. However, when I run the app on a real iOS device, the app crashes as soon as it navigates to the WebView screen.
How can I fix this crash on real iOS devices?`
Code:
import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';
class WebViewExample extends StatefulWidget {
final String url;
const WebViewExample({super.key, required this.url});
@override
State<WebViewExample> createState() => _WebViewExampleState();
}
class _WebViewExampleState extends State<WebViewExample> {
late WebViewController _controller;
bool isLoading = true;
@override
void initState() {
super.initState();
_controller = WebViewController()
..setJavaScriptMode(JavaScriptMode.unrestricted)
..setNavigationDelegate(
NavigationDelegate(
onPageStarted: (String url) {
setState(() {
isLoading = true;
});
},
onPageFinished: (String url) {
setState(() {
isLoading = false;
});
},
),
)
..loadRequest(Uri.parse(widget.url));
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
children: [
WebViewWidget(controller: _controller),
if (isLoading)
const Center(child: CircularProgressIndicator()),
],
),
bottomNavigationBar: BottomAppBar(
child: Row(
children: [
Expanded(
child: ElevatedButton(
onPressed: () => Navigator.pop(context),
child: const Text('Exit Payment Page'),
),
),
],
),
),
);
}
}