Provide default method call handler for SystemChannels.textInput (#101087)

This commit is contained in:
Jami Couch 2022-05-12 17:59:13 -05:00 committed by GitHub
parent d647755ee3
commit 78885ecbeb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 0 deletions

View File

@ -17,6 +17,7 @@ import 'message_codec.dart';
import 'raw_keyboard.dart';
import 'restoration.dart';
import 'system_channels.dart';
import 'text_input.dart';
/// Listens for platform messages and directs them to the [defaultBinaryMessenger].
///
@ -36,6 +37,7 @@ mixin ServicesBinding on BindingBase, SchedulerBinding {
SystemChannels.system.setMessageHandler((dynamic message) => handleSystemMessage(message as Object));
SystemChannels.lifecycle.setMessageHandler(_handleLifecycleMessage);
SystemChannels.platform.setMethodCallHandler(_handlePlatformMessage);
TextInput.ensureInitialized();
readInitialLifecycleStateFromNativeWindow();
}

View File

@ -1575,6 +1575,12 @@ class TextInput {
TextInputAction.emergencyCall,
];
/// Ensure that a [TextInput] instance has been set up so that the platform
/// can handle messages on the text input method channel.
static void ensureInitialized() {
_instance; // ignore: unnecessary_statements
}
/// Begin interacting with the text input control.
///
/// Calling this function helps multiple clients coordinate about which one is

View File

@ -107,4 +107,11 @@ void main() {
await rootBundle.loadString('test_asset2');
expect(flutterAssetsCallCount, 4);
});
test('initInstances sets a default method call handler for SystemChannels.textInput', () async {
final ByteData message = const JSONMessageCodec().encodeMessage(<String, dynamic>{'method': 'TextInput.requestElementsInRect', 'args': null})!;
await ServicesBinding.instance.defaultBinaryMessenger.handlePlatformMessage('flutter/textinput', message, (ByteData? data) {
expect(data, isNotNull);
});
});
}