You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+77-47Lines changed: 77 additions & 47 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,32 +23,37 @@
23
23
- This package provides reactive shared preferences interaction with very little code. It is designed specifically to be used with Flutter and Dart.
24
24
25
25
## Buy me a coffee
26
+
26
27
Liked some of my work? Buy me a coffee (or more likely a beer)
27
28
28
-
[](https://www.buymeacoffee.com/hoc081098)
29
+
<ahref="https://www.buymeacoffee.com/hoc081098"target="_blank"><imgsrc="https://cdn.buymeacoffee.com/buttons/v2/default-blue.png"alt="Buy Me A Coffee"height=64></a>
29
30
30
31
## Note
31
32
32
33
Since version `1.3.4`, this package is an extension of [rx_storage](https://github.com/Flutter-Dart-Open-Source/rx_storage) package.
33
34
34
-
## More detail about returned `Stream`
35
-
- It's a **single-subscription `Stream`** (ie. it can only be listened once).
35
+
## More details about the returned `Stream`
36
+
37
+
- It's a **single-subscription `Stream`** (i.e. it can only be listened once).
36
38
37
-
-`Stream` will emit the **value (nullable)** or **a `TypeError`** as its first event when it is listen to.
39
+
-`Stream` will emit the **value (nullable)** or **a `TypeError`** as its first event when it is listened to.
38
40
39
-
- It will automatically emit value when value associated with key was changed successfully
40
-
(**emit `null`** when value associated with key was `removed` or set to `null`).
41
+
- It will **automatically** emit the new value when the value associated with key was changed successfully
42
+
(it will also **emit `null`** when value associated with key was `removed` or set to `null`).
41
43
42
44
- When value read from Storage has a type other than expected type:
43
45
- If value is `null`, the `Stream` will **emit `null`** (this occurred because `null` can be cast to any nullable type).
44
46
- Otherwise, the `Stream` will **emit a `TypeError`**.
45
47
46
-
-**Can emit** two consecutive data events that are equal. You should use Rx operator like `distinct` (More commonly known as `distinctUntilChanged` in other Rx implementations) to create an `Stream` where data events are skipped if they are equal to the previous data event.
48
+
-**Can emit** two consecutive data events that are equal.
49
+
You should use Rx operator like `distinct`
50
+
(more commonly known as `distinctUntilChanged` in other Rx implementations)
51
+
to create a `Stream` where data events are skipped if they are equal to the previous data event.
47
52
48
53
```text
49
-
Key changed: |----------K1---K2------K1----K1-----K2---------> time
54
+
Key changed |----------K1---K2------K1----K1-----K2---------> time
50
55
|
51
-
Value stream: |-----@----@------------@-----@-----------------> time
56
+
Value stream |-----@----@------------@-----@-----------------> time
52
57
| ^
53
58
| |
54
59
| Listen(key=K1)
@@ -65,13 +70,13 @@ In your flutter project, add the dependency to your `pubspec.yaml`
// must **use same rxPrefs** instance when set value and select stream
144
-
await rxPrefs.setStringList('KEY_LIST', ['Cool']); // [*] will print ['Cool']
150
+
await rxPrefs.setStringList('KEY_LIST', ['Cool']); // [*] will print ['Cool']
145
151
```
146
152
147
-
- In the previous example we re-used the RxSharedPreferences object `rxPrefs` for all writing operations. All writing operations must go through this object in order to correctly notify subscribers.
153
+
- In the previous example, we re-used the `RxSharedPreferences` object `rxPrefs` for all operations.
154
+
All operations must go through this object in order to correctly notify subscribers.
155
+
Basically, you must use the same `RxSharedPreferences` instance when set value and select stream.
148
156
149
-
- In Flutter, you:
150
-
- Can create global `RxSharedPreferences` instance.
157
+
- In a Flutter app, you can:
158
+
- Create a global `RxSharedPreferences` instance.
151
159
152
-
- Can use default singleton instance `RxSharedPreferences.getInstance()`
160
+
- Use the default singleton instance via `RxSharedPreferences.getInstance()`.
153
161
154
-
- Can use `InheritedWidget`/`Provider` to provide a `RxSharedPreferences` instance (create it in `main` function) for all widgets (recommended).
155
-
See [example/main](https://github.com/hoc081098/rx_shared_preferences/blob/86ae13abf0bcff995d0d99c54b11b103142a257e/example/lib/main.dart#L18).
162
+
- Use `InheritedWidget`/`Provider` to provide a `RxSharedPreferences` instance (create it in `main` function) for all widgets (recommended).
163
+
See [example/main](https://github.com/hoc081098/rx_shared_preferences/blob/95642a7fe8e8e0ad4579d7ae084aec9a10fe6dff/example/lib/main.dart#L17).
- All methods from [RxStorage](https://pub.dev/documentation/rx_storage/latest/rx_storage/RxStorage-class.html) (`RxSharedPreferences` implements `RxStorage`).
194
+
- All methods from [RxStorage](https://pub.dev/documentation/rx_storage/latest/rx_storage/RxStorage-class.html)
- All methods from [Storage](https://pub.dev/documentation/rx_storage/latest/rx_storage/Storage-class.html) (`RxSharedPreferences` implements `Storage`).
225
+
- All methods from [Storage](https://pub.dev/documentation/rx_storage/latest/rx_storage/Storage-class.html)
0 commit comments