@@ -46,33 +46,45 @@ final Map<String, dynamic> map = simplePreference.get('map');
46
46
47
47
``` dart
48
48
// Obtain shared preferences.
49
- final prefs = await SharedPreferences .getInstance();
49
+ final simplePreference = await SimpleSharedPreferences .getInstance();
50
50
51
51
// Save an integer value to 'counter' key.
52
- await prefs.setInt ('counter', 10);
52
+ await simplePreference.setValue<int> ('counter', 10);
53
53
// Save an boolean value to 'repeat' key.
54
- await prefs.setBool ('repeat', true);
54
+ await simplePreference.setValue<bool> ('repeat', true);
55
55
// Save an double value to 'decimal' key.
56
- await prefs.setDouble ('decimal', 1.5);
56
+ await simplePreference.setValue<double> ('decimal', 1.5);
57
57
// Save an String value to 'action' key.
58
- await prefs.setString ('action', 'Start');
58
+ await simplePreference.setValue<String> ('action', 'Start');
59
59
// Save an list of strings to 'items' key.
60
- await prefs.setStringList('items', <String>['Earth', 'Moon', 'Sun']);
60
+ await simplePreference.setValue<List<String>>('items', <String>['Earth', 'Moon', 'Sun']);
61
+
62
+ // Save an map - simple preference
63
+ await simplePreference.setValue<Map<String, dynamic>>('map', <String, dynamic>{
64
+ 'name': 'simple shared preferences',
65
+ 'age': 1,
66
+ 'isDeveloper': true,
67
+ 'height': 1.75,
68
+ 'list': [1, 2, 3],
69
+ });
61
70
```
62
71
63
72
#### Read data
64
73
65
74
``` dart
66
75
// Try reading data from the 'counter' key. If it doesn't exist, returns null.
67
- final int? counter = prefs.getInt ('counter');
76
+ final int? counter = simplePreference.getValue ('counter');
68
77
// Try reading data from the 'repeat' key. If it doesn't exist, returns null.
69
- final bool? repeat = prefs.getBool ('repeat');
78
+ final bool? repeat = simplePreference.getValue ('repeat');
70
79
// Try reading data from the 'decimal' key. If it doesn't exist, returns null.
71
- final double? decimal = prefs.getDouble ('decimal');
80
+ final double? decimal = simplePreference.getValue ('decimal');
72
81
// Try reading data from the 'action' key. If it doesn't exist, returns null.
73
- final String? action = prefs.getString ('action');
82
+ final String? action = simplePreference.getValue ('action');
74
83
// Try reading data from the 'items' key. If it doesn't exist, returns null.
75
- final List<String>? items = prefs.getStringList('items');
84
+ final List<String>? items = simplePreference.getValue'items');
85
+
86
+ // Try reading data from the 'map' key. If it doesn't exist, returns null
87
+ final Map<String, dynamic>? map = simplePreference.getValue('map');
76
88
```
77
89
78
90
#### Remove an entry
0 commit comments