injectScrolling static method

InjectedScrolling injectScrolling({
  1. double initialScrollOffset = 0.0,
  2. bool keepScrollOffset = true,
  3. void onScrolling(
    1. InjectedScrolling
    )?,
  4. int endScrollDelay = 300,
})

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:

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,
  );
}