Validate business data
FDC validation is dataset-centered, so the same rules apply whether data is changed from a grid, a standalone editor, or application code.
Put required rules in the schema
FdcStringField(
name: 'company',
label: 'Company',
required: true,
)
Put single-field rules on the field
FdcStringField(
name: 'state',
label: 'State',
validator: (row, value) {
final text = value as String?;
if (text != null && text.length != 2) {
return 'Use a two-letter state code.';
}
return null;
},
)
Put cross-field rules on the dataset
final bookings = FdcDataSet(
fields: fields,
recordValidator: (row) {
final start = row['start_date'] as DateTime?;
final end = row['end_date'] as DateTime?;
if (start != null && end != null && end.isBefore(start)) {
return const [
FdcValidationError(
message: 'End date must not be before start date.',
fieldName: 'end_date',
),
];
}
return const [];
},
);
Surface validation consistently
Use onValidationError when the screen needs centralized feedback handling, such as a message area or notification service.
Keep field-specific feedback attached to the field whenever possible so a grid or editor can direct the user to the correct input.
Avoid duplicating UI-only rules
Do not implement one validation rule in a grid callback and another copy in a form validator. Put business validity in the dataset schema and record validator, then let every data-aware UI share it.
See Validation and Editing Lifecycle.