@@ -8,7 +8,7 @@ import 'package:flutter/cupertino.dart';
8
8
import 'package:flutter/rendering.dart' ;
9
9
import 'package:flutter/services.dart' ;
10
10
import 'package:flutter/foundation.dart' ;
11
- import 'package:flutter/gestures.dart' show DragStartBehavior;
11
+ import 'package:flutter/gestures.dart' show DragStartBehavior, PointerDeviceKind ;
12
12
import 'package:flutter_test/flutter_test.dart' ;
13
13
14
14
class MockClipboard {
@@ -1791,6 +1791,99 @@ void main() {
1791
1791
expect (controller.selection.extentOffset, 5 );
1792
1792
});
1793
1793
1794
+ testWidgets ('Can select text by dragging with a mouse' , (WidgetTester tester) async {
1795
+ final TextEditingController controller = TextEditingController ();
1796
+
1797
+ await tester.pumpWidget (
1798
+ CupertinoApp (
1799
+ home: Center (
1800
+ child: CupertinoTextField (
1801
+ dragStartBehavior: DragStartBehavior .down,
1802
+ controller: controller,
1803
+ style: const TextStyle (
1804
+ fontFamily: 'Ahem' ,
1805
+ fontSize: 10.0 ,
1806
+ ),
1807
+ ),
1808
+ ),
1809
+ ),
1810
+ );
1811
+
1812
+ const String testValue = 'abc def ghi' ;
1813
+ await tester.enterText (find.byType (CupertinoTextField ), testValue);
1814
+ // Skip past scrolling animation.
1815
+ await tester.pump ();
1816
+ await tester.pump (const Duration (milliseconds: 200 ));
1817
+
1818
+ final Offset ePos = textOffsetToPosition (tester, testValue.indexOf ('e' ));
1819
+ final Offset gPos = textOffsetToPosition (tester, testValue.indexOf ('g' ));
1820
+
1821
+ final TestGesture gesture = await tester.startGesture (ePos, kind: PointerDeviceKind .mouse);
1822
+ await tester.pump ();
1823
+ await gesture.moveTo (gPos);
1824
+ await tester.pump ();
1825
+ await gesture.up ();
1826
+ await tester.pumpAndSettle ();
1827
+
1828
+ expect (controller.selection.baseOffset, testValue.indexOf ('e' ));
1829
+ expect (controller.selection.extentOffset, testValue.indexOf ('g' ));
1830
+ });
1831
+
1832
+ testWidgets ('Continuous dragging does not cause flickering' , (WidgetTester tester) async {
1833
+ int selectionChangedCount = 0 ;
1834
+ const String testValue = 'abc def ghi' ;
1835
+ final TextEditingController controller = TextEditingController (text: testValue);
1836
+
1837
+ controller.addListener (() {
1838
+ selectionChangedCount++ ;
1839
+ });
1840
+
1841
+ await tester.pumpWidget (
1842
+ CupertinoApp (
1843
+ home: Center (
1844
+ child: CupertinoTextField (
1845
+ dragStartBehavior: DragStartBehavior .down,
1846
+ controller: controller,
1847
+ style: const TextStyle (
1848
+ fontFamily: 'Ahem' ,
1849
+ fontSize: 10.0 ,
1850
+ ),
1851
+ ),
1852
+ ),
1853
+ ),
1854
+ );
1855
+
1856
+ final Offset cPos = textOffsetToPosition (tester, 2 ); // Index of 'c'.
1857
+ final Offset gPos = textOffsetToPosition (tester, 8 ); // Index of 'g'.
1858
+ final Offset hPos = textOffsetToPosition (tester, 9 ); // Index of 'h'.
1859
+
1860
+ // Drag from 'c' to 'g'.
1861
+ final TestGesture gesture = await tester.startGesture (cPos, kind: PointerDeviceKind .mouse);
1862
+ await tester.pump ();
1863
+ await gesture.moveTo (gPos);
1864
+ await tester.pumpAndSettle ();
1865
+
1866
+ expect (selectionChangedCount, isNonZero);
1867
+ selectionChangedCount = 0 ;
1868
+ expect (controller.selection.baseOffset, 2 );
1869
+ expect (controller.selection.extentOffset, 8 );
1870
+
1871
+ // Tiny movement shouldn't cause text selection to change.
1872
+ await gesture.moveTo (gPos + const Offset (4.0 , 0.0 ));
1873
+ await tester.pumpAndSettle ();
1874
+ expect (selectionChangedCount, 0 );
1875
+
1876
+ // Now a text selection change will occur after a significant movement.
1877
+ await gesture.moveTo (hPos);
1878
+ await tester.pump ();
1879
+ await gesture.up ();
1880
+ await tester.pumpAndSettle ();
1881
+
1882
+ expect (selectionChangedCount, 1 );
1883
+ expect (controller.selection.baseOffset, 2 );
1884
+ expect (controller.selection.extentOffset, 9 );
1885
+ });
1886
+
1794
1887
testWidgets (
1795
1888
'text field respects theme' ,
1796
1889
(WidgetTester tester) async {
0 commit comments