@@ -433,6 +433,63 @@ void main() {
433
433
},
434
434
);
435
435
436
+ testWidgets ('Text field drops selection color when losing focus' , (WidgetTester tester) async {
437
+ // Regression test for https://github.com/flutter/flutter/issues/103341.
438
+ final Key key1 = UniqueKey ();
439
+ final Key key2 = UniqueKey ();
440
+ final TextEditingController controller1 = TextEditingController ();
441
+ const Color selectionColor = Colors .orange;
442
+ const Color cursorColor = Colors .red;
443
+
444
+ await tester.pumpWidget (
445
+ CupertinoApp (
446
+ home: Center (
447
+ child: DefaultSelectionStyle (
448
+ selectionColor: selectionColor,
449
+ cursorColor: cursorColor,
450
+ child: Column (
451
+ children: < Widget > [
452
+ CupertinoTextField (
453
+ key: key1,
454
+ controller: controller1,
455
+ ),
456
+ CupertinoTextField (key: key2),
457
+ ],
458
+ ),
459
+ ),
460
+ ),
461
+ ),
462
+ );
463
+
464
+ const TextSelection selection = TextSelection (baseOffset: 0 , extentOffset: 4 );
465
+ final EditableTextState state1 = tester.state <EditableTextState >(find.byType (EditableText ).first);
466
+ final EditableTextState state2 = tester.state <EditableTextState >(find.byType (EditableText ).last);
467
+
468
+ await tester.tap (find.byKey (key1));
469
+ await tester.enterText (find.byKey (key1), 'abcd' );
470
+ await tester.pump ();
471
+
472
+ await tester.tap (find.byKey (key2));
473
+ await tester.enterText (find.byKey (key2), 'dcba' );
474
+ await tester.pump ();
475
+
476
+ // Focus and selection is active on first TextField, so the second TextFields
477
+ // selectionColor should be dropped.
478
+ await tester.tap (find.byKey (key1));
479
+ controller1.selection = const TextSelection (baseOffset: 0 , extentOffset: 4 );
480
+ await tester.pump ();
481
+ expect (controller1.selection, selection);
482
+ expect (state1.widget.selectionColor, selectionColor);
483
+ expect (state2.widget.selectionColor, null );
484
+
485
+ // Focus and selection is active on second TextField, so the first TextFields
486
+ // selectionColor should be dropped.
487
+ await tester.tap (find.byKey (key2));
488
+ await tester.pump ();
489
+ expect (state1.widget.selectionColor, null );
490
+ expect (state2.widget.selectionColor, selectionColor);
491
+ });
492
+
436
493
testWidgets (
437
494
'multi-lined text fields are intrinsically taller no-strut' ,
438
495
(WidgetTester tester) async {
0 commit comments