I need to add the value in the list which is comma separated.
Sample data:
English,Hindi,French
Below is the class of List:
Dart has a very good type checking system and I think your problem is an obvious one based on the error message. You must convert your list of String
into a list of Language
. I don't recall the syntax from the top of my head but I think you should be able to convert your list of String
with .map<List<Language>>((item) => Language(item))
One way you can do this is like this.
List<Language> _selectedLanguages;
_selectedLanguages = (responseBody['user_lang'].split(',') as List<String>).map((text) => Language(name: text)).toList();