小编Jah*_*iya的帖子

从动态数据表颤动中获取选定的行索引

在颤振中,我有动态小部件数据表。使用按钮提交值(通过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)

android datatables dart flutter flutter-layout

2
推荐指数
1
解决办法
4544
查看次数

标签 统计

android ×1

dart ×1

datatables ×1

flutter ×1

flutter-layout ×1