File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -531,6 +531,10 @@ class EditableTextState extends State<EditableText> implements TextInputClient {
531
531
_openOrCloseInputConnectionIfNeeded ();
532
532
_startOrStopCursorTimerIfNeeded ();
533
533
_updateOrDisposeSelectionOverlayIfNeeded ();
534
+ if (! _hasFocus) {
535
+ // Clear the selection and composition state if this widget lost focus.
536
+ _value = new TextEditingValue (text: _value.text);
537
+ }
534
538
}
535
539
536
540
@override
Original file line number Diff line number Diff line change @@ -1503,4 +1503,41 @@ void main() {
1503
1503
expect (scrollableState.position.pixels, isNot (equals (0.0 )));
1504
1504
}
1505
1505
);
1506
+
1507
+ testWidgets (
1508
+ 'Text field drops selection when losing focus' ,
1509
+ (WidgetTester tester) async {
1510
+ final Key key1 = new UniqueKey ();
1511
+ final TextEditingController controller1 = new TextEditingController ();
1512
+ final Key key2 = new UniqueKey ();
1513
+
1514
+ Widget builder () {
1515
+ return overlay (new Center (
1516
+ child: new Material (
1517
+ child: new Column (
1518
+ children: < Widget > [
1519
+ new TextField (
1520
+ key: key1,
1521
+ controller: controller1
1522
+ ),
1523
+ new TextField (key: key2),
1524
+ ],
1525
+ ),
1526
+ ),
1527
+ ));
1528
+ }
1529
+
1530
+ await tester.pumpWidget (builder ());
1531
+ await tester.tap (find.byKey (key1));
1532
+ await tester.enterText (find.byKey (key1), 'abcd' );
1533
+ await tester.pump ();
1534
+ controller1.selection = const TextSelection (baseOffset: 0 , extentOffset: 3 );
1535
+ await tester.pump ();
1536
+ expect (controller1.selection, isNot (equals (TextRange .empty)));
1537
+
1538
+ await tester.tap (find.byKey (key2));
1539
+ await tester.pump ();
1540
+ expect (controller1.selection, equals (TextRange .empty));
1541
+ }
1542
+ );
1506
1543
}
You can’t perform that action at this time.
0 commit comments