Part 14 Convert the data

preview_player
Показать описание

Рекомендации по теме
Комментарии
Автор

Even though i use castFrom it throws same error

santhoshd
Автор

Future<void> fetchQuestions() async{
http.get(url).then((response) {
//the 'then' method returns a 'response' which is our data.
//to what's inside, we have to decode first.
var data = json.decode(response.body) as Map<String, dynamic>;

data.forEach((key, value) {
List<Question> newQuestions = [];
var newQuestion = Question(
id: key, //the encripted key/the title we gave to our data
title: value['title'], //title of the question
options: Map.castFrom(value['options'])//value['options'], the options
);
//add to newQuestions

print(newQuestions);
});
//print(newQuestions);
});
}
The //print(newQuestions); throws an error so I had to move it above. I hope it is not a problem in the future!

wowingles