flutter

How to use RefreshIndicator without Scroll widget?


I'm trying to use RefreshIndicator but without using a scrolling widget, I can't use it. My goal is here is to just to show a Text widget and add pull to refresh functionality.

 if (snapshot.data.isEmpty) {
            return RefreshIndicator(
              onRefresh: () async {
                _init();
              },
              child: Center(
                child: Text('No data'),
              ),
            );
          }

I've wrapped my Text('No data') widget in a SingleChildScrollView but it didn't work. My solution is now below but it looks ugly. Is there a better way to do it?

  if (snapshot.data.isEmpty) {
            return RefreshIndicator(
              onRefresh: () async {
                _init();
                print('we scrolled');
              },
              child: Center(
                child: ListView.builder(
                  itemCount: 1,
                  itemBuilder: (context, index) {
                    return Text('No data\nPull to Refresh');
                  },
                ),
              ),
            );
          }

enter image description here


Solution

  • set physics to always scrollable

    ListView.builder(
                  physics:AlwaysScrollableScrollPhysics(),
                  itemCount: 1,
                  itemBuilder: (context, index) {
                    return Text('No data\nPull to Refresh');
                  },
                )