Bug: MethodChannel handler registration before BinaryMessenger initialization
Description
The plugin logs the following error during initialization:
CallBundle: Deferred handler registration (binding not ready): 'package:flutter/src/services/platform_channel.dart': Failed assertion: line 589 pos 7: '_binaryMessenger != null || BindingBase.debugBindingType() != null': Cannot set the method call handler before the binary messenger has been initialized.
Current Implementation
The handler is registered inside the constructor:
MethodChannelCallBundle() {
_ensureHandlerRegistered();
}
which eventually calls:
methodChannel.setMethodCallHandler(_handleNativeCall);
Problem
At the time the constructor is executed, Flutter bindings may not yet be initialized, causing setMethodCallHandler() to throw.
The plugin catches the exception and logs:
CallBundle: Deferred handler registration (binding not ready)
This indicates that the plugin is attempting to register the MethodChannel handler before the BinaryMessenger is available.
Expected Behavior
The plugin should avoid calling setMethodCallHandler() until Flutter bindings have been initialized and the BinaryMessenger is available.
Suggested Fix
Delay handler registration until Flutter initialization is complete, or perform a check before calling:
methodChannel.setMethodCallHandler(_handleNativeCall);
to ensure that the BinaryMessenger is ready.
Full Error
CallBundle: Deferred handler registration (binding not ready): 'package:flutter/src/services/platform_channel.dart': Failed assertion: line 589 pos 7: '_binaryMessenger != null || BindingBase.debugBindingType() != null': Cannot set the method call handler before the binary messenger has been initialized. This happens when you call setMethodCallHandler() before the WidgetsFlutterBinding has been initialized. You can fix this by either calling WidgetsFlutterBinding.ensureInitialized() before this or by passing a custom BinaryMessenger instance to MethodChannel().
Bug: MethodChannel handler registration before BinaryMessenger initialization
Description
The plugin logs the following error during initialization:
Current Implementation
The handler is registered inside the constructor:
which eventually calls:
methodChannel.setMethodCallHandler(_handleNativeCall);Problem
At the time the constructor is executed, Flutter bindings may not yet be initialized, causing
setMethodCallHandler()to throw.The plugin catches the exception and logs:
This indicates that the plugin is attempting to register the MethodChannel handler before the BinaryMessenger is available.
Expected Behavior
The plugin should avoid calling
setMethodCallHandler()until Flutter bindings have been initialized and the BinaryMessenger is available.Suggested Fix
Delay handler registration until Flutter initialization is complete, or perform a check before calling:
methodChannel.setMethodCallHandler(_handleNativeCall);to ensure that the BinaryMessenger is ready.
Full Error