Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Refresh indicator without scrollview

Tags:

flutter

I know with a ListView or SingleChildScrollView RefreshIndicator just works natively but I want to use a RefreshIndicator on a page that doesn't scroll. Is this even possible and if so, how?

like image 203
Trent Piercy Avatar asked May 06 '18 00:05

Trent Piercy


People also ask

How do I disable RefreshIndicator in flutter?

To disable RefreshIndicator pass notificationPredicate function that returns false. After doing that refresh indicator won't be shown or onRefresh called.

What is flutter physics?

Physics simulation in Flutter is a beautiful way to Animate components of the flutter app to make it look more realistic and interactive. These can be used to create a range of animations like falling objects due to gravity to making a container seem attached to a spring.


1 Answers

You must do the following:

  • Use a SingleChildScrollView with the property physics set to AlwaysScrollableScrollPhysics().
  • Make sure it's child has a height of the size of the screen, which you can get with MediaQuery.of(context).size.height.

The complete example:

classs MyWidget extends StatelessWidget {   @override   Widget build(BuildContext context) {     return RefreshIndicator(       onRefresh: () {},       child: SingleChildScrollView(         physics: AlwaysScrollableScrollPhysics(),         child: Container(           child: Center(             child: Text('Hello World'),           ),           height: MediaQuery.of(context).size.height,         ),       ),     );   } } 
like image 85
Gustavo Avatar answered Sep 19 '22 13:09

Gustavo