@@ -5399,4 +5399,59 @@ void main() {
5399
5399
);
5400
5400
expect (count, 1 ); // The `onSelectionChanged` will not be triggered.
5401
5401
});
5402
+
5403
+ testWidgets ("Off-screen selected text doesn't throw exception" , (WidgetTester tester) async {
5404
+ // This is a regression test for https://github.com/flutter/flutter/issues/123527
5405
+
5406
+ TextSelection ? selection;
5407
+ await tester.pumpWidget (
5408
+ MaterialApp (
5409
+ home: Material (
5410
+ child: Builder (
5411
+ builder: (BuildContext context) {
5412
+ return Column (
5413
+ children: < Widget > [
5414
+ Expanded (
5415
+ child: ListView .builder (
5416
+ itemCount: 100 ,
5417
+ itemBuilder: (BuildContext context, int index) {
5418
+ return SelectableText (
5419
+ 'I love Flutter! $index ' ,
5420
+ onSelectionChanged: (TextSelection s, _) {
5421
+ selection = s;
5422
+ },
5423
+ );
5424
+ },
5425
+ ),
5426
+ ),
5427
+ TextButton (
5428
+ onPressed: () {
5429
+ Navigator .pop (context);
5430
+ },
5431
+ child: const Text ('Pop' ),
5432
+ ),
5433
+ ],
5434
+ );
5435
+ }
5436
+ ),
5437
+ ),
5438
+ ));
5439
+
5440
+ expect (selection, null );
5441
+
5442
+ final Offset selectableTextStart = tester.getTopLeft (find.byType (SelectableText ).first);
5443
+ final TestGesture gesture = await tester.startGesture (selectableTextStart + const Offset (50 , 5 ));
5444
+ await tester.pump (const Duration (milliseconds: 500 ));
5445
+ await gesture.up ();
5446
+
5447
+ expect (selection, isNotNull);
5448
+
5449
+ await tester.drag (find.byType (ListView ), const Offset (0.0 , - 3000.0 ));
5450
+ await tester.pumpAndSettle ();
5451
+
5452
+ await tester.tap (find.text ('Pop' ));
5453
+ await tester.pumpAndSettle ();
5454
+
5455
+ expect (tester.takeException (), isNull);
5456
+ });
5402
5457
}
0 commit comments