nested_scroll_controller 0.0.2 copy "nested_scroll_controller: ^0.0.2" to clipboard
nested_scroll_controller: ^0.0.2 copied to clipboard

outdated

A ScrollController specifically for controlling a NestedScrollView.

nested_scroll_controller #

Pub Version

A widget used in conjunction with a basic ScrollController to allow for controlling a NestedScrollView like it was a regular scroll view.
This is a small, single-file library which empowers you in every way (and more!) that a standard scroll controller would on a scroll view:

  • animate to an offset or an index
  • jump to an offset or an index
  • add listeners to the total offset
  • TODO: utilize NestedScrollPositions with NestedScrollController as you would ScrollPositions with ScrollController!

Usage #

See example.
To utilize [NestedScrollController] there are four main steps:

    /// In build method...
    ScrollController outerScrollController = ScrollController();
    NestedScrollController nestedScrollController;

    return ... /// [Scaffold] and [DefaultTabController] here.
         NestedScrollView(
          /// 1. Use the [controller] field with a custom [ScrollController].
          controller: outerScrollController,
          headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) { ... },

          /// 2. Wrap the body in a [Builder] to provide the [NestedScrollView.body]
          /// [BuildContext].
          body: Builder(
            builder: (context) {
              /// 3. Create the [NestedScrollController] here!
              ///
              /// In this example, I noticed that the center** was originally around
              /// the 2nd index, hence the 3rd parameter.
              ///
              /// ** See [NestedScrollController.centerCorrectionOffset] for more information
              /// on this term.
              nestedScrollController = NestedScrollController(
                bodyContext: context,
                outerController: outerScrollController,
                centerCorrectionOffset: itemExtent * 4,
              );
              return ... /// [TabBarView] with [CustomScrollView] here.
                    SliverPadding(
                        padding: const EdgeInsets.all(8.0),
                        sliver: SliverFixedExtentList(
                        itemExtent: itemExtent,
                        delegate: SliverChildBuilderDelegate(
                            (BuildContext context, int index) {
                            return ListTile(
                                title: Text('Item $index'),
                                onTap: () {
                                /// 4. Use the [NestedScrollController]!
                                nestedScrollController.animateToIndex(
                                    index,
                                    itemExtent: itemExtent,
                                );
                                      ...
10
likes
0
points
84
downloads

Publisher

unverified uploader

Weekly Downloads

A ScrollController specifically for controlling a NestedScrollView.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on nested_scroll_controller