flutterdartasync-awaitpull-to-refresh

RefreshIndicator Flutter


Does the RefreshIndicator only work with Scrollable or ListView-related widgets? I wish to use it with a Container inside a Scaffoled and use a GestureRecognizer whereby upon pulling down it refreshes.

I tried to use RefreshIndicator in my code enclosing a Container but it didn't work.


Solution

  • Add SingleChildScrollView in between works fine for me.

    class 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,
                ),
              ),
            );
          }
    
    }