Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.
like image 602
Aysha Hamna Avatar asked Jun 10 '21 05:06

Aysha Hamna


People also ask

How to set mock message handler in flutter?

flutter pub upgrade --major-versions It's working fine for me. Go to specified class 'BasicMessageChannel' by press and hold ctrl and click on it than search for the 'setMockMessageHandler' by ctrl+F than u will see something like this // Looking for setMockMessageHandler?

What happened to checkmessagehandler in the new API?

Tests using checkMessageHandler have no equivalent in the new API, since message handler registration is handled directly by the ChannelBuffers object, which does not expose the currently registered listener for a channel. (Tests verifying handler registration appear to be rare.) Code that needs migrating may see errors such as the following:

How many tests did the change to the mock method handlers break?

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. with code using the default instance of TestDefaultBinaryMessenger: This change allowed me to keep all tests unchanged.

What is a messagecodec?

A named channel for communicating with platform plugins using asynchronous message passing. Messages are encoded into binary before being sent, and binary messages received are decoded into Dart values. The MessageCodec used must be compatible with the one used by the platform plugin.


3 Answers

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

like image 106
Jury Dpling Avatar answered Oct 11 '22 19:10

Jury Dpling


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

like image 37
thiago_silva Avatar answered Oct 11 '22 20:10

thiago_silva


  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

like image 24
Em Ikram Avatar answered Oct 11 '22 19:10

Em Ikram