Recall & Review
beginner
What is SharedPreferences in Flutter?
SharedPreferences is a way to store small amounts of data as key-value pairs on the device. It is used for saving simple data like user settings or preferences.
Click to reveal answer
beginner
How do you save a string value using SharedPreferences in Flutter?
You get an instance of SharedPreferences and then use the method
setString(key, value) to save a string value with a key.Click to reveal answer
beginner
Which method do you use to read a value from SharedPreferences?
Use
getString(key) for strings, getInt(key) for integers, and similar methods for other types to read stored values by their key.Click to reveal answer
intermediate
Can SharedPreferences store complex objects like lists or maps directly?
No, SharedPreferences only stores simple data types like strings, ints, doubles, bools, and string lists. For complex objects, you need to convert them to a string format like JSON.
Click to reveal answer
beginner
Why is SharedPreferences suitable for storing user settings?
Because it is fast, simple, and persists data across app launches without needing a database. It is perfect for small pieces of data like user preferences.
Click to reveal answer
Which method is used to save a boolean value in SharedPreferences?
✗ Incorrect
The correct method to save a boolean value is setBool(key, value).
What type of data can SharedPreferences NOT store directly?
✗ Incorrect
SharedPreferences cannot store custom objects directly; they must be converted to strings first.
How do you get an instance of SharedPreferences in Flutter?
✗ Incorrect
You use SharedPreferences.getInstance() which returns a Future of SharedPreferences.
Which of these is a correct way to read a string value from SharedPreferences?
✗ Incorrect
The method to read a string is getString(key), so prefs.getString('key') is correct.
What happens if you try to read a key that does not exist in SharedPreferences?
✗ Incorrect
If the key does not exist, SharedPreferences returns null.
Explain how to save and retrieve a user preference using SharedPreferences in Flutter.
Think about how you get the SharedPreferences object and then use set and get methods.
You got /5 concepts.
Describe the limitations of SharedPreferences and when you might need a different storage solution.
Consider what kind of data SharedPreferences can handle well and what it cannot.
You got /5 concepts.