injectScrolling static method
InjectedScrolling
injectScrolling({})
Inject a ScrollController
This injected state abstracts the best practices to come out with a simple, clean, and testable approach to control Scrollable view.
If you don't use OnScrollBuilder to listen to the state, it is highly recommended to manually dispose the state using Injected.dispose method.
Parameters:
initialScrollOffset
: Optional double. Defaults to 0.0.
is the initial scroll offset
endScrollDelay
: Optional int. Defaults to 300.
The delay in milliseconds to be awaited after the user stop scrolling to consider scrolling action ended.
onScrolling
: Optional callback.
Callback invoked each time the ScrollController emits a notification. It exposes the InjectedScrolling instance. It is used to invoke side effects when:
- Reaching the maximum scroll extent InjectedScrolling.maxScrollExtent
- Reaching the minimum scroll extent InjectedScrolling.minScrollExtent
- While is scrolling in the forward direction
- While is scrolling InjectedScrolling.isScrolling InjectedScrolling.isScrollingForward
- When starts scrolling InjectedScrolling.isScrollingReverse
- When starts scrolling to the forward direction InjectedScrolling.hasStartedScrolling InjectedScrolling.hasStartedScrollingForward
- When starts scrolling to the reverse direction InjectedScrolling.hasStartedScrollingReverse
- When scrolling ends InjectedScrolling.hasEndedScrolling
Example
final scroll = RM.injectScrolling(
onScrolling: (scroll) {
if (scroll.hasReachedMinExtent) {
print('isTop');
}
if (scroll.hasReachedMaxExtent) {
print('isBottom');
}
if (scroll.hasStartedScrollingReverse) {
print('hasStartedUp');
}
if (scroll.hasStartedScrollingForward) {
print('hasStartedDown');
}
if (scroll.hasStartedScrolling) {
print('hasStarted');
}
if (scroll.isScrollingReverse) {
print('isScrollingUp');
}
if (scroll.isScrollingForward) {
print('isScrollingDown');
}
if (scroll.isScrolling) {
print('isScrolling');
}
if (scroll.hasEndedScrolling) {
print('hasEnded');
}
},
);
keepScrollOffset
: Optional bool. Defaults to true.
Similar to ScrollController.keepScrollOffset
See OnScrollBuilder
Implementation
static InjectedScrolling injectScrolling({
double initialScrollOffset = 0.0,
bool keepScrollOffset = true,
void Function(InjectedScrolling)? onScrolling,
int endScrollDelay = 300,
}) {
return InjectedScrollingImp(
initialScrollOffset: initialScrollOffset,
keepScrollOffset: keepScrollOffset,
onScroll: onScrolling != null ? OnScroll<void>(onScrolling) : null,
onScrollEndedDelay: endScrollDelay,
);
}