0
0
Fluttermobile~5 mins

SharedPreferences for key-value in Flutter - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AstoreBool(key, value)
BsaveBoolean(key, value)
CputBool(key, value)
DsetBool(key, value)
What type of data can SharedPreferences NOT store directly?
ACustom objects
Bint
CString
DList of strings
How do you get an instance of SharedPreferences in Flutter?
ASharedPreferences.instance()
BSharedPreferences.getInstance()
CSharedPreferences.create()
DSharedPreferences.new()
Which of these is a correct way to read a string value from SharedPreferences?
Aprefs.getString('key')
Bprefs.readString('key')
Cprefs.fetchString('key')
Dprefs.loadString('key')
What happens if you try to read a key that does not exist in SharedPreferences?
AReturns an empty string
BThrows an error
CReturns null
DReturns zero
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.