Skip to content

Commit 718d7c8

Browse files
committed
feat: add RefreshIndicatorDurations class
1 parent 2894958 commit 718d7c8

File tree

11 files changed

+281
-132
lines changed

11 files changed

+281
-132
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
## 3.0.0
22
- **CustomRefreshIndicator**:
3-
- Deprecated *indicatorFinalizeDuration*, *indicatorSettleDuration*, *indicatorCancelDuration* and *completeStateDuration* parameters in favor of *finalizeDuration*, *settleDuration*, *cancelDuration* and *completeDuration*.
3+
- Deprecated *indicatorFinalizeDuration*, *indicatorSettleDuration*, *indicatorCancelDuration* and *completeStateDuration* parameters in favor of *durations*.
44
- The indicator widget will now be rebuilt every time *state* changes, even if the *autoRebuilt* parameter is set to false. This will make managing the state of the indicator widget simpler.
5+
- Deprecated *IndicatorDelegate* and *MaterialIndicatorDelegate* in favor of *CustomMaterialIndicator* widget.
56
- **IndicatorController**:
67
- The controller now extends *Animation<double>*. This allows it to be used directly with *Transition* widgets to further improve animation performance.
78
- New *ClampedAnimation* class for constraining the *IndicatorController* animation value within a specific range using the *clamp* method.

example/lib/indicators/check_mark_indicator.dart

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,12 @@ class _CheckMarkIndicatorState extends State<CheckMarkIndicator> with SingleTick
4949

5050
@override
5151
Widget build(BuildContext context) {
52-
return CustomRefreshIndicator(
52+
return CustomMaterialIndicator(
53+
withRotation: false,
5354
onRefresh: () => Future.delayed(const Duration(seconds: 2)),
54-
completeDuration: const Duration(seconds: 2),
55+
durations: const RefreshIndicatorDurations(
56+
completeDuration: Duration(seconds: 2),
57+
),
5558
onStateChanged: (change) {
5659
/// set [_renderCompleteState] to true when controller.state become completed
5760
if (change.didChange(to: IndicatorState.complete)) {
@@ -62,37 +65,34 @@ class _CheckMarkIndicatorState extends State<CheckMarkIndicator> with SingleTick
6265
_renderCompleteState = false;
6366
}
6467
},
65-
builder: MaterialIndicatorDelegate(
66-
withRotation: false,
67-
builder: (
68-
BuildContext context,
69-
IndicatorController controller,
70-
) {
71-
final style = _renderCompleteState ? widget.style.completed : widget.style.loading;
72-
return AnimatedContainer(
73-
duration: const Duration(milliseconds: 150),
74-
alignment: Alignment.center,
75-
decoration: BoxDecoration(
76-
color: style.background,
77-
shape: BoxShape.circle,
78-
),
79-
child: _renderCompleteState
80-
? const Icon(
81-
Icons.check,
82-
color: Colors.white,
83-
)
84-
: SizedBox(
85-
height: 24,
86-
width: 24,
87-
child: CircularProgressIndicator(
88-
strokeWidth: 2,
89-
color: style.content,
90-
value: controller.isDragging || controller.isArmed ? controller.value.clamp(0.0, 1.0) : null,
91-
),
68+
indicatorBuilder: (
69+
BuildContext context,
70+
IndicatorController controller,
71+
) {
72+
final style = _renderCompleteState ? widget.style.completed : widget.style.loading;
73+
return AnimatedContainer(
74+
duration: const Duration(milliseconds: 150),
75+
alignment: Alignment.center,
76+
decoration: BoxDecoration(
77+
color: style.background,
78+
shape: BoxShape.circle,
79+
),
80+
child: _renderCompleteState
81+
? const Icon(
82+
Icons.check,
83+
color: Colors.white,
84+
)
85+
: SizedBox(
86+
height: 24,
87+
width: 24,
88+
child: CircularProgressIndicator(
89+
strokeWidth: 2,
90+
color: style.content,
91+
value: controller.isDragging || controller.isArmed ? controller.value.clamp(0.0, 1.0) : null,
9292
),
93-
);
94-
},
95-
).call,
93+
),
94+
);
95+
},
9696
child: widget.child,
9797
);
9898
}

example/lib/screens/horizontal_screen.dart

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,18 @@ class _HorizontalScreenState extends State<HorizontalScreen> {
3131
],
3232
),
3333
body: SafeArea(
34-
child: CustomRefreshIndicator(
34+
child: CustomMaterialIndicator(
3535
leadingScrollIndicatorVisible: false,
3636
trailingScrollIndicatorVisible: false,
3737
triggerMode: IndicatorTriggerMode.anywhere,
3838
trigger: IndicatorTrigger.bothEdges,
39-
builder: MaterialIndicatorDelegate(
40-
builder: (context, controller) {
41-
return const Icon(
42-
Icons.accessibility,
43-
color: Colors.black,
44-
size: 30,
45-
);
46-
},
47-
).call,
39+
indicatorBuilder: (context, controller) {
40+
return const Icon(
41+
Icons.accessibility,
42+
color: Colors.black,
43+
size: 30,
44+
);
45+
},
4846
onRefresh: () => Future.delayed(const Duration(seconds: 2)),
4947
child: ExampleHorizontalList(
5048
itemCount: 4,

example/lib/screens/presentation_screen.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ class _PresentationScreenState extends State<PresentationScreen> {
2020
body: SafeArea(
2121
child: CustomRefreshIndicator(
2222
trigger: IndicatorTrigger.bothEdges,
23-
finalizeDuration: const Duration(seconds: 1),
24-
settleDuration: const Duration(seconds: 1),
25-
cancelDuration: const Duration(seconds: 1),
23+
durations: const RefreshIndicatorDurations(
24+
finalizeDuration: Duration(seconds: 1),
25+
settleDuration: Duration(seconds: 1),
26+
cancelDuration: Duration(seconds: 1),
27+
),
2628
leadingScrollIndicatorVisible: false,
2729
trailingScrollIndicatorVisible: false,
2830
offsetToArmed: 100.0,

lib/src/controller.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class IndicatorController extends Animation<double>
7777
/// Whether the [edge] was determined by the [CustomRefreshIndicator] widget.
7878
bool get hasEdge => edge != null;
7979

80+
@experimental
8081
DragUpdateDetails? get dragDetails => _dragDetails;
8182
DragUpdateDetails? _dragDetails;
8283

0 commit comments

Comments
 (0)