Skip to content

Commit 95d8668

Browse files
committed
bugfix: avoid clearing saved shared value on init
1 parent 205426e commit 95d8668

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

example/pubspec.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ packages:
204204
path: ".."
205205
relative: true
206206
source: path
207-
version: "2.1.0"
207+
version: "2.1.2"
208208
sky_engine:
209209
dependency: transitive
210210
description: flutter

lib/shared_value.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class SharedValue<T> {
4141

4242
SharedValue({this.key, required T value, this.autosave = false})
4343
: _value = value {
44-
_update(rebuild: false);
44+
_update(init: true);
4545
}
4646

4747
/// The value held by this state.
@@ -112,20 +112,20 @@ class SharedValue<T> {
112112
$ = fn(_value);
113113
}
114114

115-
void _update({rebuild: true}) {
115+
void _update({init: false}) {
116116
// update the nonce
117117
nonce = random.nextDouble();
118118
stateNonceMap[this] = nonce!;
119119

120-
if (rebuild) {
120+
if (!init) {
121121
// rebuild state manger widget
122122
stateManager.rebuild();
123123
}
124124

125125
// add value to stream
126126
_controller?.add($);
127127

128-
if (autosave) {
128+
if (!init && autosave) {
129129
save();
130130
}
131131
}

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: shared_value
22
description: A straightforward way to manage global state in flutter apps.
3-
version: 2.1.2
3+
version: 2.1.3
44
author: Dev Aggarwal <[email protected]>
55
homepage: https://github.com/scientifichackers/flutter-shared-value
66

0 commit comments

Comments
 (0)