Add comma separated value to class list

前端 未结 2 1660
时光取名叫无心
时光取名叫无心 2021-01-22 19:40

I need to add the value in the list which is comma separated.

Sample data:

English,Hindi,French

Below is the class of List:



        
相关标签:
2条回答
  • 2021-01-22 20:16

    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))

    0 讨论(0)
  • 2021-01-22 20:19

    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();
    
    0 讨论(0)
提交回复
热议问题