在颤振中,我有动态小部件数据表。使用按钮提交值(通过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');
} …Run Code Online (Sandbox Code Playgroud)