Skip to content

Commit 106028e

Browse files
committed
feat: make IndicatorController extends Animation<double>
1 parent 0bea256 commit 106028e

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
## 2.3.0
2-
- The drag details have been exposed to allow animations based on the position of the pointer.
2+
- The controller now extends the *Animation<double>*.
3+
- New *ClampedAnimation* class for constraining the *IndicatorController* animation value within a specific range using the *clamp* method.
4+
- Drag interaction details are now available, enabling pointer-position-based animations.
35
- Example app:
46
- The checkmark indicator example has been simplified.
57
- Minor corrections to the envelope indicator.

lib/src/controller.dart

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
part of 'custom_refresh_indicator.dart';
22

3-
class IndicatorController extends ChangeNotifier {
3+
class IndicatorController extends Animation<double>
4+
with AnimationEagerListenerMixin, AnimationLocalListenersMixin, AnimationLocalStatusListenersMixin {
45
double _value;
56

67
/// Current indicator value / progress
8+
@override
79
double get value => _value;
810

911
/// Creates [CustomRefreshIndicator] controller class
@@ -121,14 +123,12 @@ class IndicatorController extends ChangeNotifier {
121123
/// Whether list scrolls horrizontally
122124
///
123125
/// (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;
126127

127128
/// Whether list scrolls vertically
128129
///
129130
/// (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;
132132

133133
IndicatorState _currentState;
134134

@@ -199,4 +199,23 @@ class IndicatorController extends ChangeNotifier {
199199
_isRefreshEnabled = true;
200200
notifyListeners();
201201
}
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+
);
202221
}

0 commit comments

Comments
 (0)