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

6

26

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.
Baobaobab answered 10/6, 2021 at 5:17 Comment(0)
K
41

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

Kinslow answered 30/6, 2021 at 9:2 Comment(4)
I dont want to update all my dependencies. How can I identifiy the specific dependecy which I need to upgrade?Sugar
Lifesaver! Thanks :DFerrari
This didn't work for me on Mac. Any steps specific to Mac?Oni
flutter pub upgrade --major-versions It's working fine for me.Crotchety
K
4
  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

Kilburn answered 27/10, 2021 at 12:40 Comment(1)
best thing to do when legacy need some hotfixDesrosiers
S
4

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.

Springfield answered 9/11, 2021 at 9:54 Comment(0)
E
2

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

Eyler answered 21/6, 2021 at 4:24 Comment(0)
F
2

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.

Fathomless answered 19/9, 2021 at 15:55 Comment(2)
so what is the solution?Mullis
I have the same problem, only explained what i did, still not workingFathomless
H
0

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
Hakeem answered 19/5, 2023 at 8:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.