|
1 | 1 | part of 'custom_refresh_indicator.dart'; |
2 | 2 |
|
3 | | -class IndicatorController extends ChangeNotifier { |
| 3 | +class IndicatorController extends Animation<double> |
| 4 | + with AnimationEagerListenerMixin, AnimationLocalListenersMixin, AnimationLocalStatusListenersMixin { |
4 | 5 | double _value; |
5 | 6 |
|
6 | 7 | /// Current indicator value / progress |
| 8 | + @override |
7 | 9 | double get value => _value; |
8 | 10 |
|
9 | 11 | /// Creates [CustomRefreshIndicator] controller class |
@@ -121,14 +123,12 @@ class IndicatorController extends ChangeNotifier { |
121 | 123 | /// Whether list scrolls horrizontally |
122 | 124 | /// |
123 | 125 | /// (direction equals `AxisDirection.left` or `AxisDirection.right`) |
124 | | - bool get isHorizontalDirection => |
125 | | - direction == AxisDirection.left || direction == AxisDirection.right; |
| 126 | + bool get isHorizontalDirection => direction == AxisDirection.left || direction == AxisDirection.right; |
126 | 127 |
|
127 | 128 | /// Whether list scrolls vertically |
128 | 129 | /// |
129 | 130 | /// (direction equals `AxisDirection.up` or `AxisDirection.down`) |
130 | | - bool get isVerticalDirection => |
131 | | - direction == AxisDirection.up || direction == AxisDirection.down; |
| 131 | + bool get isVerticalDirection => direction == AxisDirection.up || direction == AxisDirection.down; |
132 | 132 |
|
133 | 133 | IndicatorState _currentState; |
134 | 134 |
|
@@ -199,4 +199,23 @@ class IndicatorController extends ChangeNotifier { |
199 | 199 | _isRefreshEnabled = true; |
200 | 200 | notifyListeners(); |
201 | 201 | } |
| 202 | + |
| 203 | + /// Provides the status of the animation: [AnimationStatus.dismissed] when |
| 204 | + /// the indicator [state] is [IndicatorState.idle], |
| 205 | + /// and [AnimationStatus.forward] otherwise. |
| 206 | + @override |
| 207 | + AnimationStatus get status => state.isIdle ? AnimationStatus.dismissed : AnimationStatus.forward; |
| 208 | + |
| 209 | + /// Returns a [ClampedAnimation] that constrains the animation value of its parent |
| 210 | + /// within the given [min] and [max] range. |
| 211 | + /// |
| 212 | + /// - [min] represents the smallest value the animation can have. If the parent |
| 213 | + /// animation's value falls below this, it will be clamped to this minimum value. |
| 214 | + /// - [max] represents the largest value the animation can have. If the parent |
| 215 | + /// animation's value exceeds this, it will be clamped to this maximum value. |
| 216 | + Animation<double> clamp(double min, double max) => ClampedAnimation( |
| 217 | + parent: this, |
| 218 | + min: min, |
| 219 | + max: max, |
| 220 | + ); |
202 | 221 | } |
0 commit comments