t×tecexpressby TeKOcloud
DEv0.7.1
API & types / FLUTTER

TxDataSource.

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

ParameterTypeDefaultMeaning
configTxDataSourceConfig<T>requiredInstance configuration.

TxDataSource.array

ParameterTypeDefaultMeaning
itemsList<T>requiredEntries; replaced by dataSource when bound.
keyOfTxKeyOf<T>?nullReads the stable record key.
paginateboolfalseEnables paging; false loads the whole collection.
Member / type / returnMeaning
TxStore<T> get storeData collection or custom store contract.
List<T> get itemsEntries; replaced by dataSource when bound.
List<TxGroup<T>> groups = []Result group hierarchy.
int totalCount = 0Total filtered record count before paging.
int revision = 0Revision counter after a successful load.
bool? containsKey(Object key)Returns false for known removals, a boolean for an array store, otherwise undefined/null.
int? groupCountTop-level group count before paging.
bool loading = falseShows the loading state.
bool loaded = falseAt least one load completed successfully.
Object? errorMost recent load/write error.
List<TxSort<T>> sortSort descriptors in priority order.
List<TxSort<T>> groupGroup descriptors or group name.
TxFilter<T>? filterFilter expression.
List<TxGetter<T>> searchExprSearch fields or getters.
String searchValueSearch text; local search ignores case.
int pageSizeRecords per page.
int pageIndexZero-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.
dart
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();
}