首页 > 解决方案 > 刷新向上滑动以刷新小部件颤动

问题描述

我有一个应用程序,它从 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());
    }),

标签: flutterflutter-animation

解决方案


做这样的事情..

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');
          }
        )
      ),
    );
  }
}

推荐阅读