Skip to content

Commit 6690d82

Browse files
committed
doc: update README
1 parent a86ab8f commit 6690d82

File tree

4 files changed

+29
-13
lines changed

4 files changed

+29
-13
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.0.1
2+
3+
* Doc: Update README.md
4+
15
## 1.0.0
26

37
* Initial release

README.md

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,33 +46,45 @@ final Map<String, dynamic> map = simplePreference.get('map');
4646

4747
```dart
4848
// Obtain shared preferences.
49-
final prefs = await SharedPreferences.getInstance();
49+
final simplePreference = await SimpleSharedPreferences.getInstance();
5050
5151
// Save an integer value to 'counter' key.
52-
await prefs.setInt('counter', 10);
52+
await simplePreference.setValue<int>('counter', 10);
5353
// Save an boolean value to 'repeat' key.
54-
await prefs.setBool('repeat', true);
54+
await simplePreference.setValue<bool>('repeat', true);
5555
// Save an double value to 'decimal' key.
56-
await prefs.setDouble('decimal', 1.5);
56+
await simplePreference.setValue<double>('decimal', 1.5);
5757
// Save an String value to 'action' key.
58-
await prefs.setString('action', 'Start');
58+
await simplePreference.setValue<String>('action', 'Start');
5959
// 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+
});
6170
```
6271

6372
#### Read data
6473

6574
```dart
6675
// 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');
6877
// 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');
7079
// 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');
7281
// 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');
7483
// 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');
7688
```
7789

7890
#### Remove an entry

lib/simple_shared_preferences.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class SimpleSharedPreferences {
8686
if (T == Map<String, dynamic>) {
8787
final String? jsonString = _sp!.getString(key);
8888
if (jsonString == null) {
89-
return <String, dynamic>{} as T;
89+
return null;
9090
}
9191
return jsonDecode(jsonString) as T;
9292
}

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: simple_shared_preferences
22
description: A simple wrapper for [SharedPreferences] that supports string, int, double, bool, List<String>, and Map<String, dynamic> types.
3-
version: 1.0.0
3+
version: 1.0.1
44
homepage: https://github.com/camus-design/simple_shared_preferences
55

66
environment:

0 commit comments

Comments
 (0)