unified_local_data library

Engine-agnostic local storage for Flutter.

Create a data source with UnifiedDataSourceFactory.create and a config, such as UnifiedDataSourceConfig.hive, then use the UnifiedDataSource API: the same calls work on every engine. For Isar, add the unified_local_data_isar package. To write an engine of your own, see package:unified_local_data/engine.dart.

Classes

DataModel<T>
An optional contract for models that convert themselves to and from JSON. The API uses DataModelAdapter, not this interface.
DataModelAdapter<T>
Converts T to and from JSON for the object methods of UnifiedDataSource, such as putObject and getObject.
HiveDataSource
The Hive engine: each collection is a Hive box, holding values under string keys.
HiveDataSourceConfig
Configuration for the Hive engine, which stores each collection in its own Hive box.
HiveEncryptionConfig
The AES key that encrypts every Hive box the data source opens.
NativeCollectionAccessor<T>
Direct access to one collection through the engine's own types, returned by UnifiedDataSource.native.
QueryBuilder<T>
A chainable query over the objects of one collection.
UnifiedDataSource
Local key-value storage that works the same on every engine.
UnifiedDataSourceConfig
Which engine a UnifiedDataSource uses, and how.
UnifiedDataSourceFactory
Creates the app's UnifiedDataSource and keeps it as a singleton.

Extensions

LocalDataSourceStreamX on Stream<T>
Stream helpers for the watch methods of UnifiedDataSource.

Typedefs

FromJson<T> = T Function(JsonMap json)
Builds a T from a JSON object.
JsonMap = Map<String, dynamic>
A JSON object.
SortComparator<T> = int Function(T a, T b)
Orders two query results, the way Comparator does.
ToJson<T> = JsonMap Function(T object)
Turns a T into a JSON object.
WhereClause<T> = bool Function(T item)
Whether item belongs in a query's results.

Exceptions / Errors

DataNotFoundException
Thrown when requested data doesn't exist.
DataSourceNotInitializedException
Thrown when a data source is used before init() or after dispose().
DataSourceReadException
Thrown when a read fails, including when a stored value isn't of the requested type. Watch streams emit it as an error.
DataSourceWriteException
Thrown when a write, a delete, clear or drop fails.
LocalDataSourceException
The base of every exception a UnifiedDataSource throws.
UnsupportedOperationException
Thrown when the engine can't do what was asked, such as returning a native accessor for a box that isn't open.