【发布时间】:2020-01-11 22:24:31
【问题描述】:
我有一个 listTiles 列表,每个列表都带有文本,旁边有一个按钮来删除磁贴。如果按钮被按下,用户确认他们想要删除它并且该图块被移除。以前我使用了一个带键的可关闭小部件,但在这种情况下,我如何将列表中的项目与我需要删除的图块相关联。
代码(忽略onTap(),底部的flatButtons作为提示):
ListView.builder(
itemCount: subGoals.length,
itemBuilder: (context,index){
return Card(
color: Colors.grey[500],
child: ListTile(
onTap: (){
//should make new list with the title of the ListTile's text
},
title: Text(subGoals[index],
style: TextStyle(color: Colors.white,fontSize: 35),
),
trailing: IconButton(
icon: Icon(Icons.close),
color: Colors.white,
splashColor: Colors.red[600],
onPressed: (){
showDialog(
context: context,
builder: (BuildContext context){
return AlertDialog(
title: Center(child: Text("Delete List?", style: TextStyle(fontSize: 25))),
content: Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
FlatButton(
child: Text("Yes", style: TextStyle(fontSize: 22)),
onPressed: (){
if(true){
//removeTile method goes here
}
}
),
FlatButton(
child: Text("No", style: TextStyle(fontSize: 22)),
onPressed: (){
Navigator.pop(context);
}
),
【问题讨论】:
-
您是否没有使用某种
List的项目在您的ListView中生成您的ListTiles? -
是的,我很困惑的是,当我按下按钮时,程序如何知道我点击了列表的哪个索引。有什么我可以访问的东西将按钮与瓷砖/索引的其余部分联系起来
标签: flutter