diff --git a/packages/flutter/lib/src/services/text_input.dart b/packages/flutter/lib/src/services/text_input.dart index 6bfe9d8adc..b2ccef4320 100644 --- a/packages/flutter/lib/src/services/text_input.dart +++ b/packages/flutter/lib/src/services/text_input.dart @@ -1877,7 +1877,9 @@ class TextInput { final Map firstArg = args[1] as Map; _currentConnection!._client.performPrivateCommand( firstArg['action'] as String, - firstArg['data'] as Map, + firstArg['data'] == null + ? {} + : firstArg['data'] as Map, ); break; case 'TextInputClient.updateFloatingCursor': diff --git a/packages/flutter/test/services/text_input_test.dart b/packages/flutter/test/services/text_input_test.dart index bd4d9bd67e..a1be567feb 100644 --- a/packages/flutter/test/services/text_input_test.dart +++ b/packages/flutter/test/services/text_input_test.dart @@ -562,6 +562,32 @@ void main() { expect(client.latestMethodCall, 'performPrivateCommand'); }); + test('TextInputClient performPrivateCommand method is called with no data at all', () async { + // Assemble a TextInputConnection so we can verify its change in state. + final FakeTextInputClient client = FakeTextInputClient(TextEditingValue.empty); + const TextInputConfiguration configuration = TextInputConfiguration(); + TextInput.attach(client, configuration); + + expect(client.latestMethodCall, isEmpty); + + // Send performPrivateCommand message. + final ByteData? messageBytes = const JSONMessageCodec().encodeMessage({ + 'args': [ + 1, + jsonDecode('{"action": "actionCommand"}'), // No `data` parameter. + ], + 'method': 'TextInputClient.performPrivateCommand', + }); + await ServicesBinding.instance.defaultBinaryMessenger.handlePlatformMessage( + 'flutter/textinput', + messageBytes, + (ByteData? _) {}, + ); + + expect(client.latestMethodCall, 'performPrivateCommand'); + expect(client.latestPrivateCommandData, {}); + }); + test('TextInputClient showAutocorrectionPromptRect method is called', () async { // Assemble a TextInputConnection so we can verify its change in state. final FakeTextInputClient client = FakeTextInputClient(TextEditingValue.empty); @@ -933,6 +959,7 @@ class FakeTextInputClient with TextInputClient { String latestMethodCall = ''; final List performedSelectors = []; + late Map? latestPrivateCommandData; @override TextEditingValue currentTextEditingValue; @@ -946,8 +973,9 @@ class FakeTextInputClient with TextInputClient { } @override - void performPrivateCommand(String action, Map data) { + void performPrivateCommand(String action, Map? data) { latestMethodCall = 'performPrivateCommand'; + latestPrivateCommandData = data; } @override