Skip to content
This repository has been archived by the owner on Jul 11, 2024. It is now read-only.

Commit

Permalink
Migrate platform_interface to pigeon 0.2.1 (#113)
Browse files Browse the repository at this point in the history
* Migrate platform_interface to pigeon 0.2.1

* Format

* Fix Analysis
  • Loading branch information
creativecreatorormaybenot authored May 14, 2021
1 parent db843e4 commit 5c4906a
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 81 deletions.
4 changes: 4 additions & 0 deletions wakelock_platform_interface/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
6 changes: 6 additions & 0 deletions wakelock_platform_interface/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
include: ../analysis_options.yaml

analyzer:
exclude:
- 'lib/messages.dart'
- 'test/messages.dart'
135 changes: 56 additions & 79 deletions wakelock_platform_interface/lib/messages.dart
Original file line number Diff line number Diff line change
@@ -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<dynamic, dynamic> _toMap() {
final pigeonMap = <dynamic, dynamic>{};
Object encode() {
final Map<Object?, Object?> pigeonMap = <Object?, Object?>{};
pigeonMap['enable'] = enable;
return pigeonMap;
}

// ignore: unused_element
static ToggleMessage _fromMap(Map<dynamic, dynamic> pigeonMap) {
final result = ToggleMessage();
result.enable = pigeonMap['enable'];
return result;
static ToggleMessage decode(Object message) {
final Map<Object?, Object?> pigeonMap = message as Map<Object?, Object?>;
return ToggleMessage()..enable = pigeonMap['enable'] as bool?;
}
}

class IsEnabledMessage {
late bool enabled;
bool? enabled;

// ignore: unused_element
Map<dynamic, dynamic> _toMap() {
final pigeonMap = <dynamic, dynamic>{};
Object encode() {
final Map<Object?, Object?> pigeonMap = <Object?, Object?>{};
pigeonMap['enabled'] = enabled;
return pigeonMap;
}

// ignore: unused_element
static IsEnabledMessage _fromMap(Map<dynamic, dynamic> pigeonMap) {
final result = IsEnabledMessage();
result.enabled = pigeonMap['enabled'];
return result;
static IsEnabledMessage decode(Object message) {
final Map<Object?, Object?> pigeonMap = message as Map<Object?, Object?>;
return IsEnabledMessage()..enabled = pigeonMap['enabled'] as bool?;
}
}

class WakelockApi {
Future<void> toggle(ToggleMessage arg) async {
final requestMap = arg._toMap();
const channel = BasicMessageChannel<dynamic>(
'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<void> toggle(ToggleMessage arg) async {
final Object encoded = arg.encode();
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
'dev.flutter.pigeon.WakelockApi.toggle', const StandardMessageCodec(),
binaryMessenger: _binaryMessenger);
final Map<Object?, Object?>? replyMap =
await channel.send(encoded) as Map<Object?, Object?>?;
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<Object?, Object?> error =
(replyMap['error'] as Map<Object?, Object?>?)!;
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<IsEnabledMessage> isEnabled() async {
const channel = BasicMessageChannel<dynamic>(
'dev.flutter.pigeon.WakelockApi.isEnabled', StandardMessageCodec());

final replyMap = await channel.send(null);
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
'dev.flutter.pigeon.WakelockApi.isEnabled',
const StandardMessageCodec(),
binaryMessenger: _binaryMessenger);
final Map<Object?, Object?>? replyMap =
await channel.send(null) as Map<Object?, Object?>?;
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<Object?, Object?> error =
(replyMap['error'] as Map<Object?, Object?>?)!;
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<dynamic>(
'dev.flutter.pigeon.WakelockApi.toggle', StandardMessageCodec());
if (api == null) {
channel.setMockMessageHandler(null);
} else {
channel.setMockMessageHandler((dynamic message) async {
final mapMessage = message as Map<dynamic, dynamic>;
final input = ToggleMessage._fromMap(mapMessage);
api.toggle(input);
return <dynamic, dynamic>{};
});
}
}
{
const channel = BasicMessageChannel<dynamic>(
'dev.flutter.pigeon.WakelockApi.isEnabled', StandardMessageCodec());
if (api == null) {
channel.setMockMessageHandler(null);
} else {
channel.setMockMessageHandler((dynamic message) async {
final output = api.isEnabled();
return <dynamic, dynamic>{'result': output._toMap()};
});
}
return IsEnabledMessage.decode(replyMap['result']!);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class MethodChannelWakelock extends WakelockPlatformInterface {
Future<bool> get enabled async {
final message = await _api.isEnabled();

return message.enabled;
return message.enabled!;
}

@override
Expand Down
2 changes: 1 addition & 1 deletion wakelock_platform_interface/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
45 changes: 45 additions & 0 deletions wakelock_platform_interface/test/messages.dart
Original file line number Diff line number Diff line change
@@ -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<Object?> channel = BasicMessageChannel<Object?>(
'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 <Object?, Object?>{};
});
}
}
{
const BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
'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 <Object?, Object?>{'result': output.encode()};
});
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> log = [];
late ToggleMessage toggleMessage;
Expand Down

0 comments on commit 5c4906a

Please sign in to comment.