Agung
Agung

Reputation: 13803

Can I show refresh Indicator even though I can't scroll the list view?

In a page, my listView can be scrolled if I have at least 7 items or more. if there are only 3 items in my list then listView can not be scrolled.

I need to show Refresh Indicator (that circular indicator at the top of list) in my list even though I have less than 7 items (list can not be scrolled). How to do that?

Here is my code:

return RefreshIndicator(
      onRefresh: () {},
      child: ListView.builder(
        physics: ClampingScrollPhysics(),
        itemCount: controller.items.length + 1,
        itemBuilder: (context, index) {
        },
      }
)

Upvotes: 1

Views: 1380

Answers (3)

Jahidul Islam
Jahidul Islam

Reputation: 12565

As well as you can wrap your Listview, you can change this behavior so that the ListView only occupies the space it needs

return RefreshIndicator(
      onRefresh: () {},
      child: ListView.builder(
        shrinkWrap: true,
        physics: ScrollPhysics(),
        itemCount: controller.items.length + 1,
        itemBuilder: (context, index) {

        },

       }
   )

Upvotes: -1

stacktrace2234
stacktrace2234

Reputation: 1500

You can do this if you don't wanna lose your clamping physics:

physics: ClampingScrollPhysics(parent: AlwaysScrollableScrollPhysics()),

Upvotes: 6

Ehsan Askari
Ehsan Askari

Reputation: 891

set the physics of the listView to AlwaysScrollableScrollPhysics()

return RefreshIndicator(
      onRefresh: () {},
      child: ListView.builder(
        physics: AlwaysScrollableScrollPhysics(),
        itemCount: controller.items.length + 1,
        itemBuilder: (context, index) {

        },

       }
   )

Upvotes: 3

Related Questions