Skip to content

Commit 52b3dc2

Browse files
AlexV525LongCatIsLooongCasey Hillers
authored
[CP] Fix a type casting error in text_input.dart (flutter#109635) (flutter#114806)
(cherry picked from commit 8caa14e) Co-authored-by: LongCatIsLooong <[email protected]> Co-authored-by: Casey Hillers <[email protected]>
1 parent a1b2976 commit 52b3dc2

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

packages/flutter/lib/src/services/text_input.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -1510,7 +1510,7 @@ RawFloatingCursorPoint _toTextPoint(FloatingCursorDragState state, Map<String, d
15101510
assert(encoded['X'] != null, 'You must provide a value for the horizontal location of the floating cursor.');
15111511
assert(encoded['Y'] != null, 'You must provide a value for the vertical location of the floating cursor.');
15121512
final Offset offset = state == FloatingCursorDragState.Update
1513-
? Offset(encoded['X'] as double, encoded['Y'] as double)
1513+
? Offset((encoded['X'] as num).toDouble(), (encoded['Y'] as num).toDouble())
15141514
: Offset.zero;
15151515
return RawFloatingCursorPoint(offset: offset, state: state);
15161516
}

packages/flutter/test/services/text_input_test.dart

+27
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,33 @@ void main() {
241241
expect(record[0].exception.toString(), matches(RegExp(r'\brange.start >= 0 && range.start <= text.length\b')));
242242
expect(record[0].exception.toString(), matches(RegExp(r'\bRange start 2 is out of text of length 1\b')));
243243
});
244+
245+
test('FloatingCursor coordinates type-casting', () async {
246+
// Regression test for https://github.com/flutter/flutter/issues/109632.
247+
final List<FlutterErrorDetails> errors = <FlutterErrorDetails>[];
248+
FlutterError.onError = errors.add;
249+
250+
final FakeTextInputClient client = FakeTextInputClient(const TextEditingValue(text: 'test3'));
251+
const TextInputConfiguration configuration = TextInputConfiguration();
252+
TextInput.attach(client, configuration);
253+
254+
final ByteData? messageBytes = const JSONMessageCodec().encodeMessage(<String, dynamic>{
255+
'method': 'TextInputClient.updateFloatingCursor',
256+
'args': <dynamic>[
257+
-1,
258+
'FloatingCursorDragState.update',
259+
<String, dynamic>{ 'X': 2, 'Y': 3 },
260+
],
261+
});
262+
263+
await ServicesBinding.instance.defaultBinaryMessenger.handlePlatformMessage(
264+
'flutter/textinput',
265+
messageBytes,
266+
(ByteData? _) {},
267+
);
268+
269+
expect(errors, isEmpty);
270+
});
244271
});
245272

246273
group('TextInputConfiguration', () {

0 commit comments

Comments
 (0)