1

I have two textfields and i want to add them in list in object form like this

{"color":red,"size":L},{"color":blue,"size":S}

here is my code

i created this list

List<dynamic> _colorList = [];

and using it in a button like this

 _colorList.add({"color": currentColor, "size": size.text});

and i need to remove the items from list too so unable to use Map<String, Object>

Error:

The argument type 'Map<String, Object>' can't be assigned to the parameter type 'String'.

please help how to do this.

1 Answer 1

2

you have to use Map<String, dynamic> and write a custom delete function.

void main() {
  
  List<Map<String, dynamic>> _colorList = [];
  
  void  deleteByColorName (String colorName)  {
    _colorList.removeWhere((element) {
    return  element["color"] == colorName;
    });
  }
  
  _colorList.add({"color": "colorA", "size": 1});
  _colorList.add({"color": "colorB", "size": 1});
  
  deleteByColorName("colorA");
  
  print(_colorList);
}

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.