如何在ListView.builder中编辑/删除项目在不同类中
我试过了
setState(() =>queueData.removeAt(widget.number-1);
listview.builder 的QueueGenerator 类列表中的按钮
TextButton(
onPressed: () {
Navigator.pop(context, "OK");
setState(() {
// remove and update listview ?
queueData[widget.number-1] = _controller
.text
.toString();
});
},
child: Text("Confirm",
style: Theme.of(context).textTheme.labelSmall))
(这与两个类位于不同的文件中)
List<String> queueData = [];
List<String> queueTemp = [];
Listview.builder
ListView.builder(
itemCount: qList.length,
itemBuilder: (context, index) {
return QueueGenerator(
number: index + 1,
description: qList[index]);
})
I've tried
setState(() => queueData.removeAt(widget.number-1);
button from QueueGenerator class
TextButton(
onPressed: () {
Navigator.pop(context, "OK");
setState(() {
// remove and update listview ?
queueData[widget.number-1] = _controller
.text
.toString();
});
},
child: Text("Confirm",
style: Theme.of(context).textTheme.labelSmall))
lists for listview.builder (this is in different file from both classes)
List<String> queueData = [];
List<String> queueTemp = [];
Listview.builder
ListView.builder(
itemCount: qList.length,
itemBuilder: (context, index) {
return QueueGenerator(
number: index + 1,
description: qList[index]);
})
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,您可以将这两个列表
作为全局变量进行,并在此使用它们而无需将它们作为窗口小部件中的参数
快速解决方案,但我不建议它
,或者您需要将它们作为私人变量放在提供商中,并为其创建Getters和Setters的功能,以便您可以编辑它们
:当您调用他们在其中的提供商时,请确保听是真实的
well you can either make these two lists
as global variables and use them there without passing them as a parameter in the widget
fast solution but I don't recommend it
or you need to put them in the provider as private variables and create functions of getters and setters for them so you can edit them
note: when you call the provider which they are in it make sure the listen is true to see the changes