Aysha Hamna
Aysha Hamna

Reputation: 446

The method 'setMockMessageHandler' isn't defined for the class 'BasicMessageChannel<dynamic>'

After running the Flutter project, I get this error. What can I do to solve it?

Error: The method 'setMockMessageHandler' 
isn't defined for the class 'BasicMessageChannel<dynamic>'.

FAILURE: Build failed with an exception.

Upvotes: 26

Views: 23873

Answers (6)

Zeus
Zeus

Reputation: 128

enter image description here

1

  1. : flutter pub upgrade
  2. : flutter clean
  3. : flutter pub upgrade --major-versions
  4. : cd ios
  5. : pod repo update
  6. : pod update
  7. : open Runner.xcworkspace
  8. : make clean & make run

Upvotes: 0

Ber
Ber

Reputation: 41813

Running across this problem after upgrading to Flutter 2.5.3 (from 2.2.3). The change outlined in the release notes broke several hundred tests since the mock method handlers were set in the global setUp() for most tests.

As shown in the release notes, I replaced code like

 MethodChannel('channelName')
   .setMockMethodCallHandler((MethodCall methodCall) {});

with code using the default instance of TestDefaultBinaryMessenger:

 TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
   .setMockMethodCallHandler(MethodChannel('channelName'), (MethodCall methodCall) {});

This change allowed me to keep all tests unchanged.

Upvotes: 4

Em Ikram
Em Ikram

Reputation: 171

  1. Go to specified class 'BasicMessageChannel' by press and hold ctrl and click on it
  2. than search for the 'setMockMessageHandler' by ctrl+F than u will see something like this // Looking for setMockMessageHandler? // See this shim package: packages/flutter_test/lib/src/deprecated.dart and paste this line below this comment void setMockMessageHandler(dynamic message){

} but this is just simple hack which is not recommended

Upvotes: 4

Hosam Eisa
Hosam Eisa

Reputation: 59

I have the same problem, I have tried all the above and did not help. flutter pub upgrade and flutter pub upgrade --major-versions outputs this:

No dependencies changed.

1 package is discontinued.

76 packages have newer versions incompatible with dependency constraints.

Try flutter pub outdated for more information.

No changes to pubspec.yaml! The plugins advance_pdf_viewer, flutter_absolute_path, geocoder, google_api_headers, onesignal_flutter use a deprecated version of the Android embedding. To avoid unexpected runtime failures, or future build failures, try to see if these plugins support the Android V2 embedding. Otherwise, consider removing them since a future release of Flutter will remove these deprecated APIs. If you are plugin author, take a look at the docs for migrating the plugin to the V2 embedding: https://flutter.dev/go/android-plugin-migration.

Upvotes: 2

Jury Dpling
Jury Dpling

Reputation: 753

I had the same problem after update plugin's in AndroidStudio on Mac

flutter pub upgrade

did nothing for me, but

flutter clean
flutter pub upgrade --major-versions

has solved the problem

Upvotes: 41

thiago_silva
thiago_silva

Reputation: 1726

I had the same problem today.

from what i could notice, this basically was a breaking change caused by transition of platform channel test interfaces to flutter_test package.

in my case, the problem was resolved just running the flutter pub upgrade on a global terminal session.

see more details about the mentioned transition on referred release notes

Upvotes: 2

Related Questions