Skip to content

Commit 322bf2d

Browse files
committed
Add waitUntil()
0.4.0
1 parent 2af1c4c commit 322bf2d

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/shared_value.dart

+9
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,15 @@ class SharedValue<T> {
126126
}
127127
}
128128

129+
Future<void> waitUntil(bool Function(T) predicate) async {
130+
// short-circuit if predicate already satisfied
131+
if (predicate(value)) return;
132+
// otherwise, run predicate on every change
133+
await for (T value in this.stream) {
134+
if (predicate(value)) break;
135+
}
136+
}
137+
129138
/// Try to load the value stored at [key] in shared preferences.
130139
/// If no value is found, return immediately.
131140
/// Else, udpdate [value] and rebuild dependent widgets if it changed.

pubspec.yaml

+1-1
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: 0.3.3
3+
version: 0.4.0
44
author: Dev Aggarwal <[email protected]>
55
homepage: https://github.com/pycampers/flutter-global-state
66

0 commit comments

Comments
 (0)