diff --git a/wakelock_platform_interface/CHANGELOG.md b/wakelock_platform_interface/CHANGELOG.md index ea3c802d..b21300b8 100644 --- a/wakelock_platform_interface/CHANGELOG.md +++ b/wakelock_platform_interface/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.2.1 + +* Migrated to pigeon `0.2.1`, which fixes deprecated usage of `setMockMessageHandler`. + ## 0.2.0 * Bumped to stable null safety release. diff --git a/wakelock_platform_interface/analysis_options.yaml b/wakelock_platform_interface/analysis_options.yaml new file mode 100644 index 00000000..76337915 --- /dev/null +++ b/wakelock_platform_interface/analysis_options.yaml @@ -0,0 +1,6 @@ +include: ../analysis_options.yaml + +analyzer: + exclude: + - 'lib/messages.dart' + - 'test/messages.dart' diff --git a/wakelock_platform_interface/lib/messages.dart b/wakelock_platform_interface/lib/messages.dart index e3252f17..f0a703cf 100644 --- a/wakelock_platform_interface/lib/messages.dart +++ b/wakelock_platform_interface/lib/messages.dart @@ -1,123 +1,100 @@ -// Autogenerated from Pigeon (v0.1.14), do not edit directly. +// Autogenerated from Pigeon (v0.2.1), do not edit directly. // See also: https://pub.dev/packages/pigeon -// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import +// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types +// @dart = 2.12 import 'dart:async'; import 'dart:typed_data' show Uint8List, Int32List, Int64List, Float64List; import 'package:flutter/services.dart'; class ToggleMessage { - late bool enable; + bool? enable; - // ignore: unused_element - Map _toMap() { - final pigeonMap = {}; + Object encode() { + final Map pigeonMap = {}; pigeonMap['enable'] = enable; return pigeonMap; } - // ignore: unused_element - static ToggleMessage _fromMap(Map pigeonMap) { - final result = ToggleMessage(); - result.enable = pigeonMap['enable']; - return result; + static ToggleMessage decode(Object message) { + final Map pigeonMap = message as Map; + return ToggleMessage()..enable = pigeonMap['enable'] as bool?; } } class IsEnabledMessage { - late bool enabled; + bool? enabled; - // ignore: unused_element - Map _toMap() { - final pigeonMap = {}; + Object encode() { + final Map pigeonMap = {}; pigeonMap['enabled'] = enabled; return pigeonMap; } - // ignore: unused_element - static IsEnabledMessage _fromMap(Map pigeonMap) { - final result = IsEnabledMessage(); - result.enabled = pigeonMap['enabled']; - return result; + static IsEnabledMessage decode(Object message) { + final Map pigeonMap = message as Map; + return IsEnabledMessage()..enabled = pigeonMap['enabled'] as bool?; } } class WakelockApi { - Future toggle(ToggleMessage arg) async { - final requestMap = arg._toMap(); - const channel = BasicMessageChannel( - 'dev.flutter.pigeon.WakelockApi.toggle', StandardMessageCodec()); + /// Constructor for [WakelockApi]. The [binaryMessenger] named argument is + /// available for dependency injection. If it is left null, the default + /// BinaryMessenger will be used which routes to the host platform. + WakelockApi({BinaryMessenger? binaryMessenger}) + : _binaryMessenger = binaryMessenger; + + final BinaryMessenger? _binaryMessenger; - final replyMap = await channel.send(requestMap); + Future toggle(ToggleMessage arg) async { + final Object encoded = arg.encode(); + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.WakelockApi.toggle', const StandardMessageCodec(), + binaryMessenger: _binaryMessenger); + final Map? replyMap = + await channel.send(encoded) as Map?; if (replyMap == null) { throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - details: null); + code: 'channel-error', + message: 'Unable to establish connection on channel.', + details: null, + ); } else if (replyMap['error'] != null) { - final error = replyMap['error']; + final Map error = + (replyMap['error'] as Map?)!; throw PlatformException( - code: error['code'], - message: error['message'], - details: error['details']); + code: (error['code'] as String?)!, + message: error['message'] as String?, + details: error['details'], + ); } else { // noop } } Future isEnabled() async { - const channel = BasicMessageChannel( - 'dev.flutter.pigeon.WakelockApi.isEnabled', StandardMessageCodec()); - - final replyMap = await channel.send(null); + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.WakelockApi.isEnabled', + const StandardMessageCodec(), + binaryMessenger: _binaryMessenger); + final Map? replyMap = + await channel.send(null) as Map?; if (replyMap == null) { throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - details: null); + code: 'channel-error', + message: 'Unable to establish connection on channel.', + details: null, + ); } else if (replyMap['error'] != null) { - final error = replyMap['error']; + final Map error = + (replyMap['error'] as Map?)!; throw PlatformException( - code: error['code'], - message: error['message'], - details: error['details']); + code: (error['code'] as String?)!, + message: error['message'] as String?, + details: error['details'], + ); } else { - return IsEnabledMessage._fromMap(replyMap['result']); - } - } -} - -abstract class TestWakelockApi { - void toggle(ToggleMessage arg); - - IsEnabledMessage isEnabled(); - - static void setup(TestWakelockApi? api) { - { - const channel = BasicMessageChannel( - 'dev.flutter.pigeon.WakelockApi.toggle', StandardMessageCodec()); - if (api == null) { - channel.setMockMessageHandler(null); - } else { - channel.setMockMessageHandler((dynamic message) async { - final mapMessage = message as Map; - final input = ToggleMessage._fromMap(mapMessage); - api.toggle(input); - return {}; - }); - } - } - { - const channel = BasicMessageChannel( - 'dev.flutter.pigeon.WakelockApi.isEnabled', StandardMessageCodec()); - if (api == null) { - channel.setMockMessageHandler(null); - } else { - channel.setMockMessageHandler((dynamic message) async { - final output = api.isEnabled(); - return {'result': output._toMap()}; - }); - } + return IsEnabledMessage.decode(replyMap['result']!); } } } diff --git a/wakelock_platform_interface/lib/method_channel_wakelock.dart b/wakelock_platform_interface/lib/method_channel_wakelock.dart index cd1052ff..52e8c51a 100644 --- a/wakelock_platform_interface/lib/method_channel_wakelock.dart +++ b/wakelock_platform_interface/lib/method_channel_wakelock.dart @@ -9,7 +9,7 @@ class MethodChannelWakelock extends WakelockPlatformInterface { Future get enabled async { final message = await _api.isEnabled(); - return message.enabled; + return message.enabled!; } @override diff --git a/wakelock_platform_interface/pubspec.yaml b/wakelock_platform_interface/pubspec.yaml index bc0a9889..07a1c3cc 100644 --- a/wakelock_platform_interface/pubspec.yaml +++ b/wakelock_platform_interface/pubspec.yaml @@ -2,7 +2,7 @@ name: wakelock_platform_interface description: >-2 A common platform interface for the wakelock plugin used by the different platform implementations. -version: 0.2.0 +version: 0.2.1 homepage: >-2 https://github.com/creativecreatorormaybenot/wakelock/tree/master/wakelock_platform_interface diff --git a/wakelock_platform_interface/test/messages.dart b/wakelock_platform_interface/test/messages.dart new file mode 100644 index 00000000..14eb3e81 --- /dev/null +++ b/wakelock_platform_interface/test/messages.dart @@ -0,0 +1,45 @@ +// Autogenerated from Pigeon (v0.2.1), do not edit directly. +// See also: https://pub.dev/packages/pigeon +// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import +// @dart = 2.12 +import 'dart:async'; +import 'dart:typed_data' show Uint8List, Int32List, Int64List, Float64List; +import 'package:flutter/services.dart'; +import 'package:flutter_test/flutter_test.dart'; + +import 'package:wakelock_platform_interface/messages.dart'; + +abstract class TestWakelockApi { + void toggle(ToggleMessage arg); + IsEnabledMessage isEnabled(); + static void setup(TestWakelockApi? api) { + { + const BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.WakelockApi.toggle', StandardMessageCodec()); + if (api == null) { + channel.setMockMessageHandler(null); + } else { + channel.setMockMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.WakelockApi.toggle was null. Expected ToggleMessage.'); + final ToggleMessage input = ToggleMessage.decode(message!); + api.toggle(input); + return {}; + }); + } + } + { + const BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.WakelockApi.isEnabled', StandardMessageCodec()); + if (api == null) { + channel.setMockMessageHandler(null); + } else { + channel.setMockMessageHandler((Object? message) async { + // ignore message + final IsEnabledMessage output = api.isEnabled(); + return {'result': output.encode()}; + }); + } + } + } +} diff --git a/wakelock_platform_interface/test/wakelock_platform_interface_test.dart b/wakelock_platform_interface/test/wakelock_platform_interface_test.dart index 130cb03a..da5fb4a8 100644 --- a/wakelock_platform_interface/test/wakelock_platform_interface_test.dart +++ b/wakelock_platform_interface/test/wakelock_platform_interface_test.dart @@ -3,6 +3,8 @@ import 'package:wakelock_platform_interface/messages.dart'; import 'package:wakelock_platform_interface/method_channel_wakelock.dart'; import 'package:wakelock_platform_interface/wakelock_platform_interface.dart'; +import 'messages.dart'; + class _ApiLogger implements TestWakelockApi { final List log = []; late ToggleMessage toggleMessage;