Skip to content

Commit

Permalink
Provide default method call handler for SystemChannels.textInput (#10…
Browse files Browse the repository at this point in the history
…1087)
  • Loading branch information
fbcouch authored May 12, 2022
1 parent d647755 commit 78885ec
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/flutter/lib/src/services/binding.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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].
///
Expand All @@ -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();
}

Expand Down
6 changes: 6 additions & 0 deletions packages/flutter/lib/src/services/text_input.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions packages/flutter/test/services/binding_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
}

0 comments on commit 78885ec

Please sign in to comment.