颤抖如何在数据更改的情况下更新Listview.builder

问题描述

我正在使用Flutter中的 ListView.builder 。现在一切正常,在回调方法中有以下几行代码

@override
void initState(){
  items = new List();
  for(int index = 0; index < dataList.length; index++){
    items.add(...creating widget ..);
  }
}

 @override
  Widget build(BuildContext context) {
    return Container(
    child: ListView.builder(
        scrollDirection: Axis.vertical,shrinkWrap: true,itemCount: dataList.length,itemBuilder: (BuildContext context,int index) {
          return Container(
            width: width,height: 160,key: UniqueKey(),padding: EdgeInsets.all(10),child: items[index],);
        },),);
  }

问题是 dataList 的数据更新时,如果数据值已更新,已删除,我应该如何实现此列表以使列表更新 UI 或地点已更改。 StreamBuilder是解决方案吗?

解决方法

如果它在不断变化,请使用rope

例如:https://bendyworks.com/blog/a-month-of-flutter-rendering-a-list-view-with-stream-builder

否则,您可以使用StreamBuilder

例如:https://medium.com/nonstopio/flutter-future-builder-with-list-view-builder-d7212314e8c9

OR

如果dataList在应用程序内部更改(删除/更新),则调用FutureBuilder,这将更新setState()

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...