【发布时间】:2021-06-28 11:07:34
【问题描述】:
我有一个小部件列表,我想删除最后一项,但是当我执行下面的 5 行时没有任何反应。
if (mounted) {
setState(() {
verlustContentList.removeLast();
});
}
这就是我生成列表的方式:
generateList() async {
return verlustContentList = List.generate(
15,
(index) => VerlustContent(
key: Key(
index.toString(),
),
),
);
}
这就是我显示列表的方式:
StreamBuilder(
stream: generateList().asStream(),
builder: (BuildContext context, AsyncSnapshot snapshot) {
return ListView.builder(
itemCount: verlustContentList.length,
itemBuilder: (context, index) {
return verlustContentList[index];
},
);
},
);
带有设计的 VerlustContent 类是有状态的。
【问题讨论】:
-
你能发布一个最小的可重现代码来让我们更好地帮助我们吗?
-
是的,我会更新的
-
好的,我希望现在更容易
标签: flutter listview stream-builder