flutter - 刷新向上滑动以刷新小部件颤动
问题描述
我有一个应用程序,它从 firebase 获取一些数据,然后调用一个类来显示基于 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());
}),
解决方案
做这样的事情..
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: RefreshIndicator(
onRefresh: () async {
//write your code here to update the list*********
},
child: ListView.builder(
itemCount: 100,
itemBuilder: (BuildContext context, int index) {
return Text('Line $index');
}
)
),
);
}
}
推荐阅读
- ld - 当ld找不到符号_start时,它默认是什么?
- java - Spring Batch 在 Spring Boot 中完成 Job 后发送响应
- mongodb - 在 mongodb 的 $lookup 中应用条件
- python-3.x - 如何摆脱 Ipython Pandas 中的斜体并获取纯文本?
- websphere - IBM Websphere - 您可以提取应用程序属性文件吗?
- image - 捕获 wxFrame 内容并保存到文件
- java - Exception 类是已检查还是未检查的异常?
- microsoft-graph-api - 枚举日历事件时出现“重复格式无效”错误
- regex - 为什么 ex (vim) 将匹配模式捕获到行尾
- flexbox - Bootstrap 4 和断点