fluttercommunity / fluttercommunity/wakelock_plus

getting PlatformException(channel-error, Unable to establish connection on channel: "dev.flutter.pigeon.wakelock_plus_platform_interface.WakelockPlusApi.toggle"., null, null) error when running test cases

Open
#67 12 comments 8 reactions 0 assignees View on GitHub
Dominant language
Dart
Stars
109
Forks
97
Avg merge
5d 4h
Merged PRs (30d)
2

Description

I am using **wakelock_plus** for one of my classes to keep player screen on. Test cases related to that file are failing. I was earlier using **wakelock**, recently updated to **wakelock_plus**. In the test case file I have a setupAll method where earlier for wakelock **'wakelock_macos'** was used for MethodChannel name like below.

```
const channel = MethodChannel('wakelock_macos');
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(channel, (MethodCall methodCall) async {
return null;
});
```
for this test cases were passed successfully.

After comparing the **wakelock** and **wakelock_plus** libraries, I attempted to utilise the MethodChannel named **'wakelock_plus_macos'** for wakelock_plus in the same way that we used it for wakelock.
`const channel = MethodChannel('wakelock_plus_macos');`

But test cases are failing with below error:
`PlatformException(channel-error, Unable to establish connection on channel: "dev.flutter.pigeon.wakelock_plus_platform_interface.WakelockPlusApi.toggle"., null, null)`

Now if I use 'dev.flutter.pigeon.wakelock_plus_platform_interface.WakelockPlusApi.toggle' as the MethodChannel name like
`const channel = MethodChannel('dev.flutter.pigeon.wakelock_plus_platform_interface.WakelockPlusApi.toggle');`

I am getting another error:
```
FormatException: Message corrupted

package:flutter/src/services/message_codecs.dart 532:16 StandardMessageCodec.readValueOfType
package:flutter/src/services/message_codecs.dart 477:12 StandardMessageCodec.readValue
package:flutter/src/services/message_codecs.dart 522:23 StandardMessageCodec.readValueOfType
package:flutter/src/services/message_codecs.dart 477:12 StandardMessageCodec.readValue
package:flutter/src/services/message_codecs.dart 609:41 StandardMethodCodec.decodeMethodCall
package:flutter_test/src/test_default_binary_messenger.dart 300:45 TestDefaultBinaryMessenger.setMockMethodCallHandler.
package:flutter_test/src/test_default_binary_messenger.dart 143:29 TestDefaultBinaryMessenger.send
package:flutter/src/services/platform_channel.dart 218:54 BasicMessageChannel.send
package:wakelock_plus_platform_interface/messages.g.dart 122:32 WakelockPlusApi.toggle
package:wakelock_plus_platform_interface/src/method_channel_wakelock_plus.dart 20:16 MethodChannelWakelockPlus.toggle
package:wakelock_plus/wakelock_plus.dart 71:41 WakelockPlus.toggle
```

What should be used for MethodChannel to run test cases successfully

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.