skip to Main Content

I try to add dynamic table row list value but it display this error when I click Add Box to add table list.

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))),
          ),
        ]));

this is my full code in dartPad

every table cell user can insert data. And this question continue from this make model of array object in flutter

2

Answers


  1. Your data and the type of this parameter doesn’t match. From your code examplt, I will focus the value of the rowValue and I assume you set the wrong type. Try to change the type of the rowValue like List<Map<String,dynamic>> rowValue.

    Login or Signup to reply.
  2. Declared type and assigned data type are different. Declared type is Map<List, dynamic> and the date being assigned is List<Map<String, Object>>

    Since there’s only one map in rowValue data list, we may remove the list type as well as the cast, cause we don’t need to cast the type.

    This should work.

    Map<String, dynamic> rowValue = <String, 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': ''}
                    ],
                  ]
                };
    
              
                this.rowList.add(rowValue);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search