3

I have a Material Design screen where I use a RefreshIndicator for pull-to-refresh effect. However, I need the RefreshIndicator to appear below the SliverAppBar; due to that, I can't just leave the SliverAppBar inside the list's CustomScrollView and I need to give it a header place in a NestedScrollView.

The problem comes because I can't seem to synchronize the general scroll of the list and the header. The list scrolls fine, but the header does not. I want it to float and snap upon scroll up/down.


class Sample extends StatefulWidget {
  @override
  _SampleState createState() => _SampleState();
}

class _SampleState extends State<Sample> {
  final ScrollController _scrollController = new ScrollController();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: NestedScrollView(
        headerSliverBuilder: (context, _) => [
          SliverOverlapAbsorber(
            handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context),
            sliver: SliverAppBar(
              floating: true,
              snap: true,
              title: Text('Title'),
            ),
          )
        ],
        body: Builder(
          builder: (context) => RefreshIndicator(
            onRefresh: () { /* do stuff */ },
            child: CustomScrollView(
              controller: _scrollController, // needed for an infinite scroll items loading effect
              slivers: <Widget>[
                SliverOverlapInjector(
                  handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context)
                )
                // more slivers
              ],
            ),
          )
        ),
      ),
    );
  }
}

I guess I am missing something regarding the injecting/absorbing of the header sliver overlap.

How can I make the SliverAppBar and the general CustomScrollView scroll synchronously?

1 Answer 1

3

This solution worked for my case:

adding floatHeaderSlivers: true to NestedScrollView

https://github.com/flutter/flutter/issues/17518#issuecomment-641629975

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.