Skip to main content

Data adapters

A data adapter connects FdcDataSet to a source of rows. The dataset owns records, editing state, validation, navigation, and change tracking; the adapter owns loading data and, when supported, applying changes to the source.

final customers = FdcDataSet(
fields: const [
FdcIntegerField(name: 'id', isKey: true),
FdcStringField(name: 'company', size: 120),
FdcStringField(name: 'city', size: 80),
],
adapter: FdcMemoryDataAdapter(
rows: const [
{'id': 1, 'company': 'Northwind Supply', 'city': 'Seattle'},
{'id': 2, 'company': 'Blue Ridge Foods', 'city': 'Denver'},
],
),
);

await customers.open();

Responsibilities

An adapter can provide capabilities such as:

  • filtering;
  • sorting;
  • searching;
  • paging and total counts;
  • aggregates;
  • selected-key filtering;
  • applying inserts, updates, and deletes.

The dataset checks adapter capabilities before issuing backend operations. This lets UI and dataset code remain independent from the physical data source.

Source filters and default sorts

Adapters can define filters that always apply and source-level default ordering:

FdcMemoryDataAdapter(
rows: rows,
filters: const [
FdcDataAdapterFilter(
fieldName: 'active',
operator: FdcDataAdapterFilterOperator.equals,
value: true,
),
],
sorts: const [
FdcDataAdapterSort(
fieldName: 'company',
sortType: FdcSortType.ascending,
),
],
)

Source filters are combined with dataset and grid filters using AND semantics. Clearing UI filters does not remove adapter source filters. Clearing user sorting returns to the adapter's default ordering.

Choosing an adapter

Use FdcMemoryDataAdapter for local rows, tests, demos, and modest client-side datasets. Use SQLite adapters for local database-backed applications. Use FdcJsonAdapter when the application wants full control over transport and backend calls. Use FdcRestAdapter for the same canonical JSON contract with HTTP request handling already modeled.

Custom adapters can implement a specialized source while keeping the same dataset lifecycle.