From f9627998e7d95704b767fbae5d1188251cdc5507 Mon Sep 17 00:00:00 2001 From: "Michael W. Aziz" Date: Sun, 27 Apr 2025 14:32:30 +0300 Subject: [PATCH] [SYNC] --- .../sheet/src/models/sheet_store.model.dart | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) 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); } }