Skip to content

[webview_flutter] LateInitializationError: Field '_currentNavigationDelegate' has not been initialized. #119332

@Szaki

Description

@Szaki

Steps to Reproduce

  1. Execute flutter run on the code sample with webview_flutter: ^4.0.2.

Expected results:

The WebView loads correctly and without any exceptions.

Actual results:

The WebView loads, but throws numerous LateInitializationErrors, leading to failures in tests.

Code sample
import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';

void main() {
  runApp(const MyApp());
}

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

  @override
  Widget build(BuildContext context) => MaterialApp(
        home: Scaffold(
          body: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              VideoPlayer(
                url: Uri.https('youtube.com', 'embed'),
              )
            ],
          ),
        ),
      );
}

class VideoPlayer extends StatelessWidget {
  final Uri url;
  late final controller = WebViewController()
    ..setJavaScriptMode(JavaScriptMode.unrestricted)
    ..loadRequest(url);

  VideoPlayer({
    super.key,
    required this.url,
  });

  @override
  Widget build(BuildContext context) => AspectRatio(
        aspectRatio: 16 / 9,
        child: WebViewWidget(controller: controller),
      );
}
Logs
[  +29 ms] 
           ══╡ EXCEPTION CAUGHT BY SERVICES LIBRARY ╞══════════════════════════════════════════════════════════
           The following LateError was thrown during a platform message callback:
           LateInitializationError: Field '_currentNavigationDelegate@68193571' has not been initialized.
           
           When the exception was thrown, this was the stack:
           #0      AndroidWebViewController._currentNavigationDelegate (package:webview_flutter_android/src/android_webview_controller.dart)
           #1      AndroidWebViewController._webChromeClient.<anonymous closure>.<anonymous closure> (package:webview_flutter_android/src/android_webview_controller.dart:104:35)
           #2      WebChromeClientFlutterApiImpl.onProgressChanged (package:webview_flutter_android/src/android_webview_api_impls.dart:830:34)
           #3      WebChromeClientFlutterApi.setup.<anonymous closure> (package:webview_flutter_android/src/android_webview.pigeon.dart:1830:15)
           #4      BasicMessageChannel.setMessageHandler.<anonymous closure> (package:flutter/src/services/platform_channel.dart:214:49)
           #5      _DefaultBinaryMessenger.setMessageHandler.<anonymous closure> (package:flutter/src/services/binding.dart:393:35)
           #6      _invoke2 (dart:ui/hooks.dart:183:13)
           #7      _ChannelCallbackRecord.invoke (dart:ui/channel_buffers.dart:40:5)
           #8      _Channel.push (dart:ui/channel_buffers.dart:130:31)
           #9      ChannelBuffers.push (dart:ui/channel_buffers.dart:326:17)
           #10     PlatformDispatcher._dispatchPlatformMessage (dart:ui/platform_dispatcher.dart:664:22)
           #11     _dispatchPlatformMessage (dart:ui/hooks.dart:86:31)
           ════════════════════════════════════════════════════════════════════════════════════════════════════
[   +7 ms] The Flutter DevTools debugger and profiler on moto g 20 is available at: http://127.0.0.1:9102?uri=http://127.0.0.1:40599/Zs6U2RsJhD0=/
[        ] 
           Another exception was thrown: LateInitializationError: Field '_currentNavigationDelegate@68193571' has not been initialized.
[        ] 
           Another exception was thrown: LateInitializationError: Field '_currentNavigationDelegate@68193571' has not been initialized.
[   +7 ms] E/FrameEvents(16511): updateAcquireFence: Did not find frame.
[   +3 ms] I/gralloc4(16511): register: id=21700003b9a
[   +1 ms] I/gralloc4(16511): register: id=21700003b9b
[  +29 ms] I/gralloc4(16511): register: id=21700003b9c
[   +1 ms] E/FrameEvents(16511): updateAcquireFence: Did not find frame.
[   +3 ms] I/gralloc4(16511): register: id=21700003b9d
[  +72 ms] 
           Another exception was thrown: LateInitializationError: Field '_currentNavigationDelegate@68193571' has not been initialized.
[ +372 ms] I/GraphicsJNI(16511): GraphicsJNI::isHardwareConfig qemu gles is 1.
[   +9 ms] D/SensorManager(16511): registerListenerImpl sensor = {Sensor name="Game Rotation Vector", vendor="Sprd Group Ltd.", version=1, type=15, maxRange=1.0, resolution=1.0E-6, power=11.27, minDelay=10000}, delayUs = 16666, latencyUs = 0, listener =
org.chromium.device.sensors.PlatformSensor@741408f
[ +236 ms] E/FrameEvents(16511): updateAcquireFence: Did not find frame.
[   +4 ms] D/SensorManager(16511): unregisterListenerImpl sensor = {Sensor name="Game Rotation Vector", vendor="Sprd Group Ltd.", version=1, type=15, maxRange=1.0, resolution=1.0E-6, power=11.27, minDelay=10000}, listener =
org.chromium.device.sensors.PlatformSensor@741408f
[   +7 ms] I/gralloc4(16511): register: id=21700003b9e
[   +7 ms] E/FrameEvents(16511): updateAcquireFence: Did not find frame.
[  +10 ms] E/FrameEvents(16511): updateAcquireFence: Did not find frame.
[        ] I/gralloc4(16511): register: id=21700003b9f
[   +5 ms] E/FrameEvents(16511): updateAcquireFence: Did not find frame.
[  +10 ms] E/FrameEvents(16511): updateAcquireFence: Did not find frame.
[   +2 ms] 
           Another exception was thrown: LateInitializationError: Field '_currentNavigationDelegate@68193571' has not been initialized.
[   +8 ms] 
           Another exception was thrown: LateInitializationError: Field '_currentNavigationDelegate@68193571' has not been initialized.
No issues found! (ran in 0.8s)
[✓] Flutter (Channel stable, 3.7.0, on Ubuntu 22.10 5.19.0-29-generic, locale en_US.UTF-8)
    • Flutter version 3.7.0 on channel stable at /usr/lib/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision b06b8b2710 (4 days ago), 2023-01-23 16:55:55 -0800
    • Engine revision b24591ed32
    • Dart version 2.19.0
    • DevTools version 2.20.1

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
    • Android SDK at /home/gergely/Android/Sdk
    • Platform android-33, build-tools 33.0.1
    • Java binary at: /snap/android-studio/125/android-studio/jre/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • Chrome at google-chrome

[✓] Linux toolchain - develop for Linux desktop
    • Ubuntu clang version 15.0.2-1
    • cmake version 3.24.2
    • ninja version 1.11.0
    • pkg-config version 0.29.2

[✓] Android Studio (version 2021.3)
    • Android Studio at /snap/android-studio/125/android-studio
    • Flutter plugin version 71.2.3
    • Dart plugin version 213.7433
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)

[✓] VS Code (version 1.74.3)
    • VS Code at /usr/share/code
    • Flutter extension version 3.58.0

[✓] Connected device (3 available)
    • moto g 20 (mobile) • ZY32C5299V • android-arm64  • Android 11 (API 30)
    • Linux (desktop)    • linux      • linux-x64      • Ubuntu 22.10 5.19.0-29-generic
    • Chrome (web)       • chrome     • web-javascript • Google Chrome 109.0.5414.119

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!

Metadata

Metadata

Assignees

No one assigned

    Labels

    c: crashStack traces logged to the consolefound in release: 3.7Found to occur in 3.7has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: webviewThe WebView pluginpackageflutter/packages repository. See also p: labels.platform-androidAndroid applications specifically

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions