Skip to content

Commit 8cdaa3a

Browse files
author
Kamil Klyta
committed
Match the required extent to armed with the built-in indicator
1 parent 0638f80 commit 8cdaa3a

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
## 2.0.0-dev.2
2+
## Breaking changes
3+
- Renamed `extentPercentageToArmed` argument to `containerExtentPercentageToArmed` which better describes what it exactly means.
4+
- Changed the default value of the `defaultContainerExtentPercentageToArmed` from `0.20` to `0.1(6)` to match the behavior of the built-in indicator widget.
25
- Removed deprecated **IndicatorStateHelper** class. Instead use **CustomRefreshIndicator.onStateChanged** method.
36
- Removed deprecated **leadingGlowVisible** and **trailingGlowVisible** arguments. Instead use **leadingScrollIndicatorVisible** and **trailingScrollIndicatorVisible** accoringly.
47
- The default value of the **trailingScrollIndicatorVisible** for the **EnvelopRefreshIndicator** has been changed from **true** to **false**.

lib/src/custom_refresh_indicator.dart

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,14 @@ extension on IndicatorTrigger {
3030
}
3131

3232
class CustomRefreshIndicator extends StatefulWidget {
33+
/// The value from which [IndicatorController] is considered to be armed.
3334
static const armedFromValue = 1.0;
34-
static const defaultExtentPercentageToArmed = 0.20;
35+
36+
/// The default distance the user must over-scroll for the indicator
37+
/// to be armed, as a percentage of the scrollable's container extent.
38+
///
39+
/// This value matches the extent to armed of built-in [RefreshIndicator] widget.
40+
static const defaultContainerExtentPercentageToArmed = 0.25 * (1 / 1.5);
3541

3642
/// Duration of changing [IndicatorController] value from `<1.0` to `0.0`.
3743
/// When user stop dragging list before it become to armed [IndicatorState].
@@ -66,9 +72,14 @@ class CustomRefreshIndicator extends StatefulWidget {
6672
/// Number of pixels that user should drag to change [IndicatorState] from idle to armed.
6773
final double? offsetToArmed;
6874

69-
/// Value from 0.0 to 1.0 that describes the percentage of scroll container extent
70-
/// that user should drag to change [IndicatorState] from idle to armed.
71-
final double? extentPercentageToArmed;
75+
/// The distance the user must scroll for the indicator to be armed,
76+
/// as a percentage of the scrollable's container extent.
77+
///
78+
/// If the [offsetToArmed] argument is specified, it will be used instead,
79+
/// and this value will not take effect.
80+
///
81+
/// The default value equals `0.1(6)`.
82+
final double containerExtentPercentageToArmed;
7283

7384
/// Part of widget tree that contains scrollable element (like ListView).
7485
/// Scroll notifications from the first scrollable element will be used
@@ -131,18 +142,21 @@ class CustomRefreshIndicator extends StatefulWidget {
131142
this.controller,
132143
this.offsetToArmed,
133144
this.onStateChanged,
134-
this.extentPercentageToArmed,
145+
double? containerExtentPercentageToArmed,
135146
this.draggingToIdleDuration = const Duration(milliseconds: 300),
136147
this.armedToLoadingDuration = const Duration(milliseconds: 200),
137148
this.loadingToIdleDuration = const Duration(milliseconds: 100),
138149
this.completeStateDuration,
139150
this.leadingScrollIndicatorVisible = false,
140151
this.trailingScrollIndicatorVisible = true,
141152
}) : assert(
142-
extentPercentageToArmed == null || offsetToArmed == null,
153+
containerExtentPercentageToArmed == null || offsetToArmed == null,
143154
'Providing `extentPercentageToArmed` argument take no effect when `offsetToArmed` is provided. '
144155
'Remove redundant argument.',
145156
),
157+
// set the default extent percentage value if not provided
158+
containerExtentPercentageToArmed = containerExtentPercentageToArmed ??
159+
defaultContainerExtentPercentageToArmed,
146160
super(key: key);
147161

148162
@override
@@ -408,8 +422,7 @@ class CustomRefreshIndicatorState extends State<CustomRefreshIndicator>
408422
if (offsetToArmed != null) {
409423
newValue = _dragOffset / offsetToArmed;
410424
} else {
411-
final extentPercentageToArmed = widget.extentPercentageToArmed ??
412-
CustomRefreshIndicator.defaultExtentPercentageToArmed;
425+
final extentPercentageToArmed = widget.containerExtentPercentageToArmed;
413426

414427
newValue = _dragOffset / (containerExtent * extentPercentageToArmed);
415428
}

0 commit comments

Comments
 (0)