Skip to content

Commit

Permalink
Fix a type casting error in text_input.dart (flutter#109635)
Browse files Browse the repository at this point in the history
  • Loading branch information
LongCatIsLooong authored Aug 17, 2022
1 parent 3d94a01 commit 8caa14e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/flutter/lib/src/services/text_input.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1523,7 +1523,7 @@ RawFloatingCursorPoint _toTextPoint(FloatingCursorDragState state, Map<String, d
assert(encoded['X'] != null, 'You must provide a value for the horizontal location of the floating cursor.');
assert(encoded['Y'] != null, 'You must provide a value for the vertical location of the floating cursor.');
final Offset offset = state == FloatingCursorDragState.Update
? Offset(encoded['X'] as double, encoded['Y'] as double)
? Offset((encoded['X'] as num).toDouble(), (encoded['Y'] as num).toDouble())
: Offset.zero;
return RawFloatingCursorPoint(offset: offset, state: state);
}
Expand Down
27 changes: 27 additions & 0 deletions packages/flutter/test/services/text_input_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,33 @@ void main() {
expect(record[0].exception.toString(), matches(RegExp(r'\brange.start >= 0 && range.start <= text.length\b')));
expect(record[0].exception.toString(), matches(RegExp(r'\bRange start 2 is out of text of length 1\b')));
});

test('FloatingCursor coordinates type-casting', () async {
// Regression test for https://github.com/flutter/flutter/issues/109632.
final List<FlutterErrorDetails> errors = <FlutterErrorDetails>[];
FlutterError.onError = errors.add;

final FakeTextInputClient client = FakeTextInputClient(const TextEditingValue(text: 'test3'));
const TextInputConfiguration configuration = TextInputConfiguration();
TextInput.attach(client, configuration);

final ByteData? messageBytes = const JSONMessageCodec().encodeMessage(<String, dynamic>{
'method': 'TextInputClient.updateFloatingCursor',
'args': <dynamic>[
-1,
'FloatingCursorDragState.update',
<String, dynamic>{ 'X': 2, 'Y': 3 },
],
});

await ServicesBinding.instance.defaultBinaryMessenger.handlePlatformMessage(
'flutter/textinput',
messageBytes,
(ByteData? _) {},
);

expect(errors, isEmpty);
});
});

group('TextInputConfiguration', () {
Expand Down

0 comments on commit 8caa14e

Please sign in to comment.