刷新向上滑动刷新 FUTUREBUILDER widget flutter
Refresh swipe up to refresh FUTUREBUILDER widget flutter
我有一个应用程序可以从 firebase 获取一些数据,然后调用 class 来显示基于 firebase 数据的小部件。我尝试添加向上滑动刷新,但我不知道将它放在哪里以及在刷新时调用什么。我正在尝试使用 RefreshIndicator。
在这里我将放置调用数据库 (firebase) 的代码,然后为数据库中的每个事件创建一个小部件。
如果您需要更多信息,请随时发表评论。非常感谢您的帮助!
FutureBuilder(
future: databaseReference.once(),
builder: (context, AsyncSnapshot<DataSnapshot> snapshot) {
List lists = [];
if (snapshot.hasData) {
lists.clear();
Map<dynamic, dynamic> values = snapshot.data.value;
values.forEach((key, values) {
lists.add(values);
});
return new ListView.builder(
primary: false,
padding: EdgeInsets.only(left:12.0,right:12,bottom: 15,),
shrinkWrap: true,
itemCount: lists.length,
itemBuilder: (BuildContext context, int index) {
if(lists[index]["Status"]== "Active"){;
return Container(
child:EvendWidget(lists[index]["EventImage"],
Text(lists[index]["EventName"]).data,
Text(lists[index]["EventLocation"]+ ", "+lists[index]
["EventCounty"] ).data,
Text(lists[index]["Date"]+ ", "+lists[index]["Time"]+
" - "+lists[index]["Time"]).data,
Text(lists[index]["Duration"]+ " H").data,
Text(lists[index]["Genre"]).data,
Text(lists[index]["Price"]).data,false));}else{return
SizedBox.shrink(); };
});
}
return Container(
margin: const EdgeInsets.only(top: 300),
child:CircularProgressIndicator());
}),
如果您需要更多信息,请随时发表评论。非常感谢您的帮助!
您可以像这样使用 RefreshIndicator:
Future<void> _onRefresh() async {
databaseReference.once();
return 'success';
}
return RefreshIndicator(
onRefresh: _onRefresh,
child: ListView.builder(
itemBuilder: (BuildContext context, int index) {
--your code here--
}
如果您需要了解任何其他信息,请告诉我。
我有一个应用程序可以从 firebase 获取一些数据,然后调用 class 来显示基于 firebase 数据的小部件。我尝试添加向上滑动刷新,但我不知道将它放在哪里以及在刷新时调用什么。我正在尝试使用 RefreshIndicator。
在这里我将放置调用数据库 (firebase) 的代码,然后为数据库中的每个事件创建一个小部件。
如果您需要更多信息,请随时发表评论。非常感谢您的帮助!
FutureBuilder(
future: databaseReference.once(),
builder: (context, AsyncSnapshot<DataSnapshot> snapshot) {
List lists = [];
if (snapshot.hasData) {
lists.clear();
Map<dynamic, dynamic> values = snapshot.data.value;
values.forEach((key, values) {
lists.add(values);
});
return new ListView.builder(
primary: false,
padding: EdgeInsets.only(left:12.0,right:12,bottom: 15,),
shrinkWrap: true,
itemCount: lists.length,
itemBuilder: (BuildContext context, int index) {
if(lists[index]["Status"]== "Active"){;
return Container(
child:EvendWidget(lists[index]["EventImage"],
Text(lists[index]["EventName"]).data,
Text(lists[index]["EventLocation"]+ ", "+lists[index]
["EventCounty"] ).data,
Text(lists[index]["Date"]+ ", "+lists[index]["Time"]+
" - "+lists[index]["Time"]).data,
Text(lists[index]["Duration"]+ " H").data,
Text(lists[index]["Genre"]).data,
Text(lists[index]["Price"]).data,false));}else{return
SizedBox.shrink(); };
});
}
return Container(
margin: const EdgeInsets.only(top: 300),
child:CircularProgressIndicator());
}),
如果您需要更多信息,请随时发表评论。非常感谢您的帮助!
您可以像这样使用 RefreshIndicator:
Future<void> _onRefresh() async {
databaseReference.once();
return 'success';
}
return RefreshIndicator(
onRefresh: _onRefresh,
child: ListView.builder(
itemBuilder: (BuildContext context, int index) {
--your code here--
}
如果您需要了解任何其他信息,请告诉我。