Recall & Review
beginner
What is a model class in Flutter when working with JSON?A model class is a simple Dart class that represents the structure of JSON data. It helps convert JSON into Dart objects and vice versa, making it easier to work with data in the app.Click to reveal answer
beginner
What is the purpose of the factory constructor named
fromJson in a model class?The <code>fromJson</code> factory constructor creates an instance of the model class from a JSON map. It reads JSON keys and assigns their values to the class properties.Click to reveal answer
beginner
Why do we use the
toJson method in a model class?The <code>toJson</code> method converts the model class instance back into a JSON map. This is useful when sending data to a server or saving it in JSON format.Click to reveal answer
intermediate
How do you handle nested JSON objects in Flutter model classes?
For nested JSON objects, create separate model classes for each nested structure. Use their <code>fromJson</code> and <code>toJson</code> methods inside the parent model class to convert nested data.Click to reveal answer
beginner
What Dart type is commonly used to represent JSON maps in model classes?
The Dart type
Map<String, dynamic> is used to represent JSON maps because JSON keys are strings and values can be any type.Click to reveal answer
Which method in a Flutter model class converts JSON data into a Dart object?
✗ Incorrect
The fromJson factory constructor reads JSON and creates a Dart object.
What Dart type is used to represent JSON data in model classes?
✗ Incorrect
JSON objects are represented as Map in Dart.
Why do we create separate model classes for nested JSON objects?
✗ Incorrect
Separate classes help manage nested JSON data clearly and convert it properly.
What does the toJson method do in a Flutter model class?
✗ Incorrect
toJson converts the Dart object back into JSON format.
Which keyword is used to create a constructor that returns an instance from JSON?
✗ Incorrect
The factory keyword defines a constructor that can return an instance, often used for fromJson.
Explain how to create a Flutter model class from JSON data.
Think about how you turn a map of data into a Dart object and back.
You got /4 concepts.
Describe how to handle nested JSON objects in Flutter model classes.
Imagine JSON like a family tree with smaller parts inside bigger parts.
You got /4 concepts.