Flutter 如何在没有滚动小部件的情况下使用RefreshIndicator?
我正在尝试使用RefreshIndicator,但如果不使用滚动小部件,我就无法使用它。我的目标是显示一个文本小部件并添加pull-to-refresh功能Flutter 如何在没有滚动小部件的情况下使用RefreshIndicator?,flutter,Flutter,我正在尝试使用RefreshIndicator,但如果不使用滚动小部件,我就无法使用它。我的目标是显示一个文本小部件并添加pull-to-refresh功能 if (snapshot.data.isEmpty) { return RefreshIndicator( onRefresh: () async { _init(); }, child: Cente
if (snapshot.data.isEmpty) {
return RefreshIndicator(
onRefresh: () async {
_init();
},
child: Center(
child: Text('No data'),
),
);
}
我已将文本“无数据”小部件包装在SingleChildScrollView中,但它不起作用。我的解决方案现在在下面,但看起来很难看。有更好的方法吗
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');
},
),
),
);
}
将物理设置为始终可滚动
ListView.builder(
physics:AlwaysScrollableScrollPhysics(),
itemCount: 1,
itemBuilder: (context, index) {
return Text('No data\nPull to Refresh');
},
)