Skip to content

Commit 091935a

Browse files
committed
chore(core): improvements to custom fields examples
1 parent a11962e commit 091935a

File tree

4 files changed

+49
-41
lines changed

4 files changed

+49
-41
lines changed

packages/flutter_form_builder/example/lib/main.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class MyApp extends StatelessWidget {
1313
Widget build(BuildContext context) {
1414
return MaterialApp(
1515
title: 'Flutter FormBuilder Demo',
16+
debugShowCheckedModeBanner: false,
1617
theme: ThemeData(
1718
primarySwatch: Colors.blue,
1819
inputDecorationTheme: const InputDecorationTheme(

packages/flutter_form_builder/example/lib/sources/complete_form.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ class CompleteFormState extends State<CompleteForm> {
181181
[FormBuilderValidators.required()]),
182182
items: genderOptions
183183
.map((gender) => DropdownMenuItem(
184+
alignment: AlignmentDirectional.center,
184185
value: gender,
185186
child: Text(gender),
186187
))
@@ -232,7 +233,7 @@ class CompleteFormState extends State<CompleteForm> {
232233
onChanged: _onChanged,
233234
),
234235
FormBuilderSwitch(
235-
title: const Text('I Accept the tems and conditions'),
236+
title: const Text('I Accept the terms and conditions'),
236237
name: 'accept_terms_switch',
237238
initialValue: true,
238239
onChanged: _onChanged,

packages/flutter_form_builder/example/lib/sources/custom_fields.dart

Lines changed: 45 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -21,67 +21,73 @@ class _CustomFieldsState extends State<CustomFields> {
2121
key: _formKey,
2222
child: Column(
2323
children: <Widget>[
24+
const SizedBox(height: 20),
2425
FormBuilderField<String?>(
2526
name: 'name',
26-
onChanged: (val) => debugPrint(val.toString()),
2727
builder: (FormFieldState field) {
28-
return Row(
29-
crossAxisAlignment: CrossAxisAlignment.center,
30-
children: [
31-
const Expanded(child: Text('Name'), flex: 1),
32-
Expanded(
33-
flex: 2,
34-
child: InputDecorator(
35-
decoration: InputDecoration(
36-
errorText: field.errorText,
37-
border: InputBorder.none,
38-
contentPadding: EdgeInsets.zero),
39-
child: CupertinoTextField(
40-
onChanged: (value) => field.didChange(value),
41-
),
42-
),
43-
),
44-
],
28+
return CupertinoTextField(
29+
onChanged: (value) => field.didChange(value),
4530
);
4631
},
47-
autovalidateMode: AutovalidateMode.always,
48-
validator: (valueCandidate) {
49-
if (valueCandidate?.isEmpty ?? true) {
50-
return 'This field is required.';
51-
}
52-
return null;
32+
),
33+
const SizedBox(height: 10),
34+
FormBuilderField<bool>(
35+
name: 'terms',
36+
builder: (FormFieldState field) {
37+
return CheckboxListTile(
38+
title: const Text('I Accept the terms and conditions'),
39+
value: false,
40+
controlAffinity: ListTileControlAffinity.leading,
41+
onChanged: (value) => field.didChange(value),
42+
);
5343
},
5444
),
45+
const SizedBox(height: 10),
5546
FormBuilderField<String?>(
56-
name: "option",
47+
name: 'name',
48+
builder: (FormFieldState field) {
49+
return CupertinoFormRow(
50+
prefix: const Text('Name: '),
51+
error:
52+
field.errorText != null ? Text(field.errorText!) : null,
53+
child: CupertinoTextField(
54+
onChanged: (value) => field.didChange(value),
55+
),
56+
);
57+
},
58+
autovalidateMode: AutovalidateMode.always,
5759
validator: (valueCandidate) {
5860
if (valueCandidate?.isEmpty ?? true) {
5961
return 'This field is required.';
6062
}
6163
return null;
6264
},
63-
builder: (FormFieldState<String?> field) {
65+
),
66+
const SizedBox(height: 10),
67+
FormBuilderField<bool>(
68+
name: 'terms',
69+
builder: (FormFieldState field) {
6470
return InputDecorator(
6571
decoration: InputDecoration(
66-
labelText: "Select option",
67-
contentPadding:
68-
const EdgeInsets.only(top: 10.0, bottom: 0.0),
69-
border: InputBorder.none,
72+
labelText: 'Terms',
7073
errorText: field.errorText,
7174
),
72-
child: SizedBox(
73-
height: 200,
74-
child: CupertinoPicker(
75-
itemExtent: 30,
76-
children: options.map((c) => Text(c)).toList(),
77-
onSelectedItemChanged: (index) {
78-
field.didChange(options[index]);
79-
},
80-
),
75+
child: CheckboxListTile(
76+
title: const Text('I Accept the terms and conditions'),
77+
controlAffinity: ListTileControlAffinity.leading,
78+
value: false,
79+
onChanged: (value) => field.didChange(value),
8180
),
8281
);
8382
},
83+
validator: (valueCandidate) {
84+
if (valueCandidate != true) {
85+
return 'Accept terms and conditions to continue.';
86+
}
87+
return null;
88+
},
8489
),
90+
const SizedBox(height: 10),
8591
Row(
8692
children: <Widget>[
8793
Expanded(

packages/flutter_form_builder/lib/src/fields/form_builder_dropdown.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ class FormBuilderDropdown<T> extends FormBuilderField<T> {
226226
final BorderRadius? borderRadius;
227227

228228
/// Creates field for Dropdown button
229-
FormBuilderDropdown( {
229+
FormBuilderDropdown({
230230
Key? key,
231231
//From Super
232232
required String name,

0 commit comments

Comments
 (0)