webview_completion_fix 0.0.1 copy "webview_completion_fix: ^0.0.1" to clipboard
webview_completion_fix: ^0.0.1 copied to clipboard

PlatformiOS

Fixes iOS WebView crashes (NSInternalInconsistencyException) caused by uncalled completion handlers in WKWebView navigation delegate methods.

example/lib/main.dart

import 'package:flutter/material.dart';
// ignore: depend_on_referenced_packages
import 'package:webview_flutter/webview_flutter.dart';

void main() => runApp(const MaterialApp(home: MyApp()));

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(child: Text('HI, WebView!')),
      appBar: AppBar(title: const Text('Flutter Simple Example')),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          Navigator.of(
            context,
          ).push(MaterialPageRoute(builder: (context) => WebViewExample()));
        },
      ),
    );
  }
}

class WebViewExample extends StatefulWidget {
  const WebViewExample({super.key});

  @override
  State<WebViewExample> createState() => _WebViewExampleState();
}

class _WebViewExampleState extends State<WebViewExample> {
  late final WebViewController controller;

  @override
  void initState() {
    super.initState();

    controller = WebViewController()
      ..setJavaScriptMode(JavaScriptMode.unrestricted)
      ..setNavigationDelegate(
        NavigationDelegate(
          onProgress: (int progress) {
            // Update loading bar.
          },
          onPageStarted: (String url) {},
          onPageFinished: (String url) {},
          onHttpError: (HttpResponseError error) {},
          onWebResourceError: (WebResourceError error) {},
          onNavigationRequest: (NavigationRequest request) {
            if (request.url.startsWith('https://www.youtube.com/')) {
              return NavigationDecision.prevent;
            }
            return NavigationDecision.navigate;
          },
        ),
      )
      ..loadRequest(Uri.parse('https://www.fullstackaction.com'));
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Flutter WebView Example')),
      body: WebViewWidget(controller: controller),
    );
  }
}
2
likes
150
points
208
downloads

Publisher

verified publisherfullstackaction.com

Weekly Downloads

Fixes iOS WebView crashes (NSInternalInconsistencyException) caused by uncalled completion handlers in WKWebView navigation delegate methods.

Repository (GitHub)
View/report issues

Documentation

API reference

License

Apache-2.0 (license)

Dependencies

flutter, plugin_platform_interface, webview_flutter

More

Packages that depend on webview_completion_fix

Packages that implement webview_completion_fix