Loading...
Loading...
Build forms with ShadForm, validation, and form field values; use ShadInputFormField, ShadCheckboxFormField, ShadSelectFormField, ShadDatePickerFormField, etc. Use when building validated forms, getting form values, or using dot notation for nested fields in a Flutter shadcn_ui app.
npx skill4agent add serverpod/skills-registry shadcn_ui-formShadFormMap<String, dynamic>GlobalKey<ShadFormState>saveAndValidate()valueidShad*FormFieldShadInputFormFieldShadCheckboxFormFieldShadSelectFormFieldShadDatePickerFormFieldShadTimePickerFormFieldShadRadioGroupFormFieldShadFormfinal formKey = GlobalKey<ShadFormState>();
ShadForm(
key: formKey,
child: Column(
children: [
ShadInputFormField(
id: 'username',
label: const Text('Username'),
placeholder: const Text('Enter your username'),
description: const Text('This is your public display name.'),
validator: (v) {
if (v.length < 2) return 'Username must be at least 2 characters.';
return null;
},
),
const SizedBox(height: 16),
ShadButton(
child: const Text('Submit'),
onPressed: () {
if (formKey.currentState!.saveAndValidate()) {
print('value: ${formKey.currentState!.value}');
} else {
print('validation failed');
}
},
),
],
),
)ShadButton(
child: const Text('Submit'),
onPressed: () {
final formState = formKey.currentState!;
if (!formState.saveAndValidate()) return;
print('Form value: ${formState.value}');
},
),initialValueShadFormShadForm(
initialValue: {
'username': 'john_doe',
'email': 'john_doe@example.com',
},
child: // form fields with matching ids
)formKey.currentState!.setFieldValue('username', 'new_username');notifyField: falseformKey.currentState!.setValue({...});notifyFields: falsefromValueTransformertoValueTransformerDateTimeShadDatePickerFormField(
id: 'date',
fromValueTransformer: (value) => DateTime.tryParse(value ?? ''),
toValueTransformer: (date) =>
date == null ? null : DateFormat('yyyy-MM-dd').format(date),
...
)user.nameprofile.settings.themeformKey.currentState!.value{'user': {'name': '...', 'email': '...'}}initialValuefieldIdSeparator'/'fieldIdSeparator: null