2
2
// Use of this source code is governed by a BSD-style license that can be
3
3
// found in the LICENSE file.
4
4
5
-
6
5
import 'package:flutter/foundation.dart' ;
6
+ import 'package:flutter/gestures.dart' ;
7
7
import 'package:flutter/material.dart' ;
8
8
import 'package:flutter/rendering.dart' ;
9
9
import 'package:flutter/src/physics/utils.dart' show nearEqual;
@@ -12,6 +12,113 @@ import 'package:flutter_test/flutter_test.dart';
12
12
import '../rendering/mock_canvas.dart' ;
13
13
14
14
void main () {
15
+ // Regression test for https://github.com/flutter/flutter/issues/105833
16
+ testWidgets ('Drag gesture uses provided gesture settings' , (WidgetTester tester) async {
17
+ RangeValues values = const RangeValues (0.1 , 0.5 );
18
+ bool dragStarted = false ;
19
+ final Key sliderKey = UniqueKey ();
20
+
21
+ await tester.pumpWidget (
22
+ MaterialApp (
23
+ home: Directionality (
24
+ textDirection: TextDirection .ltr,
25
+ child: StatefulBuilder (
26
+ builder: (BuildContext context, StateSetter setState) {
27
+ return Material (
28
+ child: Center (
29
+ child: GestureDetector (
30
+ behavior: HitTestBehavior .deferToChild,
31
+ onHorizontalDragStart: (DragStartDetails details) {
32
+ dragStarted = true ;
33
+ },
34
+ child: MediaQuery (
35
+ data: MediaQuery .of (context).copyWith (gestureSettings: const DeviceGestureSettings (touchSlop: 20 )),
36
+ child: RangeSlider (
37
+ key: sliderKey,
38
+ values: values,
39
+ onChanged: (RangeValues newValues) {
40
+ setState (() {
41
+ values = newValues;
42
+ });
43
+ },
44
+ ),
45
+ ),
46
+ ),
47
+ ),
48
+ );
49
+ },
50
+ ),
51
+ ),
52
+ ),
53
+ );
54
+
55
+ TestGesture drag = await tester.startGesture (tester.getCenter (find.byKey (sliderKey)));
56
+ await tester.pump (kPressTimeout);
57
+
58
+ // Less than configured touch slop, more than default touch slop
59
+ await drag.moveBy (const Offset (19.0 , 0 ));
60
+ await tester.pump ();
61
+
62
+ expect (values, const RangeValues (0.1 , 0.5 ));
63
+ expect (dragStarted, true );
64
+
65
+ dragStarted = false ;
66
+
67
+ await drag.up ();
68
+ await tester.pumpAndSettle ();
69
+
70
+ drag = await tester.startGesture (tester.getCenter (find.byKey (sliderKey)));
71
+ await tester.pump (kPressTimeout);
72
+
73
+ bool sliderEnd = false ;
74
+
75
+ await tester.pumpWidget (
76
+ MaterialApp (
77
+ home: Directionality (
78
+ textDirection: TextDirection .ltr,
79
+ child: StatefulBuilder (
80
+ builder: (BuildContext context, StateSetter setState) {
81
+ return Material (
82
+ child: Center (
83
+ child: GestureDetector (
84
+ behavior: HitTestBehavior .deferToChild,
85
+ onHorizontalDragStart: (DragStartDetails details) {
86
+ dragStarted = true ;
87
+ },
88
+ child: MediaQuery (
89
+ data: MediaQuery .of (context).copyWith (gestureSettings: const DeviceGestureSettings (touchSlop: 10 )),
90
+ child: RangeSlider (
91
+ key: sliderKey,
92
+ values: values,
93
+ onChanged: (RangeValues newValues) {
94
+ setState (() {
95
+ values = newValues;
96
+ });
97
+ },
98
+ onChangeEnd: (RangeValues newValues) {
99
+ sliderEnd = true ;
100
+ },
101
+ ),
102
+ ),
103
+ ),
104
+ ),
105
+ );
106
+ },
107
+ ),
108
+ ),
109
+ ),
110
+ );
111
+
112
+ // More than touch slop.
113
+ await drag.moveBy (const Offset (12.0 , 0 ));
114
+
115
+ await drag.up ();
116
+ await tester.pumpAndSettle ();
117
+
118
+ expect (sliderEnd, true );
119
+ expect (dragStarted, false );
120
+ });
121
+
15
122
testWidgets ('Range Slider can move when tapped (continuous LTR)' , (WidgetTester tester) async {
16
123
RangeValues values = const RangeValues (0.3 , 0.7 );
17
124
0 commit comments