Adapter for custom synchronous or asynchronous store callbacks. Operations without callbacks are unavailable.
load is required; byKey/insert/update/remove are optional. load receives TxLoadOptions and returns TxLoadResult directly or asynchronously. Custom HTTP callbacks must check status codes and propagate failures. byKey returns undefined/null for a missing record. For paging, return data and totalCount before paging. With remoteOperations false, return all raw data. The example uses a local async callback and requires no server.
TxCustomStore
| Parameter | Type | Default | Meaning |
|---|---|---|---|
| load | FutureOr<TxLoadResult<T>> Function(TxLoadOptions<T>) | required | Loads using the supplied options; DataSource uses current query state without arguments. Errors propagate. |
| byKey | FutureOr<T?> Function(Object)? | null | Reads a record by key; missing keys return undefined (Vue) or null (Dart). |
| insert | FutureOr<T> Function(T)? | null | Inserts a record with a unique key and returns it. |
| update | FutureOr<T> Function(Object, T Function(T))? | null | Updates a notification or record. |
| remove | FutureOr<void> Function(Object)? | null | Removes the record or recursively removes a file/directory tree. |
| Member / type / return | Meaning |
|---|---|
bool get canByKey | Whether the store supports ByKey. |
bool get canInsert | Whether the store supports Insert. |
bool get canUpdate | Whether the store supports Update. |
bool get canRemove | Whether the store supports Remove. |
FutureOr<TxLoadResult<T>> load(TxLoadOptions<T> options) | Loads using the supplied options; DataSource uses current query state without arguments. Errors propagate. |
FutureOr<T?> byKey(Object key) | Reads a record by key; missing keys return undefined (Vue) or null (Dart). |
FutureOr<T> insert(T item) | Inserts a record with a unique key and returns it. |
FutureOr<T> update(Object key, T Function(T) change) | Updates a notification or record. |
FutureOr<void> remove(Object key) | Removes the record or recursively removes a file/directory tree. |
import 'package:tecexpress/tecexpress.dart';
Future<void> example() async {
final store = TxCustomStore<int>(load: (options) async => txQuery([1, 2], options), byKey: (key) => key == 1 ? 1 : null);
print(await store.load(const TxLoadOptions()));
}