【发布时间】:2020-02-15 11:40:39
【问题描述】:
在颤振中,我有动态小部件数据表。使用按钮在提交值(通过edittextbox)时添加行。在行字段中添加和删除行(在单击特定行时)。下面的代码给了我从列表中删除最后一行的输出。我需要从表中删除我单击/选择的行。它应该找到该行的索引以删除该行。有没有其他方法可以达到预期的效果?
我正在使用List<DataRow> row =[];
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
FlatButton.icon(
color: Colors.orange,
icon: Icon(FontAwesomeIcons.shoppingBag),
label: Text('Add to List'),
onPressed: () async{
ttl = int.parse(rate) * int.parse(noInputController.text);
setState(() {
this.row.add(
new DataRow(
cells: [
DataCell( Icon(Icons.remove_circle, color: Colors.red,),
//Text('remove', style: TextStyle(color: Colors.blue,decoration: TextDecoration.underline,),
onTap: () {
setState(() {
//remove item
if(amt > 0){
amt = amt - ttl;
}
print(amt);
if (index != -1){
print("before: $index $rowindex");
rowindex.removeAt(index);
//row.removeAt(index);
index = index - 1;
print("after: $index $rowindex");
}else{
print('no rows');
}
});
}),
DataCell(Text(prd),
onTap: () {
setState(() {
});
}),
DataCell(Text(noInputController.text),
onTap: () {
setState(() {
});
}),
DataCell(Text(rate),
onTap: () {
setState(() {
});
}),
DataCell(Text(ttl.toString()),
onTap: () {
setState(() {
});
}),
DataCell(Text(stype),
onTap: () {
setState(() {
});
}),
]));
print("before: $index $rowindex");
index = index + 1;
this.rowindex.add(index);
print("after: $index $rowindex");
// print(this.row.length);
return this.row;
});
rstitem(); //get total
}
),]),
SizedBox(
height: ScreenUtil.getInstance().setHeight(20),
),
new SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: DataTable(
columns: [
DataColumn(label: Text("Remove",style: TextStyle(fontWeight: FontWeight.bold, fontSize: 15.0,color: Colors.blue))),
DataColumn( //tooltip: "item code for products",
label: Text("Name",style: TextStyle(fontWeight: FontWeight.bold,fontSize: 15.0,color: Colors.blue))),
DataColumn(label: Text("Quantity",style: TextStyle(fontWeight: FontWeight.bold, fontSize: 15.0,color: Colors.blue))),
DataColumn(label: Text("Rate",style: TextStyle(fontWeight: FontWeight.bold, fontSize: 15.0,color: Colors.blue))),
DataColumn(label: Text("Total",style: TextStyle(fontWeight: FontWeight.bold, fontSize: 15.0,color: Colors.blue))),
DataColumn(label: Text("Item Type",style: TextStyle(fontWeight: FontWeight.bold, fontSize: 15.0,color: Colors.blue)))
],
rows: row,
),),
帮我解决这个问题。
【问题讨论】:
标签: android flutter dart datatables flutter-layout