Flutter 刷新刷起以刷新FUTUREBUILDER小部件颤振
我有一个应用程序,它从firebase获取一些数据,然后调用一个类来显示基于firebase数据的小部件。我尝试添加一个刷起刷新,但我不知道放在哪里,以及刷新时调用什么。我用刷新指示器试了一下 在这里,我将输入调用数据库(firebase)的代码,然后为数据库中的每个事件创建一个小部件 如果您需要更多信息,请随时发表评论。非常感谢你的帮助Flutter 刷新刷起以刷新FUTUREBUILDER小部件颤振,flutter,flutter-animation,Flutter,Flutter Animation,我有一个应用程序,它从firebase获取一些数据,然后调用一个类来显示基于firebase数据的小部件。我尝试添加一个刷起刷新,但我不知道放在哪里,以及刷新时调用什么。我用刷新指示器试了一下 在这里,我将输入调用数据库(firebase)的代码,然后为数据库中的每个事件创建一个小部件 如果您需要更多信息,请随时发表评论。非常感谢你的帮助 FutureBuilder( future: databaseReference.once(), builder: (context,
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());
}),
FutureBuilder(
future:databaseReference.once(),
生成器:(上下文,异步快照){
列表=[];
if(snapshot.hasData){
lists.clear();
映射值=snapshot.data.value;
values.forEach((键,值){
列表。添加(值);
});
返回新的ListView.builder(
主要:错误,
填充:边设置。仅限(左:12.0,右:12,下:15,),
收缩膜:对,
itemCount:lists.length,
itemBuilder:(构建上下文,int索引){
如果(列出[索引][“状态”]=“活动”){;
返回容器(
子项:EvendWidget(列出[索引][“EventImage”],
文本(列出[索引][“事件名称])。数据,
文本(列出[索引][“EventLocation”]+,“+列出[索引]
[“EventCounty”])。数据,
文本(列出[索引][“日期”]+,“+列出[索引][“时间”]+
“-”+列出[索引][“时间”])。数据,
文本(列出[索引][“持续时间”]+“H”)。数据,
文本(列出[索引][“类型])。数据,
Text(列出[索引][“价格])。数据,false));}else{return
SizedBox.shrink();};
});
}
返回容器(
边距:仅限常量边集(顶部:300),
child:CircularProgressIndicator());
}),
如果您需要更多信息,请随时发表评论。非常感谢你的帮助 您可以像这样使用RefreshIndicator:
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());
}),
Future<void> _onRefresh() async {
databaseReference.once();
return 'success';
}
return RefreshIndicator(
onRefresh: _onRefresh,
child: ListView.builder(
itemBuilder: (BuildContext context, int index) {
--your code here--
}
Future\u onRefresh()异步{
databaseReference.once();
回归"成功",;
}
返回刷新指示器(
onRefresh:\u onRefresh,
子项:ListView.builder(
itemBuilder:(构建上下文,int索引){
--你的代码在这里--
}
如果您还需要了解其他信息,请告诉我。如果您想“刷新”您的数据多次使用
StreamBuilder
,而不是FutureBuilder
StreamBuilder和FutureBuilder之间的区别是什么?请检查此示例:因此,我必须在内部添加整个FutureBuilder?是的。只需将ListView.builder包装在RefreshIndicator中并调用_onRefresh函数。我将其包装在内部,并注意hap笔当我向上滑动时,我的代码现在看起来像这样:你需要拉动刷新,对吗?像这样?