Skip to main content

Your First DataSet

FdcDataSet is the center of the FD Components programming model. Start by defining a typed schema and loading local rows.

final customers = FdcDataSet(
fields: const <FdcFieldDef>[
FdcIntegerField(
name: 'id',
label: 'ID',
isKey: true,
storage: FdcFieldStorage(updateable: false),
),
FdcStringField(
name: 'company',
label: 'Company',
size: 120,
required: true,
),
FdcDecimalField(
name: 'credit_limit',
label: 'Credit limit',
precision: 12,
scale: 2,
minValue: 0,
),
FdcBooleanField(
name: 'active',
label: 'Active',
defaultValue: true,
),
],
);

await customers.loadRows(<Map<String, Object?>>[
<String, Object?>{
'id': 1,
'company': 'Northstar Analytics',
'credit_limit': 25000,
'active': true,
},
<String, Object?>{
'id': 2,
'company': 'BluePeak Logistics',
'credit_limit': 42000,
'active': true,
},
]);

This is local mode: the dataset owns its rows directly and does not use an adapter. loadRows is the appropriate entry point for this mode.

For external storage, create the dataset with an adapter and call open() instead. The dataset lifecycle remains the same while persistence is delegated through the adapter contract.

Why define fields first?

Field metadata is shared throughout FD Components. The same schema can drive:

  • validation and required-value rules;
  • editing and typed conversion;
  • labels and display behavior;
  • filtering and sorting semantics;
  • grid columns and data-aware editors;
  • adapter storage metadata and keys.

Next: Your First Data Grid