Complete the code to save a string value to local storage using Flutter's SharedPreferences.
final prefs = await SharedPreferences.getInstance(); await prefs.setString('username', [1]);
You must provide the string value in quotes to save it correctly.
Complete the code to read a string value from local storage using Flutter's SharedPreferences.
final prefs = await SharedPreferences.getInstance(); String? username = prefs.[1]('username');
Use getString to retrieve a string value from SharedPreferences.
Fix the error in the code to check if local storage has a key before reading it.
final prefs = await SharedPreferences.getInstance(); if (prefs.[1]('username')) { String? username = prefs.getString('username'); }
The correct method to check if a key exists in SharedPreferences is containsKey.
Fill both blanks to save and then read an integer value from local storage.
final prefs = await SharedPreferences.getInstance(); await prefs.[1]('counter', 10); int? counter = prefs.[2]('counter');
Use setInt to save an integer and getInt to read it back.
Fill both blanks to remove a key from local storage and check if it still exists.
final prefs = await SharedPreferences.getInstance(); await prefs.[1]('session'); bool exists = prefs.[2]('session'); print('Session key exists: ' + exists.toString());
Use remove to delete a key, containsKey to check if it exists.