From 57a93419b4d3f952733583cca3ae436c38670509 Mon Sep 17 00:00:00 2001 From: chunhtai <47866232+chunhtai@users.noreply.github.com> Date: Thu, 2 Jan 2020 16:19:52 -0800 Subject: [PATCH] =?UTF-8?q?EditableText=20should=20not=20update=20textinpu?= =?UTF-8?q?t=20style=20when=20the=20textinput=20is=20=E2=80=A6=20(#47904)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/src/widgets/editable_text.dart | 18 ++-- .../test/widgets/editable_text_test.dart | 83 +++++++++++++++++++ 2 files changed, 94 insertions(+), 7 deletions(-) diff --git a/packages/flutter/lib/src/widgets/editable_text.dart b/packages/flutter/lib/src/widgets/editable_text.dart index bbfaffaabd..54e2f14fcc 100644 --- a/packages/flutter/lib/src/widgets/editable_text.dart +++ b/packages/flutter/lib/src/widgets/editable_text.dart @@ -1172,13 +1172,17 @@ class EditableTextState extends State with AutomaticKeepAliveClien } if (widget.style != oldWidget.style) { final TextStyle style = widget.style; - _textInputConnection?.setStyle( - fontFamily: style.fontFamily, - fontSize: style.fontSize, - fontWeight: style.fontWeight, - textDirection: _textDirection, - textAlign: widget.textAlign, - ); + // The _textInputConnection will pick up the new style when it attaches in + // _openInputConnection. + if (_textInputConnection != null && _textInputConnection.attached) { + _textInputConnection.setStyle( + fontFamily: style.fontFamily, + fontSize: style.fontSize, + fontWeight: style.fontWeight, + textDirection: _textDirection, + textAlign: widget.textAlign, + ); + } } } diff --git a/packages/flutter/test/widgets/editable_text_test.dart b/packages/flutter/test/widgets/editable_text_test.dart index e0f74ed5ed..3d6bce3247 100644 --- a/packages/flutter/test/widgets/editable_text_test.dart +++ b/packages/flutter/test/widgets/editable_text_test.dart @@ -513,6 +513,89 @@ void main() { expect(handles[1].localToGlobal(Offset.zero), const Offset(197.0, 17.0)); }); + testWidgets('can update style of previous activated EditableText', (WidgetTester tester) async { + final Key key1 = UniqueKey(); + final Key key2 = UniqueKey(); + await tester.pumpWidget( + MediaQuery( + data: const MediaQueryData(devicePixelRatio: 1.0), + child: Directionality( + textDirection: TextDirection.ltr, + child: FocusScope( + node: focusScopeNode, + autofocus: true, + child: Column( + children: [ + EditableText( + key: key1, + controller: TextEditingController(), + backgroundCursorColor: Colors.grey, + focusNode: focusNode, + style: const TextStyle(fontSize: 9), + cursorColor: cursorColor, + ), + EditableText( + key: key2, + controller: TextEditingController(), + backgroundCursorColor: Colors.grey, + focusNode: focusNode, + style: const TextStyle(fontSize: 9), + cursorColor: cursorColor, + ), + ], + ), + ), + ), + ), + ); + + await tester.tap(find.byKey(key1)); + await tester.showKeyboard(find.byKey(key1)); + controller.text = 'test'; + await tester.idle(); + RenderBox renderEditable = tester.renderObject(find.byKey(key1)); + expect(renderEditable.size.height, 9.0); + // Taps the other EditableText to deactivate the first one. + await tester.tap(find.byKey(key2)); + await tester.showKeyboard(find.byKey(key2)); + // Updates the style. + await tester.pumpWidget( + MediaQuery( + data: const MediaQueryData(devicePixelRatio: 1.0), + child: Directionality( + textDirection: TextDirection.ltr, + child: FocusScope( + node: focusScopeNode, + autofocus: true, + child: Column( + children: [ + EditableText( + key: key1, + controller: TextEditingController(), + backgroundCursorColor: Colors.grey, + focusNode: focusNode, + style: const TextStyle(fontSize: 20), + cursorColor: cursorColor, + ), + EditableText( + key: key2, + controller: TextEditingController(), + backgroundCursorColor: Colors.grey, + focusNode: focusNode, + style: const TextStyle(fontSize: 9), + cursorColor: cursorColor, + ), + ], + ), + ), + ), + ), + ); + renderEditable = tester.renderObject(find.byKey(key1)); + expect(renderEditable.size.height, 20.0); + expect(tester.takeException(), null); + }); + testWidgets('Multiline keyboard with newline action is requested when maxLines = null', (WidgetTester tester) async { await tester.pumpWidget( MediaQuery(