This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
home: Scaffold( | |
body: CustomScrollView( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
prefs.reload(); | |
// or | |
await prefs.reload(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Remove an entry | |
final removeSuccessful = await prefs.remove("name"); | |
// or | |
prefs.remove("age"); | |
// Delete database | |
prefs.clear(); | |
// or | |
final prefsCleared = await prefs.clear() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bool storingSuccessful; | |
storingSuccessful = await prefs.setString("name", "Rashed"); | |
storingSuccessful = await prefs.setInt("age", 20); | |
storingSuccessful = await prefs.setDouble("score", 100.0); | |
storingSuccessful = await prefs.setBool("darkMode", true); | |
storingSuccessful = await prefs.setStringList("aliases",[]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
prefs.setString("name", "Rashed"); | |
prefs.setInt("age", 20); | |
prefs.setDouble("score", 100.0); | |
prefs.setBool("darkMode", true); | |
prefs.setStringList("aliases", ["rashed", "rashedmyt"]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String name = prefs.getString("name"); | |
int age = prefs.getInt("age"); | |
double score = prefs.getDouble("score"); | |
bool darkMode = prefs.getBool("darkMode"); | |
List<String> aliases = prefs.getStringList("aliases"); | |
var auto = prefs.get("auto"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final prefs = await SharedPreferences.getInstance(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:shared_preferences/shared_preferences.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dependencies: | |
flutter: | |
sdk: flutter | |
shared_preferences: ^0.5.3+1 // replace with newest version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Retrieves list of keys present in DB | |
List<String> keys = prefs.getKeys(); | |
// Checks whether given key exists in DB | |
bool keyPresent = prefs.containsKey("name"); |
NewerOlder