Skip to content

Commit ee688aa

Browse files
mdebbargoderbauer
authored andcommitted
[web] Inform the engine when read-only flag is flipped (flutter#65499)
1 parent 96a3d37 commit ee688aa

File tree

4 files changed

+65
-2
lines changed

4 files changed

+65
-2
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,13 @@ class TextInputConnection {
880880
TextInput._instance._requestAutofill();
881881
}
882882

883+
/// Requests that the text input control update itself according to the new
884+
/// [TextInputConfiguration].
885+
void updateConfig(TextInputConfiguration configuration) {
886+
assert(attached);
887+
TextInput._instance._updateConfig(configuration);
888+
}
889+
883890
/// Requests that the text input control change its internal state to match the given state.
884891
void setEditingState(TextEditingValue value) {
885892
assert(attached);
@@ -1211,6 +1218,14 @@ class TextInput {
12111218
_scheduleHide();
12121219
}
12131220

1221+
void _updateConfig(TextInputConfiguration configuration) {
1222+
assert(configuration != null);
1223+
_channel.invokeMethod<void>(
1224+
'TextInput.updateConfig',
1225+
configuration.toJson(),
1226+
);
1227+
}
1228+
12141229
void _setEditingState(TextEditingValue value) {
12151230
assert(value != null);
12161231
_channel.invokeMethod<void>(

packages/flutter/lib/src/widgets/editable_text.dart

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1561,15 +1561,22 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
15611561
if (!_shouldCreateInputConnection) {
15621562
_closeInputConnectionIfNeeded();
15631563
} else {
1564-
if (oldWidget.readOnly && _hasFocus)
1564+
if (oldWidget.readOnly && _hasFocus) {
15651565
_openInputConnection();
1566+
}
1567+
}
1568+
1569+
if (kIsWeb && _hasInputConnection) {
1570+
if (oldWidget.readOnly != widget.readOnly) {
1571+
_textInputConnection!.updateConfig(textInputConfiguration);
1572+
}
15661573
}
15671574

15681575
if (widget.style != oldWidget.style) {
15691576
final TextStyle style = widget.style;
15701577
// The _textInputConnection will pick up the new style when it attaches in
15711578
// _openInputConnection.
1572-
if (_textInputConnection != null && _textInputConnection!.attached) {
1579+
if (_hasInputConnection) {
15731580
_textInputConnection!.setStyle(
15741581
fontFamily: style.fontFamily,
15751582
fontSize: style.fontSize,

packages/flutter/test/widgets/editable_text_test.dart

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1436,6 +1436,44 @@ void main() {
14361436
}
14371437
});
14381438

1439+
testWidgets('Sends "updateConfig" when read-only flag is flipped', (WidgetTester tester) async {
1440+
bool readOnly = true;
1441+
StateSetter setState;
1442+
final TextEditingController controller = TextEditingController(text: 'Lorem ipsum dolor sit amet');
1443+
1444+
await tester.pumpWidget(
1445+
MaterialApp(
1446+
home: StatefulBuilder(builder: (BuildContext context, StateSetter stateSetter) {
1447+
setState = stateSetter;
1448+
return EditableText(
1449+
readOnly: readOnly,
1450+
controller: controller,
1451+
backgroundCursorColor: Colors.grey,
1452+
focusNode: focusNode,
1453+
style: textStyle,
1454+
cursorColor: cursorColor,
1455+
);
1456+
}),
1457+
),
1458+
);
1459+
1460+
// Interact with the field to establish the input connection.
1461+
final Offset topLeft = tester.getTopLeft(find.byType(EditableText));
1462+
await tester.tapAt(topLeft + const Offset(0.0, 5.0));
1463+
await tester.pump();
1464+
1465+
expect(tester.testTextInput.hasAnyClients, kIsWeb ? isTrue : isFalse);
1466+
if (kIsWeb) {
1467+
expect(tester.testTextInput.setClientArgs['readOnly'], isTrue);
1468+
}
1469+
1470+
setState(() { readOnly = false; });
1471+
await tester.pump();
1472+
1473+
expect(tester.testTextInput.hasAnyClients, isTrue);
1474+
expect(tester.testTextInput.setClientArgs['readOnly'], isFalse);
1475+
});
1476+
14391477
testWidgets('Fires onChanged when text changes via TextSelectionOverlay', (WidgetTester tester) async {
14401478
String changedValue;
14411479
final Widget widget = MaterialApp(

packages/flutter_test/lib/src/test_text_input.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ class TestTextInput {
9898
_client = methodCall.arguments[0] as int;
9999
setClientArgs = methodCall.arguments[1] as Map<String, dynamic>;
100100
break;
101+
case 'TextInput.updateConfig':
102+
setClientArgs = methodCall.arguments as Map<String, dynamic>;
103+
break;
101104
case 'TextInput.clearClient':
102105
_client = 0;
103106
_isVisible = false;

0 commit comments

Comments
 (0)