Skip to content
Boring Doc
BreakingHigh impactOfficial migration guidesince 2.5.0landed 2.3.0-17.0.pre.1

Transition of platform channel test interfaces to flutter_test package

Framework · Official source

The following methods have been replaced by APIs in the `flutter_test` package:

Original behavior

As part of a refactoring of the low-level plugin communications architecture, we have moved from the previous `onPlatformMessage`/`handlePlatformMessage` logic to a per-channel buffering system implemented in the engine in the `ChannelBuffers` class. To maintain compatibility with existing code, the existing `BinaryMessenger.setMessageHandler` API has been refactored to use the new `ChannelBuffers` API.

New behavior

Specifically, the following APIs were affected:

Who is affected
affected:
Practical impact
Behaviour or API differences that can break builds or change runtime behaviour.
What action should I take?
Follow the official migration guide below, update affected call sites, run `dart fix --apply` where a fix is available, then run your tests.
Official migration guide (excerpt, © The Flutter Authors, CC BY 3.0)

The flutter_test package provides some shims so that uses of the obsolete setMock... and checkMock... methods will continue to work. Tests that previously did not import package:flutter_test/flutter_test.dart can do so to enable these shims; this should be sufficient to migrate most code.

These shim APIs are deprecated, however. Instead, in code using WidgetTester (for example, using testWidgets), it is recommended to use the following patterns to replace calls to those methods (where tester is the WidgetTester instance):

// old code
ServicesBinding.defaultBinaryMessenger.setMockMessageHandler(...);
ServicesBinding.defaultBinaryMessenger.checkMockMessageHandler(...);
// new code
tester.binding.defaultBinaryMessenger.setMockMessageHandler(...);
tester.binding.defaultBinaryMessenger.checkMockMessageHandler(...);
// old code
myChannel.setMockMessageHandler(...);
myChannel.checkMockMessageHandler(...);
// new code
tester.binding.defaultBinaryMessenger.setMockDecodedMessageHandler(myChannel, ...);
tester.binding.defaultBinaryMessenger.checkMockMessageHandler(myChannel, ...);
// old code
myMethodChannel.setMockMethodCallHandler(...);
myMethodChannel.checkMockMethodCallHandler(...);
// new code
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(myMethodChannel, ...);
tester.binding.defaultBinaryMessenger.checkMockMessageHandler(myMethodChannel, ...);

Tests that use package:test and test() can be changed to use package:flutter_test and testWidgets() to get access to a WidgetTester.

Code that does not have access to a WidgetTester can refer to TestDefaultBinaryMessengerBinding.instance!.defaultBinaryMessenger instead of tester.binding.defaultBinaryMessenger.

Tests that do not use the default test widgets binding (AutomatedTestWidgetsFlutterBinding, which is initialized by testWidgets) can mix the TestDefaultBinaryMessengerBinding mixin into their binding to get the same results.

Tests that manipulate onPlatformMessage will no longer function as designed. To send mock messages to the framework, consider using ChannelBuffers.push. There is no mechanism to intercept messages from the plugins and forward them to the framework in the new API. If your use case requires such a mechanism, please file a bug.

Migration assistantAI-generated · grounded in cited sources
AI explanations are not configured
Set AI_PROVIDER (for example to openai-compatible with a local Ollama or LM Studio endpoint) to enable grounded explanations. Everything else on this page works without an AI provider.
Official migration guide·Verified classification (95%)

Listed in the official breaking-changes index (docs.flutter.dev/release/breaking-changes).

An official announcement or migration guide documents an intended behaviour or API change. A verified source change (git diff) shows code changed but does not by itself prove a public API is breaking. AI interpretations are labelled and never used to classify a change.

Source commit
b3045439b7c0
Source last updated
Oct 21, 2026
Last synchronized
Oct 21, 2026
Publication status
published
Publication history
  • Oct 21, 2026, 8:31 PM: new → published (ingestion) — Backed by an official breaking-change/migration guide.
AI explanationAI-generated · grounded in cited sources
AI explanations are not configured
Set AI_PROVIDER (for example to openai-compatible with a local Ollama or LM Studio endpoint) to enable grounded explanations. Everything else on this page works without an AI provider.
Was this useful?