@@ -132,6 +132,52 @@ void main() {
132132 expect(tester.testTextInput.setClientArgs!['inputAction'], equals(serializedActionName));
133133 }
134134
135+ testWidgets('Text with selection can be shown on the screen when the keyboard shown', (WidgetTester tester) async {
136+ // Regression test for https://github.com/flutter/flutter/issues/119628
137+ final ScrollController scrollController = ScrollController();
138+ final TextEditingController textController = TextEditingController.fromValue(
139+ const TextEditingValue(text: 'I love flutter'),
140+ );
141+
142+ final Widget widget = MaterialApp(
143+ home: Scaffold(
144+ body: SingleChildScrollView(
145+ controller: scrollController,
146+ child: Column(
147+ children: <Widget>[
148+ const SizedBox(height: 1000.0),
149+ SizedBox(
150+ height: 20.0,
151+ child: EditableText(
152+ controller: textController,
153+ backgroundCursorColor: Colors.grey,
154+ focusNode: focusNode,
155+ style: const TextStyle(),
156+ cursorColor: Colors.red,
157+ ),
158+ ),
159+ ],
160+ ),
161+ ),
162+ ),
163+ );
164+ await tester.pumpWidget(widget);
165+
166+ await tester.showKeyboard(find.byType(EditableText));
167+ TestWidgetsFlutterBinding.instance.window.viewInsetsTestValue = const _TestWindowPadding(bottom: 500);
168+ addTearDown(TestWidgetsFlutterBinding.instance.window.clearViewInsetsTestValue);
169+ textController.selection = TextSelection(
170+ baseOffset: 0,
171+ extentOffset: textController.text.length,
172+ );
173+
174+ await tester.pump();
175+
176+ // The offset of the scrollController should change immediately after window changes its metrics.
177+ final double offsetAfter = scrollController.offset;
178+ expect(offsetAfter, isNot(0.0));
179+ });
180+
135181 // Related issue: https://github.com/flutter/flutter/issues/98115
136182 testWidgets('ScheduleShowCaretOnScreen with no animation when the window changes metrics', (WidgetTester tester) async {
137183 final ScrollController scrollController = ScrollController();
@@ -170,6 +216,7 @@ void main() {
170216 await tester.pumpWidget(widget);
171217 await tester.showKeyboard(find.byType(EditableText));
172218 TestWidgetsFlutterBinding.instance.window.viewInsetsTestValue = const _TestWindowPadding(bottom: 500);
219+ addTearDown(TestWidgetsFlutterBinding.instance.window.clearViewInsetsTestValue);
173220 await tester.pump();
174221
175222 // The offset of the scrollController should change immediately after window changes its metrics.
0 commit comments