diff --git a/lib/src/sheet/src/models/sheet_store.model.dart b/lib/src/sheet/src/models/sheet_store.model.dart index 95e7a62..4516f53 100644 --- a/lib/src/sheet/src/models/sheet_store.model.dart +++ b/lib/src/sheet/src/models/sheet_store.model.dart @@ -15,6 +15,21 @@ class SheetStore extends ChangeNotifier { static final StreamController> _stateStreamController = StreamController>.broadcast(); final Stream> 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(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); } - _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); } }