Observable data source with query state and asynchronous loading. Writes reload the data; its owner disposes the instance.
Default configuration: pageSize 20, pageIndex 0, paginate true; array stores are local, other stores remote. The Vue array shorthand retains paging; Dart TxDataSource.array defaults to paginate false. items starts empty; call load() unless a bound consumer triggers the initial load. Invalid paging is rejected. Replace the store and key by creating a new instance. configure returns a Promise/Future of the reloaded list. byKey returns a Promise/Future of a record or undefined/null; insert/update return the written record and remove returns no value. Vue push returns the new list; Dart push returns no value. cancel/dispose return no value. Load/write failures are also exposed in error. For unsupported operations Vue throws Error and Dart throws UnsupportedError. Loading after disposal fails.
TxDataSource
| Parameter | Type | Default | Meaning |
|---|---|---|---|
| config | TxDataSourceConfig<T> | required | Instance configuration. |
TxDataSource.array
| Parameter | Type | Default | Meaning |
|---|---|---|---|
| items | List<T> | required | Entries; replaced by dataSource when bound. |
| keyOf | TxKeyOf<T>? | null | Reads the stable record key. |
| paginate | bool | false | Enables paging; false loads the whole collection. |
| Member / type / return | Meaning |
|---|---|
TxStore<T> get store | Data collection or custom store contract. |
List<T> get items | Entries; replaced by dataSource when bound. |
List<TxGroup<T>> groups = [] | Result group hierarchy. |
int totalCount = 0 | Total filtered record count before paging. |
int revision = 0 | Revision counter after a successful load. |
bool? containsKey(Object key) | Returns false for known removals, a boolean for an array store, otherwise undefined/null. |
int? groupCount | Top-level group count before paging. |
bool loading = false | Shows the loading state. |
bool loaded = false | At least one load completed successfully. |
Object? error | Most recent load/write error. |
List<TxSort<T>> sort | Sort descriptors in priority order. |
List<TxSort<T>> group | Group descriptors or group name. |
TxFilter<T>? filter | Filter expression. |
List<TxGetter<T>> searchExpr | Search fields or getters. |
String searchValue | Search text; local search ignores case. |
int pageSize | Records per page. |
int pageIndex | Zero-based page index. |
Future<List<T>> load() | Loads using the supplied options; DataSource uses current query state without arguments. Errors propagate. |
Future<List<T>> reload() | Reloads the current query and returns visible records. |
Future<List<T>> configure({List<TxSort<T>>? sort, TxFilter<T>? filter, bool clearFilter = false, String? searchValue, List<TxGetter<T>>? searchExpr, List<TxSort<T>>? group, int? pageSize, int? pageIndex}) | Changes query options and reloads. Search, filter and page size reset the page unless explicitly supplied. |
void cancel() | Set synchronously to true to cancel the action. |
Future<T?> byKey(Object key) | Reads a record by key; missing keys return undefined (Vue) or null (Dart). |
Future<T> insert(T item) | Inserts a record with a unique key and returns it. |
Future<T> update(Object key, T Function(T) change) | Updates a notification or record. |
Future<void> remove(Object key) | Removes the record or recursively removes a file/directory tree. |
Future<void> push(List<TxPush<T>> changes) | Runs store writes sequentially and reloads once; not a transaction, partial success is possible on error. |
void dispose() | Stops queries and listeners; do not use the instance afterward. |
import 'package:flutter/material.dart';
import 'package:tecexpress/tecexpress.dart';
Future<void> example() async {
final source = TxDataSource.array(<Map<String, Object>>[{'id': 1, 'name': 'One'}], keyOf: (row) => row['id']!);
void listener() => debugPrint('${source.loading}: ${source.error}');
source.addListener(listener);
await source.load();
await source.configure(searchExpr: [(row) => row['name']], searchValue: 'One');
await source.insert({'id': 2, 'name': 'Two'});
await source.update(2, (row) => {...row, 'name': 'Updated'});
await source.push([TxPush.update(2, (row) => {...row, 'name': 'Changed'})]);
print(await source.byKey(1));
print(source.containsKey(1));
await source.remove(2);
await source.reload();
source.cancel();
source.removeListener(listener);
source.dispose();
}