Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to open a Hive box named 'settings'.
Flutter
var box = await Hive.[1]('settings');
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using closeBox instead of openBox
Trying to createBox which doesn't exist
✗ Incorrect
Use openBox to open or create a box in Hive.
2fill in blank
mediumComplete the code to add a value 'dark' with key 'theme' to the box.
Flutter
await box.[1]('theme', 'dark');
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using get instead of put
Using delete or clear which remove data
✗ Incorrect
Use put to store a value with a key in Hive.
3fill in blank
hardFix the error in the code to read the value for key 'username' from the box.
Flutter
var username = box.[1]('username');
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using put instead of get
Using delete or clear which remove data
✗ Incorrect
Use get to read a value by key from Hive box.
4fill in blank
hardFill both blanks to delete the key 'token' and then close the box.
Flutter
await box.[1]('token'); await box.[2]();
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using put or get instead of delete
Not closing the box properly
✗ Incorrect
Use delete to remove a key and close to close the box.
5fill in blank
hardFill all three blanks to create a map of all keys and values where values are not null.
Flutter
var allData = {for (var key in box.[1]) if (box.[3](key) != null) key: box.[2](key)}; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using values instead of keys for iteration
Using wrong method to get values
✗ Incorrect
Use keys to iterate keys, and get to get values.