Skip to content

Commit 733f002

Browse files
committed
Add reversed support
1 parent 6a3f855 commit 733f002

File tree

2 files changed

+31
-11
lines changed

2 files changed

+31
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
- Initial support for programmatically-controlled indicators has been added. Added the `show`,` hide` and `refresh` methods to the` CustomRefreshIndicatorState` class. It can be accessed via GlobalKey. Take a look at an [programmatically-controlled screen example](/example/lib/screens/programmatically_controlled_indicator_screen.dart).
1515
- Use the `flutter_lints` package for analysis.
1616
- Deprecate `leadingGlowVisible` and `trailingGlowVisible` in favor of `leadingScrollIndicatorVisible` and `trailingScrollIndicatorVisible` arguments.
17+
- Added `reversed` argument that allows you to trigger a refresh indicator from the end of the list.
1718

1819
## 1.0.0
1920

lib/src/custom_refresh_indicator.dart

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,14 @@ class CustomRefreshIndicator extends StatefulWidget {
5555
/// to calculate [IndicatorController] data.
5656
final Widget child;
5757

58+
/// Allows you to trigger the indicator from the other side
59+
/// of the scrollview (from the end of the list).
60+
final bool reversed;
61+
5862
/// Function in wich custom refresh indicator should be implemented.
5963
///
60-
/// IMPORTANT:
61-
/// IT IS NOT CALLED ON EVERY [IndicatorController] DATA CHANGE.
62-
///
63-
/// TIP:
64+
/// ### IMPORTANT:
65+
/// IT IS NOT CALLED ON EVERY [IndicatorController] DATA CHANGE.
6466
/// To rebuild widget on every [IndicatorController] data change, consider
6567
/// using [IndicatorController] that is passed to this function as the third argument
6668
/// in combination with [AnimationBuilder].
@@ -89,6 +91,7 @@ class CustomRefreshIndicator extends StatefulWidget {
8991
required this.child,
9092
required this.onRefresh,
9193
required this.builder,
94+
this.reversed = false,
9295
this.notificationPredicate = defaultScrollNotificationPredicate,
9396
this.controller,
9497
this.offsetToArmed,
@@ -196,8 +199,10 @@ class CustomRefreshIndicatorState extends State<CustomRefreshIndicator>
196199
}
197200

198201
bool _handleScrollStartNotification(ScrollStartNotification notification) {
199-
_canStart = notification.metrics.extentBefore == 0 &&
200-
controller.state == IndicatorState.idle;
202+
_canStart = controller.state == IndicatorState.idle &&
203+
(widget.reversed
204+
? notification.metrics.extentAfter == 0
205+
: notification.metrics.extentBefore == 0);
201206

202207
if (_canStart) setIndicatorState(IndicatorState.dragging);
203208

@@ -209,22 +214,36 @@ class CustomRefreshIndicatorState extends State<CustomRefreshIndicator>
209214
/// hide when list starts to scroll
210215
if (controller.state == IndicatorState.dragging ||
211216
controller.state == IndicatorState.armed) {
212-
if (notification.metrics.extentBefore > 0.0) {
213-
_hide();
217+
if (widget.reversed) {
218+
if (notification.metrics.extentAfter > 0.0) {
219+
_hide();
220+
} else {
221+
_dragOffset += notification.scrollDelta!;
222+
_calculateDragOffset(notification.metrics.viewportDimension);
223+
}
214224
} else {
215-
_dragOffset -= notification.scrollDelta!;
216-
_calculateDragOffset(notification.metrics.viewportDimension);
225+
if (notification.metrics.extentBefore > 0.0) {
226+
_hide();
227+
} else {
228+
_dragOffset -= notification.scrollDelta!;
229+
_calculateDragOffset(notification.metrics.viewportDimension);
230+
}
217231
}
218232
if (controller.state == IndicatorState.armed &&
219233
notification.dragDetails == null) {
220234
_start();
221235
}
222236
}
237+
223238
return false;
224239
}
225240

226241
bool _handleOverscrollNotification(OverscrollNotification notification) {
227-
_dragOffset -= notification.overscroll;
242+
if (widget.reversed) {
243+
_dragOffset += notification.overscroll;
244+
} else {
245+
_dragOffset -= notification.overscroll;
246+
}
228247
_calculateDragOffset(notification.metrics.viewportDimension);
229248
return false;
230249
}

0 commit comments

Comments
 (0)