添加动态表格行值列表

问题描述 投票:0回答:1

我尝试添加动态表格行列表值,但当我单击

Add Box
添加表格列表时,它显示此错误。

Another exception was thrown: type 'List<Map<String, Object>>' is not a subtype of type 'Map<List<dynamic>, dynamic>' in type cast
.

Container(
            // add button
            margin: EdgeInsets.only(top: 10),
            decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(2.0),
                color: Colors.grey[200],
                border: Border.all(color: Colors.grey[500], width: 1.5)),
            height: data.size.width * 0.039,
            child: FlatButton(
                onPressed: () {
                  setState(() {
                    Map<List, dynamic> rowValue = Map<List, dynamic>();
                    rowValue = [
                      {
                        'serialNo': '',
                        "table": [
                          [
                            {'first_a': ''},
                            {'Second_a': ''},
                            {'Third_a': ''},
                            {'Fourth_a': ''},
                            {'Fifth_a': ''},
                            {'Sixth_a': ''},
                            {'Seventh_a': ''},
                            {'Eighth_a': ''}
                          ],
                          [
                            {'first_b': ''},
                            {'Second_b': ''},
                            {'Third_b': ''},
                            {'Fourth_b': ''},
                            {'Fifth_b': ''},
                            {'Sixth_b': ''},
                            {'Seventh_b': ''},
                            {'Eighth_b': ''}
                          ],
                          [
                            {'first_c': ''},
                            {'Second_c': ''},
                            {'Third_c': ''},
                            {'Fourth_c': ''},
                            {'Fifth_c': ''},
                            {'Sixth_c': ''},
                            {'Seventh_c': ''},
                            {'Eighth_c': ''}
                          ],
                          [
                            {'first_d': ''},
                            {'Second_d': ''},
                            {'Third_d': ''},
                            {'Fourth_d': ''},
                            {'Fifth_d': ''},
                            {'Sixth_d': ''},
                            {'Seventh_d': ''},
                            {'Eighth_d': ''}
                          ],
                        ]
                      }
                    ] as Map<List, dynamic>;
                    print("get value new");
                    print(rowValue);
                    this.rowList.add(rowValue);
                    // updateDetails();
                  });
                },
                child: Text('+ Add Box',
                    style: TextStyle(
                        color: Colors.grey[900],
                        fontWeight: FontWeight.bold,
                        fontSize: data.size.width * 0.019))),
          ),
        ]));

这是我在 dartPad

中的完整代码

每个表格单元格用户都可以插入数据。

flutter dart arraylist
1个回答
0
投票

您的数据和该参数的类型不匹配。从您的代码示例中,我将重点关注

rowValue
的值,并且我假设您设置了错误的类型。尝试更改 rowValue 的类型,例如
List<Map<String,dynamic>> rowValue

© www.soinside.com 2019 - 2024. All rights reserved.