0
0
Fluttermobile~10 mins

SharedPreferences for key-value in Flutter - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the SharedPreferences package.

Flutter
import 'package:[1]/shared_preferences.dart';
Drag options to blanks, or click blank then click option'
Ashared_preferences
Bflutter
Cprefs
Dstorage
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect package names like 'flutter' or 'prefs'.
Forgetting to import the package.
2fill in blank
medium

Complete the code to get an instance of SharedPreferences asynchronously.

Flutter
final prefs = await SharedPreferences.[1]();
Drag options to blanks, or click blank then click option'
Ainstance
BgetInstance
Cinit
Dload
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'instance' or 'init' which do not exist.
Not using await for the asynchronous call.
3fill in blank
hard

Fix the error in saving a string value with key 'username'.

Flutter
await prefs.[1]('username', 'Alice');
Drag options to blanks, or click blank then click option'
AputString
BsaveString
CsetString
DstoreString
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent methods like 'saveString' or 'putString'.
Confusing with other storage APIs.
4fill in blank
hard

Fill both blanks to read a string value for key 'username' with a default fallback.

Flutter
String username = prefs.[1]('username') ?? [2];
Drag options to blanks, or click blank then click option'
AgetString
B'Guest'
C'Anonymous'
Dget
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'get' instead of 'getString'.
Not providing a default value causing null errors.
5fill in blank
hard

Fill all three blanks to remove a key and check if it was removed successfully.

Flutter
bool removed = await prefs.[1]('username');
if (removed) {
  print('[2] was removed');
} else {
  print('[3] not found');
}
Drag options to blanks, or click blank then click option'
Aremove
Busername
CKey
DUser
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong method names like 'delete'.
Using incorrect key names in messages.