1

`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'),
              ),
            ),
          ],
        ),
      ),
    );
  }
}



1
  • 1
    Care to share the stack trace? Commented Feb 19 at 8:17

1 Answer 1

0

The real device gives an error on iOS 18.3 and above.

Delete pubspec.lock and Podfile.lock.

Add the following line to the pubspec.yaml file.

dependency_overrides:
  webview_flutter_wkwebview: ^3.18.2

Note: In the issues opened on Github, some users stated that they worked without problems on 3.18.2, some users on 3.17.0, and some users on 3.16.3. I solved the error with ^3.16.3.

https://github.com/flutter/flutter/issues/162437

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.