Skip to content

Commit

Permalink
[CP] Fix a type casting error in text_input.dart (flutter#109635) (fl…
Browse files Browse the repository at this point in the history
…utter#114806)

(cherry picked from commit 8caa14e)

Co-authored-by: LongCatIsLooong <[email protected]>
Co-authored-by: Casey Hillers <[email protected]>
  • Loading branch information
3 people authored Nov 9, 2022
1 parent a1b2976 commit 52b3dc2
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 @@ -1510,7 +1510,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 52b3dc2

Please sign in to comment.