Opening and Closing
A dataset must have data before navigation, editing, filtering, or grid binding becomes useful. The loading entry point depends on whether the dataset owns rows locally or reads them through an adapter.
Adapter-backed datasets
Use open() when the dataset has an adapter:
final customers = FdcDataSet(
fields: customerFields,
adapter: adapter,
);
await customers.open();
open() is the lifecycle entry point for adapter-backed data. The dataset coordinates loading, query state, paging when enabled, cursor initialization, and lifecycle callbacks.
Local datasets
A dataset without an adapter owns its rows directly. Load rows with loadRows():
final customers = FdcDataSet(fields: customerFields);
customers.loadRows([
{'id': 1, 'name': 'Ada'},
{'id': 2, 'name': 'Grace'},
]);
Do not call open() on an adapter-less dataset. open() requires an adapter; local datasets use loadRows().
Closing a dataset
Close the dataset when its current data lifecycle is finished:
customers.close();
Closing clears loaded data and resets dataset state. The FdcDataSet object itself may still be reused and opened or loaded again later.
Lifecycle callbacks
Use typed lifecycle callbacks when application logic must react around open and close operations:
final customers = FdcDataSet(
fields: customerFields,
adapter: adapter,
beforeOpen: (dataSet) {
// Prepare application state before loading begins.
},
afterOpen: (dataSet) {
// React to the loaded dataset.
},
beforeClose: (dataSet) {
// Resolve application-specific close policy.
},
afterClose: (dataSet) {
// React after dataset state has been cleared.
},
);
Prefer these typed callbacks over a generic ChangeNotifier listener when business logic depends on a specific lifecycle event.