JsonStorageContainer<E extends Object> class
final
A final implementation of SerializableStorageContainer for JSON-serializable objects.
JsonStorageContainer provides a complete, ready-to-use container for storing custom Dart objects using JSON serialization. It automatically handles the conversion between objects and their JSON string representation, making it easy to persist complex data structures.
Purpose
This class bridges the gap between Dart objects and storage by:
- Automatic Serialization: Converting objects to JSON strings for storage
- Automatic Deserialization: Converting JSON strings back to objects
- Type Safety: Ensuring type-safe operations through generics
- ID Management: Supporting both custom ID extraction and automatic generation
- Full CRUD: Providing complete create, read, update, delete operations
See also:
- SerializableStorageContainer for the base class
- HyperStorage.jsonContainer for creating instances
- FromJson and ToJson typedefs for serialization functions
- IdGetter for custom ID extraction
- Inheritance
-
- Object
- BaseStorage
- SerializableStorageContainer<
E> - JsonStorageContainer
Constructors
-
JsonStorageContainer({required StorageBackend backend, required ToJson<
E> toJson, required FromJson<E> fromJson, IdGetter<E> ? idGetter, required String name, Random? random, String? delimiter, int? seed}) -
Creates a new JsonStorageContainer for storing objects of type
E.
Properties
- delimiter → String
-
The character(s) used to separate the container name from the key.
finalinherited
-
fromJson
→ FromJson<
E> -
The function used to convert JSON maps back to objects of type
E.final - hashCode → int
-
The hash code for this object.
no setterinherited
- hasListeners → bool
-
Returns
trueif there are any listeners registered (global or keyed).no setterinherited -
idGetter
→ IdGetter<
E> ? -
An optional function that extracts the ID from an object.
finalinherited
-
isEmpty
→ Future<
bool> -
Returns
trueif the container has no stored objects.no setterinherited -
isNotEmpty
→ Future<
bool> -
Returns
trueif the container has at least one stored object.no setterinherited - name → String
-
The name of the storage container, used for namespacing keys.
finalinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
toJson
→ ToJson<
E> -
The function used to convert objects of type
Eto JSON maps.final
Methods
-
add(
E value) → Future< void> -
Adds an object to the container using its ID.
inherited
-
addAll(
Iterable< E> values) → Future<void> -
Adds multiple objects to the container using their IDs.
inherited
-
addKeyListener(
String key, ListenableCallback listener) → void -
Registers a listener to be called when data for a specific
keychanges.inherited -
addListener(
ListenableCallback listener) → void -
Registers a global listener to be called when any data in the storage
changes.
inherited
-
clear(
) → Future< void> -
Removes all objects from the container.
inherited
-
close(
) → Future< void> -
Closes the container and releases all resources.
inherited
-
containsKey(
String key) → Future< bool> -
Checks if an object with the given key exists in the container.
inherited
-
deserialize(
String value) → E -
Deserializes a string back to an object of type
E.override -
generateId(
) → String -
Generates a new unique ID for an object.
inherited
-
get(
String? key) → Future< E?> -
Retrieves an object by its key.
inherited
-
getAll(
[Iterable< String> ? allowList]) → Future<Map< String, E> > -
Retrieves multiple objects from the container.
inherited
-
getDecodedKeys(
) → Future< Set< String> > -
Returns a set of all decoded keys in the container.
inherited
-
getEncodedKeys(
) → Future< Set< String> > -
Returns a set of all encoded keys in the container.
inherited
-
getId(
E value) → String -
Gets the ID for the given object.
inherited
-
getKeys(
) → Future< Set< String> > -
Returns all keys (IDs) of objects stored in the container.
inherited
-
getValues(
) → Future< List< E> > -
Retrieves all objects from the container as a list.
inherited
-
hasKeyListeners(
String key) → bool -
Returns
trueif there are any listeners registered for the givenkey.inherited -
itemHolder(
String key) → SerializableItemHolder< E> -
Creates an item holder for storing a single primitive value at the specified key.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
notifyKeyListeners(
String key) → void -
Notifies all listeners that are registered for a specific
key.inherited -
notifyListeners(
[String? key]) → void -
Notifies all registered listeners of a change.
inherited
-
remove(
String key) → Future< void> -
Removes an object by its key.
inherited
-
removeAll(
Iterable< String> keys) → Future<void> -
Removes multiple objects by their keys.
inherited
-
removeAllItems(
Iterable< E> items) → Future<void> -
Removes multiple objects from the container.
inherited
-
removeAllKeyListeners(
String key) → void -
Removes all listeners registered for a specific
key.inherited -
removeAllListeners(
) → void -
Removes all registered listeners, both global and key-specific.
inherited
-
removeItem(
E item) → Future< void> -
Removes an object from the container.
inherited
-
removeKeyListener(
String key, ListenableCallback listener) → void -
Removes a previously registered key-specific listener.
inherited
-
removeListener(
ListenableCallback listener) → void -
Removes a previously registered global listener.
inherited
-
serialize(
E value) → String -
Serializes an object of type
Eto a string for storage.override -
set(
String key, E value) → Future< void> -
Stores an object with the specified key.
inherited
-
setAll(
Map< String, E> items) → Future<void> -
Stores multiple objects with their associated keys.
inherited
-
stream(
String key) → Stream< E?> -
Provides a Stream of values for the given
key. The stream will emit the current value of the key and will update whenever the value changes.inherited -
streamAll(
) → Stream< List< E> > -
Provides a Stream of values for all items in the container.
The stream will emit the current values and will update
whenever any value changes.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
update(
E value) → Future< void> -
Updates an existing object in the container.
inherited
-
updateAll(
Iterable< E> values) → Future<void> -
Updates multiple existing objects in the container.
inherited
-
validateKeys(
Iterable< String> ? keys) → void -
Validates a collection of storage
keysto ensure they all meet requirements.inherited -
validateName(
String name) → void -
Validates the given container
nameto ensure it meets requirements.inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited