Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter: How to use RefreshIndicator with SliverAppBar

I'm trying to add RefreshIndicator to CustomScrollView. Is it possible to do? Here is the code sample:

CustomScrollView(
  slivers: <Widget>[
    SliverAppBar(
      title: Text('POSTAPP'),
      centerTitle: true,
      floating: true,
      pinned: false,
    ),
    SliverList(
        delegate: SliverChildBuilderDelegate(
          _createPostItem,
          childCount: postRepo.posts.length,
      ),
    ),
  ],
);
like image 645
Robert Apikyan Avatar asked Sep 26 '18 11:09

Robert Apikyan


People also ask

How do I use RefreshIndicator in flutter?

RefreshIndicator is a widget in Flutter that supports Material's swipe-to-refresh. It works by showing a circular progress indicator when the child's Scrollable is overscrolled. If the user ends the scroll and the indicator has been dragged far enough, it will call onRefresh . You can define your own callback function.

How do you use custom scroll view in flutter?

Now lets start implementation of CustomScrollView in Flutter First of all, create a basic project and return a Custom Scroll View widget. Then, add a silver app bar and then add a silver grid. Here we only used two child widgets in the custom scroll view. The Entry point of code.

What is SliverPadding in flutter?

Slivers are special-purpose widgets that can be combined using a CustomScrollView to create custom scroll effects. A SliverPadding is a basic sliver that insets another sliver by applying padding on each side.


1 Answers

Only like this:

RefreshIndicator(child: CustomScrollView(
        slivers: <Widget>[
          SliverAppBar(
            title: Text('POSTAPP'),
            centerTitle: true,
            floating: true,
            pinned: false,
          ),
          SliverList(
              delegate: SliverChildBuilderDelegate(_createPostItem,
                  childCount: postRepo.posts.length))
        ],
      ), onRefresh: () => Future.value(true));

SliverList isn't scrollable, so you can't wrap it in RefreshIndicator

like image 112
Andrey Turkovsky Avatar answered Oct 13 '22 21:10

Andrey Turkovsky