List<String> langList = [English, Gujarati, Hindi, Marathi, Punjabi, Urdu, Spanish]
var selectedLanguagesList = <LanguageDatum>[].obs;
langList is a string type of list. and selectedLanguagesList is a model type of list. How do I convert string list to model list in flutter ?
CodePudding user response:
Right now your language is of String type, to make language object You need to make a model class say,
Class LanguageDatum{
String name;
...
}
CodePudding user response:
If I understand your question correctly, I guess it would be
List<String> langList = [
'English',
'Gujarati',
'Hindi',
'Marathi',
'Punjabi',
'Urdu',
'Spanish'
];
class LanguageDatum extends GetxController {
final String lang;
LanguageDatum({required this.lang});
}
RxList<LanguageDatum> selectedLanguagesList =
langList.map((e) => LanguageDatum(lang: e.toString())).toList().obs;