@@ -67,6 +67,9 @@ class CustomRefreshIndicator extends StatefulWidget {
6767 /// To better understand this data, look at example app.
6868 final IndicatorController controller;
6969
70+ /// Sets axis that can start refresh drag
71+ final RefreshAxis axis;
72+
7073 CustomRefreshIndicator ({
7174 Key key,
7275 @required this .child,
@@ -80,6 +83,7 @@ class CustomRefreshIndicator extends StatefulWidget {
8083 this .loadingToIdleDuration = const Duration (milliseconds: 100 ),
8184 this .leadingGlowVisible = false ,
8285 this .trailingGlowVisible = true ,
86+ this .axis = RefreshAxis .any,
8387 }) : assert (child != null , 'child argument cannot be null' ),
8488 assert (builder != null , 'builder argument cannot be null' ),
8589 super (key: key);
@@ -153,7 +157,8 @@ class _CustomRefreshIndicatorState extends State<CustomRefreshIndicator>
153157 }
154158
155159 bool _handleScrollStartNotification (ScrollStartNotification notification) {
156- _canStart = notification.metrics.extentBefore == 0 &&
160+ _canStart = _isAxisDirectionValid (notification.metrics.axisDirection) &&
161+ notification.metrics.extentBefore == 0 &&
157162 controller.state == IndicatorState .idle;
158163
159164 if (_canStart) controller._setIndicatorState (IndicatorState .dragging);
@@ -162,6 +167,17 @@ class _CustomRefreshIndicatorState extends State<CustomRefreshIndicator>
162167 return false ;
163168 }
164169
170+ bool _isAxisDirectionValid (AxisDirection direction) {
171+ switch (widget.axis) {
172+ case RefreshAxis .vertical:
173+ return direction == AxisDirection .up || direction == AxisDirection .down;
174+ case RefreshAxis .horizontal:
175+ return direction == AxisDirection .left || direction == AxisDirection .right;
176+ default :
177+ return true ;
178+ }
179+ }
180+
165181 bool _handleScrollUpdateNotification (ScrollUpdateNotification notification) {
166182 /// hide when list starts to scroll
167183 if (controller.state == IndicatorState .dragging ||
@@ -289,3 +305,9 @@ class _CustomRefreshIndicatorState extends State<CustomRefreshIndicator>
289305 controller,
290306 );
291307}
308+
309+ enum RefreshAxis {
310+ vertical,
311+ horizontal,
312+ any,
313+ }
0 commit comments