@@ -251,8 +251,11 @@ void main() {
251
251
});
252
252
253
253
testWidgetsOnMobile ("multi-line is vertically scrollable when text spans more lines than maxLines" , (tester) async {
254
+ final initialText = "The first line of text in the field\n "
255
+ "The second line of text in the field\n "
256
+ "The third line of text in the field" ;
254
257
final controller = AttributedTextEditingController (
255
- text: AttributedText ("A \n B \n C" ),
258
+ text: AttributedText (initialText ),
256
259
);
257
260
258
261
// Pump the widget tree with a SuperTextField with a maxHeight of 2 lines
@@ -265,31 +268,38 @@ void main() {
265
268
maxHeight: 40 ,
266
269
);
267
270
268
- // Move selection to the end of the text
269
- // TODO: change to simulate user input when IME simulation is available
270
- controller.selection = const TextSelection .collapsed (offset: 5 );
271
+ double getTextBottom () {
272
+ return tester.getBottomRight (find.byType (SuperTextField )).dy;
273
+ }
274
+
275
+ double getViewportBottom () {
276
+ return tester.getBottomRight (find.byType (SuperText )).dy;
277
+ }
278
+
279
+ // Ensure the text field has not yet scrolled.
280
+ expect (getTextBottom (), lessThan (getViewportBottom ()));
281
+
282
+ // Scroll down to reveal the last line of text.
283
+ await tester.drag (find.byType (SuperTextField ), const Offset (0 , - 1000.0 ));
271
284
await tester.pumpAndSettle ();
272
285
273
286
// Ensure the text field has scrolled to the bottom.
274
- expect (
275
- SuperTextFieldInspector .findScrollOffset (),
276
- greaterThan (0.0 ),
277
- );
287
+ expect (getTextBottom (), equals (getViewportBottom ()));
278
288
279
- // Scroll upwards towards the top of the text field.
280
- await tester.drag (find.byType (SuperTextField ), const Offset (0 , - 1000 ));
289
+ // Scroll back up to the top of the text field.
290
+ await tester.drag (find.byType (SuperTextField ), const Offset (0 , 1000.0 ));
281
291
await tester.pumpAndSettle ();
282
292
283
293
// Ensure the text field has scrolled back to the top.
284
- expect (
285
- SuperTextFieldInspector .findScrollOffset (),
286
- 0.0 ,
287
- );
294
+ expect (getTextBottom (), lessThan (getViewportBottom ()));
288
295
});
289
296
290
297
testWidgetsOnDesktop ("multi-line is vertically scrollable when text spans more lines than maxLines" , (tester) async {
298
+ final initialText = "The first line of text in the field\n "
299
+ "The second line of text in the field\n "
300
+ "The third line of text in the field" ;
291
301
final controller = AttributedTextEditingController (
292
- text: AttributedText ("A \n B \n C" ),
302
+ text: AttributedText (initialText ),
293
303
);
294
304
295
305
// Pump the widget tree with a SuperTextField with a maxHeight of 2 lines
@@ -302,26 +312,38 @@ void main() {
302
312
maxHeight: 40 ,
303
313
);
304
314
305
- // Move selection to the end of the text
306
- // TODO: change to simulate user input when IME simulation is available
307
- controller.selection = const TextSelection .collapsed (offset: 5 );
315
+ double getTextBottom () {
316
+ return tester.getBottomRight (find.byType (SuperTextField )).dy;
317
+ }
318
+
319
+ double getViewportBottom () {
320
+ return tester.getBottomRight (find.byType (SuperText )).dy;
321
+ }
322
+
323
+ // Ensure the text field has not yet scrolled.
324
+ expect (getTextBottom (), lessThan (getViewportBottom ()));
325
+
326
+ // Scroll down to reveal the last line of text.
327
+ await tester.drag (
328
+ find.byType (SuperTextField ),
329
+ const Offset (0 , - 1000.0 ),
330
+ kind: PointerDeviceKind .trackpad,
331
+ );
308
332
await tester.pumpAndSettle ();
309
333
310
334
// Ensure the text field has scrolled to the bottom.
311
- expect (
312
- SuperTextFieldInspector .findScrollOffset (),
313
- greaterThan (0.0 ),
314
- );
335
+ expect (getTextBottom (), equals (getViewportBottom ()));
315
336
316
- // Scroll upwards towards the top of the text field.
317
- await tester.drag (find.byType (SuperTextField ), const Offset (0 , - 1000 ));
337
+ // Scroll back up to the top of the text field.
338
+ await tester.drag (
339
+ find.byType (SuperTextField ),
340
+ const Offset (0 , 1000.0 ),
341
+ kind: PointerDeviceKind .trackpad,
342
+ );
318
343
await tester.pumpAndSettle ();
319
344
320
345
// Ensure the text field has scrolled back to the top.
321
- expect (
322
- SuperTextFieldInspector .findScrollOffset (),
323
- 0.0 ,
324
- );
346
+ expect (getTextBottom (), lessThan (getViewportBottom ()));
325
347
});
326
348
});
327
349
}
0 commit comments