Skip to content

Commit 5516d06

Browse files
author
Kamil Klyta
committed
Extracted axis direction and user scroll direction to controller
1 parent 10e7a43 commit 5516d06

File tree

2 files changed

+14
-19
lines changed

2 files changed

+14
-19
lines changed

lib/src/custom_refresh_indicator.dart

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,6 @@ class _CustomRefreshIndicatorState extends State<CustomRefreshIndicator>
4040
/// Whether custom refresh indicator can change [IndicatorState] from `idle` to `draging`
4141
bool _canStart = false;
4242

43-
/// Direction in which user is scrolling
44-
ScrollDirection _userScrollingDirection;
45-
46-
/// The direction in which list scrolls
47-
AxisDirection _axisDirection;
4843
double _dragOffset;
4944

5045
AnimationController _animationController;
@@ -60,13 +55,9 @@ class _CustomRefreshIndicatorState extends State<CustomRefreshIndicator>
6055
void initState() {
6156
_dragOffset = 0;
6257
_canStart = false;
63-
_axisDirection = AxisDirection.down;
64-
_userScrollingDirection = ScrollDirection.idle;
6558

6659
_customRefreshIndicatorData = IndicatorController(
6760
value: _kInitialValue,
68-
direction: _axisDirection,
69-
scrollingDirection: _userScrollingDirection,
7061
);
7162

7263
_animationController = AnimationController(
@@ -91,8 +82,6 @@ class _CustomRefreshIndicatorState extends State<CustomRefreshIndicator>
9182
void _updateCustomRefreshIndicatorData() {
9283
_customRefreshIndicatorData.updateAndNotify(
9384
value: _animationController?.value ?? _kInitialValue,
94-
direction: _axisDirection,
95-
scrollingDirection: _userScrollingDirection,
9685
);
9786
}
9887

@@ -112,7 +101,7 @@ class _CustomRefreshIndicatorState extends State<CustomRefreshIndicator>
112101

113102
if (_canStart) controller._setIndicatorState(IndicatorState.draging);
114103

115-
_axisDirection = notification.metrics.axisDirection;
104+
controller._setAxisDirection(notification.metrics.axisDirection);
116105
return false;
117106
}
118107

@@ -152,7 +141,7 @@ class _CustomRefreshIndicatorState extends State<CustomRefreshIndicator>
152141
}
153142

154143
bool _handleUserScrollNotification(UserScrollNotification notification) {
155-
_userScrollingDirection = notification.direction;
144+
controller._setScrollingDirection(notification.direction);
156145
return false;
157146
}
158147

lib/src/definitions.dart

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,28 +56,28 @@ class IndicatorController extends ChangeNotifier {
5656
IndicatorController({
5757
@required double value,
5858
AxisDirection direction,
59-
@required ScrollDirection scrollingDirection,
59+
ScrollDirection scrollingDirection,
6060
IndicatorState state,
6161
}) : _state = state ?? IndicatorState.idle,
62-
_scrollingDirection = scrollingDirection,
62+
_scrollingDirection = scrollingDirection ?? ScrollDirection.idle,
6363
_direction = direction ?? AxisDirection.down,
6464
_value = value;
6565

6666
@protected
6767
@visibleForTesting
6868
void updateAndNotify({
6969
@required double value,
70-
@required AxisDirection direction,
71-
@required ScrollDirection scrollingDirection,
7270
}) {
7371
_value = value;
74-
_direction = direction;
75-
_scrollingDirection = scrollingDirection;
7672

7773
notifyListeners();
7874
}
7975

8076
ScrollDirection _scrollingDirection;
77+
void _setScrollingDirection(ScrollDirection userScrollDirection) {
78+
_scrollingDirection = userScrollDirection;
79+
notifyListeners();
80+
}
8181

8282
/// Direction in which user is scrolling
8383
ScrollDirection get scrollingDirection => _scrollingDirection;
@@ -93,6 +93,12 @@ class IndicatorController extends ChangeNotifier {
9393

9494
AxisDirection _direction;
9595

96+
/// Sets the direction in which list scrolls
97+
void _setAxisDirection(AxisDirection direction) {
98+
_direction = direction;
99+
notifyListeners();
100+
}
101+
96102
/// The direction in which list scrolls
97103
///
98104
/// For example:

0 commit comments

Comments
 (0)