Skip to content

Commit c68fa09

Browse files
authored
[pigeon] Migrates off old BinaryMessenger API (flutter#3600)
[pigeon] Migrates off old BinaryMessenger API
1 parent 6502403 commit c68fa09

File tree

23 files changed

+59
-35
lines changed

23 files changed

+59
-35
lines changed

packages/pigeon/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 9.1.4
2+
3+
* Migrates off deprecated `BinaryMessenger` API.
4+
15
## 9.1.3
26

37
* [cpp] Requires passing any non-nullable fields of generated data classes as

packages/pigeon/lib/dart_generator.dart

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,10 @@ $resultAt != null
296296

297297
indent.write('abstract class ${api.name} ');
298298
indent.addScoped('{', '}', () {
299+
if (isMockHandler) {
300+
indent.writeln(
301+
'static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => TestDefaultBinaryMessengerBinding.instance;');
302+
}
299303
indent
300304
.writeln('static const MessageCodec<Object?> codec = $codecName();');
301305
indent.newln();
@@ -332,16 +336,18 @@ $resultAt != null
332336
'binaryMessenger: binaryMessenger);',
333337
);
334338
});
335-
final String messageHandlerSetter =
336-
isMockHandler ? 'setMockMessageHandler' : 'setMessageHandler';
339+
final String messageHandlerSetterWithOpeningParentheses = isMockHandler
340+
? '_testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler<Object?>(channel, '
341+
: 'channel.setMessageHandler(';
337342
indent.write('if (api == null) ');
338343
indent.addScoped('{', '}', () {
339-
indent.writeln('channel.$messageHandlerSetter(null);');
344+
indent.writeln(
345+
'${messageHandlerSetterWithOpeningParentheses}null);');
340346
}, addTrailingNewline: false);
341347
indent.add(' else ');
342348
indent.addScoped('{', '}', () {
343349
indent.write(
344-
'channel.$messageHandlerSetter((Object? message) async ',
350+
'$messageHandlerSetterWithOpeningParentheses(Object? message) async ',
345351
);
346352
indent.addScoped('{', '});', () {
347353
final String returnType =

packages/pigeon/lib/generator_tools.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import 'ast.dart';
1111
/// The current version of pigeon.
1212
///
1313
/// This must match the version in pubspec.yaml.
14-
const String pigeonVersion = '9.1.3';
14+
const String pigeonVersion = '9.1.4';
1515

1616
/// Read all the content from [stdin] to a String.
1717
String readStdin() {

packages/pigeon/mock_handler_tester/test/message.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44
//
5-
// Autogenerated from Pigeon (v9.1.3), do not edit directly.
5+
// Autogenerated from Pigeon (v9.1.4), do not edit directly.
66
// See also: https://pub.dev/packages/pigeon
77
// 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, unused_shown_name, unnecessary_import
88

packages/pigeon/mock_handler_tester/test/test.dart

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44
//
5-
// Autogenerated from Pigeon (v9.1.3), do not edit directly.
5+
// Autogenerated from Pigeon (v9.1.4), do not edit directly.
66
// See also: https://pub.dev/packages/pigeon
77
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, unnecessary_import
88
// ignore_for_file: avoid_relative_lib_imports
@@ -46,6 +46,8 @@ class _TestHostApiCodec extends StandardMessageCodec {
4646
///
4747
/// This comment also tests multiple line comments.
4848
abstract class TestHostApi {
49+
static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding =>
50+
TestDefaultBinaryMessengerBinding.instance;
4951
static const MessageCodec<Object?> codec = _TestHostApiCodec();
5052

5153
/// This comment is to test documentation comments.
@@ -62,9 +64,12 @@ abstract class TestHostApi {
6264
'dev.flutter.pigeon.MessageApi.initialize', codec,
6365
binaryMessenger: binaryMessenger);
6466
if (api == null) {
65-
channel.setMockMessageHandler(null);
67+
_testBinaryMessengerBinding!.defaultBinaryMessenger
68+
.setMockDecodedMessageHandler<Object?>(channel, null);
6669
} else {
67-
channel.setMockMessageHandler((Object? message) async {
70+
_testBinaryMessengerBinding!.defaultBinaryMessenger
71+
.setMockDecodedMessageHandler<Object?>(channel,
72+
(Object? message) async {
6873
// ignore message
6974
api.initialize();
7075
return <Object?>[];
@@ -76,9 +81,12 @@ abstract class TestHostApi {
7681
'dev.flutter.pigeon.MessageApi.search', codec,
7782
binaryMessenger: binaryMessenger);
7883
if (api == null) {
79-
channel.setMockMessageHandler(null);
84+
_testBinaryMessengerBinding!.defaultBinaryMessenger
85+
.setMockDecodedMessageHandler<Object?>(channel, null);
8086
} else {
81-
channel.setMockMessageHandler((Object? message) async {
87+
_testBinaryMessengerBinding!.defaultBinaryMessenger
88+
.setMockDecodedMessageHandler<Object?>(channel,
89+
(Object? message) async {
8290
assert(message != null,
8391
'Argument for dev.flutter.pigeon.MessageApi.search was null.');
8492
final List<Object?> args = (message as List<Object?>?)!;
@@ -129,6 +137,8 @@ class _TestNestedApiCodec extends StandardMessageCodec {
129137

130138
/// This comment is to test api documentation comments.
131139
abstract class TestNestedApi {
140+
static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding =>
141+
TestDefaultBinaryMessengerBinding.instance;
132142
static const MessageCodec<Object?> codec = _TestNestedApiCodec();
133143

134144
/// This comment is to test method documentation comments.
@@ -142,9 +152,12 @@ abstract class TestNestedApi {
142152
'dev.flutter.pigeon.MessageNestedApi.search', codec,
143153
binaryMessenger: binaryMessenger);
144154
if (api == null) {
145-
channel.setMockMessageHandler(null);
155+
_testBinaryMessengerBinding!.defaultBinaryMessenger
156+
.setMockDecodedMessageHandler<Object?>(channel, null);
146157
} else {
147-
channel.setMockMessageHandler((Object? message) async {
158+
_testBinaryMessengerBinding!.defaultBinaryMessenger
159+
.setMockDecodedMessageHandler<Object?>(channel,
160+
(Object? message) async {
148161
assert(message != null,
149162
'Argument for dev.flutter.pigeon.MessageNestedApi.search was null.');
150163
final List<Object?> args = (message as List<Object?>?)!;

packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/main/java/com/example/alternate_language_test_plugin/CoreTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44
//
5-
// Autogenerated from Pigeon (v9.1.3), do not edit directly.
5+
// Autogenerated from Pigeon (v9.1.4), do not edit directly.
66
// See also: https://pub.dev/packages/pigeon
77

88
package com.example.alternate_language_test_plugin;

packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44
//
5-
// Autogenerated from Pigeon (v9.1.3), do not edit directly.
5+
// Autogenerated from Pigeon (v9.1.4), do not edit directly.
66
// See also: https://pub.dev/packages/pigeon
77

88
#import <Foundation/Foundation.h>

packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44
//
5-
// Autogenerated from Pigeon (v9.1.3), do not edit directly.
5+
// Autogenerated from Pigeon (v9.1.4), do not edit directly.
66
// See also: https://pub.dev/packages/pigeon
77

88
#import "CoreTests.gen.h"

packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/core_tests.gen.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44
//
5-
// Autogenerated from Pigeon (v9.1.3), do not edit directly.
5+
// Autogenerated from Pigeon (v9.1.4), do not edit directly.
66
// See also: https://pub.dev/packages/pigeon
77
// 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, unused_shown_name, unnecessary_import
88

packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/flutter_unittests.gen.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44
//
5-
// Autogenerated from Pigeon (v9.1.3), do not edit directly.
5+
// Autogenerated from Pigeon (v9.1.4), do not edit directly.
66
// See also: https://pub.dev/packages/pigeon
77
// 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, unused_shown_name, unnecessary_import
88

packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/multiple_arity.gen.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44
//
5-
// Autogenerated from Pigeon (v9.1.3), do not edit directly.
5+
// Autogenerated from Pigeon (v9.1.4), do not edit directly.
66
// See also: https://pub.dev/packages/pigeon
77
// 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, unused_shown_name, unnecessary_import
88

packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/non_null_fields.gen.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44
//
5-
// Autogenerated from Pigeon (v9.1.3), do not edit directly.
5+
// Autogenerated from Pigeon (v9.1.4), do not edit directly.
66
// See also: https://pub.dev/packages/pigeon
77
// 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, unused_shown_name, unnecessary_import
88

packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/null_fields.gen.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44
//
5-
// Autogenerated from Pigeon (v9.1.3), do not edit directly.
5+
// Autogenerated from Pigeon (v9.1.4), do not edit directly.
66
// See also: https://pub.dev/packages/pigeon
77
// 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, unused_shown_name, unnecessary_import
88

packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/nullable_returns.gen.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44
//
5-
// Autogenerated from Pigeon (v9.1.3), do not edit directly.
5+
// Autogenerated from Pigeon (v9.1.4), do not edit directly.
66
// See also: https://pub.dev/packages/pigeon
77
// 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, unused_shown_name, unnecessary_import
88

packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/primitive.gen.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44
//
5-
// Autogenerated from Pigeon (v9.1.3), do not edit directly.
5+
// Autogenerated from Pigeon (v9.1.4), do not edit directly.
66
// See also: https://pub.dev/packages/pigeon
77
// 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, unused_shown_name, unnecessary_import
88

packages/pigeon/platform_tests/flutter_null_safe_unit_tests/test/null_safe_test.dart

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ import 'test_util.dart';
2222
NullableCollectionReturnFlutterApi,
2323
])
2424
void main() {
25-
TestWidgetsFlutterBinding.ensureInitialized();
25+
final TestWidgetsFlutterBinding binding =
26+
TestWidgetsFlutterBinding.ensureInitialized();
2627

2728
test('with values filled', () {
2829
final FlutterSearchReply reply = FlutterSearchReply()
@@ -134,7 +135,7 @@ void main() {
134135
NullableArgFlutterApi.setup(mockFlutterApi);
135136

136137
final Completer<int> resultCompleter = Completer<int>();
137-
ServicesBinding.instance.defaultBinaryMessenger.handlePlatformMessage(
138+
binding.defaultBinaryMessenger.handlePlatformMessage(
138139
'dev.flutter.pigeon.NullableArgFlutterApi.doit',
139140
NullableArgFlutterApi.codec.encodeMessage(<Object?>[null]),
140141
(ByteData? data) {
@@ -158,7 +159,7 @@ void main() {
158159
NullableCollectionArgFlutterApi.setup(mockFlutterApi);
159160

160161
final Completer<List<String?>> resultCompleter = Completer<List<String?>>();
161-
ServicesBinding.instance.defaultBinaryMessenger.handlePlatformMessage(
162+
binding.defaultBinaryMessenger.handlePlatformMessage(
162163
'dev.flutter.pigeon.NullableCollectionArgFlutterApi.doit',
163164
NullableCollectionArgFlutterApi.codec.encodeMessage(<Object?>[null]),
164165
(ByteData? data) {
@@ -210,7 +211,7 @@ void main() {
210211
NullableReturnFlutterApi.setup(mockFlutterApi);
211212

212213
final Completer<int?> resultCompleter = Completer<int?>();
213-
ServicesBinding.instance.defaultBinaryMessenger.handlePlatformMessage(
214+
binding.defaultBinaryMessenger.handlePlatformMessage(
214215
'dev.flutter.pigeon.NullableReturnFlutterApi.doit',
215216
NullableReturnFlutterApi.codec.encodeMessage(<Object?>[]),
216217
(ByteData? data) {
@@ -233,7 +234,7 @@ void main() {
233234

234235
final Completer<List<String?>?> resultCompleter =
235236
Completer<List<String?>?>();
236-
ServicesBinding.instance.defaultBinaryMessenger.handlePlatformMessage(
237+
binding.defaultBinaryMessenger.handlePlatformMessage(
237238
'dev.flutter.pigeon.NullableCollectionReturnFlutterApi.doit',
238239
NullableCollectionReturnFlutterApi.codec.encodeMessage(<Object?>[]),
239240
(ByteData? data) {

packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/core_tests.gen.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44
//
5-
// Autogenerated from Pigeon (v9.1.3), do not edit directly.
5+
// Autogenerated from Pigeon (v9.1.4), do not edit directly.
66
// See also: https://pub.dev/packages/pigeon
77
// 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, unused_shown_name, unnecessary_import
88

packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/CoreTests.gen.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44
//
5-
// Autogenerated from Pigeon (v9.1.3), do not edit directly.
5+
// Autogenerated from Pigeon (v9.1.4), do not edit directly.
66
// See also: https://pub.dev/packages/pigeon
77

88
package com.example.test_plugin

packages/pigeon/platform_tests/test_plugin/ios/Classes/CoreTests.gen.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44
//
5-
// Autogenerated from Pigeon (v9.1.3), do not edit directly.
5+
// Autogenerated from Pigeon (v9.1.4), do not edit directly.
66
// See also: https://pub.dev/packages/pigeon
77

88
import Foundation

packages/pigeon/platform_tests/test_plugin/macos/Classes/CoreTests.gen.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44
//
5-
// Autogenerated from Pigeon (v9.1.3), do not edit directly.
5+
// Autogenerated from Pigeon (v9.1.4), do not edit directly.
66
// See also: https://pub.dev/packages/pigeon
77

88
import Foundation

packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44
//
5-
// Autogenerated from Pigeon (v9.1.3), do not edit directly.
5+
// Autogenerated from Pigeon (v9.1.4), do not edit directly.
66
// See also: https://pub.dev/packages/pigeon
77

88
#undef _HAS_EXCEPTIONS

packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44
//
5-
// Autogenerated from Pigeon (v9.1.3), do not edit directly.
5+
// Autogenerated from Pigeon (v9.1.4), do not edit directly.
66
// See also: https://pub.dev/packages/pigeon
77

88
#ifndef PIGEON_CORE_TESTS_GEN_H_

packages/pigeon/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: pigeon
22
description: Code generator tool to make communication between Flutter and the host platform type-safe and easier.
33
repository: https://github.com/flutter/packages/tree/main/packages/pigeon
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3Apigeon
5-
version: 9.1.3 # This must match the version in lib/generator_tools.dart
5+
version: 9.1.4 # This must match the version in lib/generator_tools.dart
66

77
environment:
88
sdk: ">=2.18.0 <4.0.0"

0 commit comments

Comments
 (0)