Skip to content

Commit ac97c84

Browse files
committed
feat: add transform and normalize methods
1 parent 5c99f0c commit ac97c84

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

lib/custom_refresh_indicator.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
export 'src/data/data.dart';
22
export 'src/custom_refresh_indicator.dart';
3-
export 'src/delegates/delegates.dart';
43
export 'src/widgets/widgets.dart';
54
export 'src/physics/physics.dart';
65
export 'src/utils/utils.dart';

lib/src/custom_refresh_indicator.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import 'package:flutter/material.dart';
44
import 'package:flutter/rendering.dart';
55
import 'package:meta/meta.dart';
66

7-
part 'controller.dart';
7+
part 'indicator_controller.dart';
88

99
typedef IndicatorBuilder = Widget Function(
1010
BuildContext context,

lib/src/controller.dart renamed to lib/src/indicator_controller.dart

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ class IndicatorController extends Animation<double>
88
ClampingWithOverscrollPhysicsState {
99
double _value;
1010

11+
/// Represents the **minimum** value that an indicator can have.
12+
static double get minValue => 0.0;
13+
14+
/// Represents the **maximum** value that an indicator can have.
15+
static double get maxValue => 1.5;
16+
1117
/// Current indicator value / progress
1218
@override
1319
double get value => _value;
@@ -211,7 +217,7 @@ class IndicatorController extends Animation<double>
211217
@override
212218
AnimationStatus get status => state.isIdle ? AnimationStatus.dismissed : AnimationStatus.forward;
213219

214-
/// Returns a [ClampedAnimation] that constrains the animation value of its parent
220+
/// Returns [ClampedAnimation] that constrains the animation value of its parent
215221
/// within the given [min] and [max] range.
216222
///
217223
/// - [min] represents the smallest value the animation can have. If the parent
@@ -223,4 +229,22 @@ class IndicatorController extends Animation<double>
223229
min: min,
224230
max: max,
225231
);
232+
233+
/// Returns [TransformedAnimation], which transforms the animation value of its parent
234+
/// to the specified [min] and [max] range.
235+
///
236+
/// - [min] represents the smallest value the animation can have.
237+
/// - [max] represents the largest value the animation can have.
238+
///
239+
/// If instead of transforming the entire range of controller values, you want to use only a specific range, see the [clamp] method.
240+
Animation<double> transform(double min, double max) => TransformedAnimation(
241+
parent: this,
242+
fromMin: minValue,
243+
fromMax: maxValue,
244+
toMin: min,
245+
toMax: max,
246+
);
247+
248+
/// Returns a new animation with the controller value transformed to the range from `0.0` to `1.0` inclusive.
249+
Animation<double> normalize() => transform(0.0, 1.0);
226250
}

0 commit comments

Comments
 (0)