Skip to content

Android: Null is not a subtype of String in AndroidInAppWebViewController._handleMethod after upgrading to 6.2.0-beta.3 #2856

Description

@changs97

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

After upgrading from flutter_inappwebview 6.1.5 to flutter_inappwebview 6.2.0-beta.3, the Android app logs a runtime type error from AndroidInAppWebViewController._handleMethod.

The error occurs during normal WebView usage. I did not explicitly long-press the WebView content, and the app does not pass a custom ContextMenu to InAppWebView.

The stacktrace points to the plugin's Android MethodChannel event dispatcher:

type 'Null' is not a subtype of type 'String'
#0      AndroidInAppWebViewController._handleMethod (package:flutter_inappwebview_android/src/in_app_webview/in_app_webview_controller.dart:1412)
#1      InternalChannelController.initMethodCallHandler.<anonymous closure> (package:flutter_inappwebview_platform_interface/src/util.dart:631)
#2      MethodChannel._handleAsMethodCall (package:flutter/src/services/platform_channel.dart:607)
#3      MethodChannel.setMethodCallHandler.<anonymous closure> (package:flutter/src/services/platform_channel.dart:597)
#4      _DefaultBinaryMessenger.setMessageHandler.<anonymous closure> (package:flutter/src/services/binding.dart:663)
#5      _invoke2 (dart:ui/hooks.dart:455)
#6      _ChannelCallbackRecord.invoke (dart:ui/channel_buffers.dart:45)
#7      _Channel.push (dart:ui/channel_buffers.dart:136)
#8      ChannelBuffers.push (dart:ui/channel_buffers.dart:344)
#9      PlatformDispatcher._dispatchPlatformMessage (dart:ui/platform_dispatcher.dart:822)
#10     _dispatchPlatformMessage (dart:ui/hooks.dart:369)

This looks like a native-to-Dart MethodChannel payload nullability issue. The Android implementation appears to read some MethodChannel arguments as non-null String, but Android native can apparently send null in at least one path.

Expected Behavior

The plugin should not throw a Dart runtime type error when Android native sends a nullable value through MethodChannel.

If a native event argument can be null, the Dart side should either accept nullable values or guard before creating non-null String values.

For example:

final String? url = call.arguments["url"];
if (url == null) {
  break;
}

or, for optional display values:

final String title = call.arguments["title"] ?? "";

Steps with code example to reproduce

  1. Use flutter_inappwebview: ^6.2.0-beta.3.
  2. Run the app on Android.
  3. Open a screen containing InAppWebView.
  4. Navigate normally inside the WebView.
  5. Observe the runtime error from AndroidInAppWebViewController._handleMethod.

The app creates InAppWebView without a custom ContextMenu:

InAppWebView(
  initialUrlRequest: initialUrlRequest,
  initialSettings: CommonUtils.getCommonWebSetting(userAgent),
)

Common settings include:

InAppWebViewSettings(
  disableContextMenu: true,
  disableLongPressContextMenuOnLinks: true,
  useShouldOverrideUrlLoading: true,
  javaScriptEnabled: true,
)

Stacktrace/Logs

I/flutter (21958): type 'Null' is not a subtype of type 'String'
I/flutter (21958): #0      AndroidInAppWebViewController._handleMethod (package:flutter_inappwebview_android/src/in_app_webview/in_app_webview_controller.dart:1412)
I/flutter (21958): #1      InternalChannelController.initMethodCallHandler.<anonymous closure> (package:flutter_inappwebview_platform_interface/src/util.dart:631)
I/flutter (21958): #2      MethodChannel._handleAsMethodCall (package:flutter/src/services/platform_channel.dart:607)
I/flutter (21958): #3      MethodChannel.setMethodCallHandler.<anonymous closure> (package:flutter/src/services/platform_channel.dart:597)
I/flutter (21958): #4      _DefaultBinaryMessenger.setMessageHandler.<anonymous closure> (package:flutter/src/services/binding.dart:663)
I/flutter (21958): #5      _invoke2 (dart:ui/hooks.dart:455)
I/flutter (21958): #6      _ChannelCallbackRecord.invoke (dart:ui/channel_buffers.dart:45)
I/flutter (21958): #7      _Channel.push (dart:ui/channel_buffers.dart:136)
I/flutter (21958): #8      ChannelBuffers.push (dart:ui/channel_buffers.dart:344)
I/flutter (21958): #9      PlatformDispatcher._dispatchPlatformMessage (dart:ui/platform_dispatcher.dart:822)
I/flutter (21958): #10     _dispatchPlatformMessage (dart:ui/hooks.dart:369)

Potential non-null String reads in flutter_inappwebview_android 1.2.0-beta.3:

String origin = call.arguments["origin"]; // onGeolocationPermissionsShowPrompt
String url = call.arguments["url"];       // onReceivedTouchIconUrl / onSafeBrowsingHit
String title = call.arguments["title"];   // onContextMenuActionItemClicked

Flutter version

3.44.0

Operating System, Device-specific and/or Tool

macOS 26.5.1 25F80 darwin-arm64
Android device: SM-F936N
Android version: 16
Android API level: 36
Android WebView: com.google.android.webview 149.0.7827.91
Android SDK: 37.0.0
Java: OpenJDK 21.0.8 bundled with Android Studio

flutter doctor -v reports no issues.

Plugin version

flutter_inappwebview: 6.2.0-beta.3

Additional information

This started after upgrading from the previous stable version:

flutter_inappwebview: 6.1.5
flutter_inappwebview_android: 1.1.3
flutter_inappwebview_platform_interface: 1.3.0+1

Current resolved package versions:

flutter_inappwebview: 6.2.0-beta.3
flutter_inappwebview_android: 1.2.0-beta.3
flutter_inappwebview_platform_interface: 1.4.0-beta.3

The same application did not show this error on flutter_inappwebview 6.1.5.

This may be a regression in the 6.2.0 beta line. The changelog for the 6.2.0 beta line includes platform interface/code generation/fromMap/toMap and Android dependency updates, so the native-to-Dart MethodChannel payload handling may need additional null safety guards.

Relevant changelog:
https://github.com/pichillilorenzo/flutter_inappwebview/blob/master/flutter_inappwebview/CHANGELOG.md#620-beta3

I am also trying to capture the exact MethodChannel event name by enabling PlatformInAppWebViewController.debugLoggingSettings.

Self grab

  • I'm ready to work on this issue!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions