[SYNC]
This commit is contained in:
@@ -15,6 +15,21 @@ class SheetStore extends ChangeNotifier {
|
||||
static final StreamController<UnmodifiableMapView<String, dynamic>> _stateStreamController = StreamController<UnmodifiableMapView<String, dynamic>>.broadcast();
|
||||
final Stream<UnmodifiableMapView<String, dynamic>> stateStream = _stateStreamController.stream;
|
||||
|
||||
/// Adds [item] to store.
|
||||
dynamic get(String itemID) {
|
||||
if (!_items.containsKey(itemID)) {
|
||||
throw Exception('No item with the ID $itemID exist in the SheetStore, Are you sure you added it?');
|
||||
}
|
||||
return _items[itemID];
|
||||
}
|
||||
|
||||
dynamic tryGet(String itemID) {
|
||||
if (!_items.containsKey(itemID)) {
|
||||
return null;
|
||||
}
|
||||
return _items[itemID];
|
||||
}
|
||||
|
||||
/// Adds [item] to store.
|
||||
void add(String itemID, dynamic value) {
|
||||
_items.addEntries(<MapEntry<String, dynamic>>[MapEntry<String, dynamic>(itemID, value)]);
|
||||
@@ -39,16 +54,15 @@ class SheetStore extends ChangeNotifier {
|
||||
|
||||
/// Removes [item] from the store.
|
||||
void remove(String itemID, dynamic value) {
|
||||
if (!_items.containsKey(itemID)) {
|
||||
throw Exception('No item with the ID $itemID exist in the SheetStore, Are you sure you added it?');
|
||||
}
|
||||
if (_items.containsKey(itemID)) {
|
||||
_items.remove(itemID);
|
||||
}
|
||||
// This call tells the widgets that are listening to this store to rebuild.
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
/// Return a stream builder for real-time value updates.
|
||||
Widget builder({required Widget child}) {
|
||||
return ListenableBuilder(listenable: this, builder: (_,__) => child);
|
||||
return ListenableBuilder(listenable: this, builder: (_, __) => child);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user