I want to load the list question in question.dart into main.dart. I wrote the code as
final newoptions = quiz[1].options
to get the options('good') in the second of the list question.
But after running it I get this error:
Class '_ImmutableMap<String, Object>' has no instance getter 'options'. Receiver: Instance of '_ImmutableMap<String, Object>' Tried calling: options
How do I solve this?
question.dart
class Question {
final int id;
final String options;
Question({required this.id, required this.options});
}
const List quiz = [
{
"id": 1,
"options": 'hello',
},
{
"id": 2,
"options": 'good',
},
{
"id": 3,
"options": 'abc',
},
];
main.dart
class Body extends StatefulWidget {
@override
_Body createState() => _Body();
}
class _Body extends State<Body> {
final newoptions = quiz[1].options;
...
}
final newoptions = quiz[1]['options']