Skip to content

Commit 60f38e4

Browse files
update example
1 parent a77e03e commit 60f38e4

File tree

1 file changed

+93
-57
lines changed

1 file changed

+93
-57
lines changed

example/lib/new_api_examples/static_vs_dynamic_value_example_main.dart

Lines changed: 93 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -43,88 +43,124 @@ class _HomePageState extends State<_HomePage> {
4343
@override
4444
Widget build(BuildContext context) {
4545
return Scaffold(
46-
appBar: AppBar(title: const Text('Static vs Dynamic - Example')),
46+
appBar: AppBar(
47+
title: Text(
48+
'Static vs Dynamic - Example (all the fields check if the input is equal to $referenceValue)')),
4749
body: Padding(
4850
padding: const EdgeInsets.all(8),
49-
child: SingleChildScrollView(
50-
child: Column(
51-
children: <Widget>[
52-
Row(
53-
mainAxisAlignment: MainAxisAlignment.center,
54-
children: <Widget>[
55-
IconButton(
56-
onPressed: () => setState(() {
57-
referenceValue--;
58-
}),
59-
icon: const Icon(Icons.remove)),
60-
Text(referenceValue.toString()),
61-
IconButton(
62-
onPressed: () => setState(() {
63-
referenceValue++;
64-
}),
65-
icon: const Icon(Icons.add)),
66-
],
67-
),
68-
const SizedBox(height: 16),
69-
const Text('With flutter form fields:'),
70-
const SizedBox(height: 8),
71-
TextFormField(
72-
decoration:
73-
const InputDecoration(labelText: 'isEqual (static)'),
74-
autovalidateMode: AutovalidateMode.always,
75-
validator: isRequired(isInt(isEqual(referenceValue))),
76-
),
77-
const SizedBox(height: 8),
78-
TextFormField(
79-
decoration:
80-
const InputDecoration(labelText: 'isEqual (dynamic)'),
81-
autovalidateMode: AutovalidateMode.always,
82-
validator: isRequired(
83-
isInt(isEqual(null, dynValue: () => referenceValue))),
84-
),
85-
const SizedBox(height: 8),
86-
TextFormField(
87-
decoration:
88-
const InputDecoration(labelText: 'isEqual (old API)'),
89-
autovalidateMode: AutovalidateMode.always,
90-
validator:
91-
FormBuilderValidators.equal(referenceValue.toString()),
92-
),
93-
const SizedBox(height: 16),
94-
const Text('With flutter_form_builder:'),
95-
const SizedBox(height: 8),
96-
FormBuilder(
97-
key: _formKey,
98-
autovalidateMode: AutovalidateMode.always,
51+
child: Column(
52+
children: <Widget>[
53+
Row(
54+
mainAxisAlignment: MainAxisAlignment.center,
55+
children: <Widget>[
56+
IconButton(
57+
onPressed: () => setState(() {
58+
referenceValue--;
59+
}),
60+
icon: const Icon(Icons.remove)),
61+
Text(referenceValue.toString()),
62+
IconButton(
63+
onPressed: () => setState(() {
64+
referenceValue++;
65+
}),
66+
icon: const Icon(Icons.add)),
67+
],
68+
),
69+
const SizedBox(height: 8),
70+
Expanded(
71+
child: SingleChildScrollView(
9972
child: Column(
100-
children: <Widget>[
73+
children: [
74+
const Text('With flutter TextFormField:'),
75+
TextFormField(
76+
decoration:
77+
const InputDecoration(labelText: 'isEqual (static)'),
78+
autovalidateMode: AutovalidateMode.always,
79+
validator: isRequired(isInt(isEqual(referenceValue))),
80+
),
81+
const SizedBox(height: 5),
82+
TextFormField(
83+
decoration:
84+
const InputDecoration(labelText: 'isEqual (dynamic)'),
85+
autovalidateMode: AutovalidateMode.always,
86+
validator: isRequired(
87+
isInt(isEqual(null, dynValue: () => referenceValue))),
88+
),
89+
const SizedBox(height: 5),
90+
TextFormField(
91+
decoration:
92+
const InputDecoration(labelText: 'isEqual (old API)'),
93+
autovalidateMode: AutovalidateMode.always,
94+
validator: FormBuilderValidators.equal(
95+
referenceValue.toString()),
96+
),
97+
const SizedBox(height: 8),
98+
const Text(
99+
'With flutter_form_builder outside a FormBuilder:'),
101100
FormBuilderTextField(
102101
name: 'isEqual (static)',
102+
autovalidateMode: AutovalidateMode.always,
103103
decoration:
104104
const InputDecoration(labelText: 'isEqual (static)'),
105105
validator: isRequired(isInt(isEqual(referenceValue))),
106106
),
107-
const SizedBox(height: 8),
107+
const SizedBox(height: 5),
108108
FormBuilderTextField(
109109
name: 'isEqual (dynamic)',
110+
autovalidateMode: AutovalidateMode.always,
110111
decoration:
111112
const InputDecoration(labelText: 'isEqual (dynamic)'),
112113
validator: isRequired(
113114
isInt(isEqual(null, dynValue: () => referenceValue))),
114115
),
115-
const SizedBox(height: 8),
116+
const SizedBox(height: 5),
116117
FormBuilderTextField(
117118
name: 'isEqual (old API)',
119+
autovalidateMode: AutovalidateMode.always,
118120
decoration:
119121
const InputDecoration(labelText: 'isEqual (old API)'),
120122
validator: FormBuilderValidators.equal(
121123
referenceValue.toString()),
122124
),
125+
const SizedBox(height: 8),
126+
const Text(
127+
'With flutter_form_builder inside a FormBuilder:'),
128+
FormBuilder(
129+
key: _formKey,
130+
autovalidateMode: AutovalidateMode.always,
131+
child: Column(
132+
children: <Widget>[
133+
FormBuilderTextField(
134+
name: 'isEqual (static)',
135+
decoration: const InputDecoration(
136+
labelText: 'isEqual (static)'),
137+
validator:
138+
isRequired(isInt(isEqual(referenceValue))),
139+
),
140+
const SizedBox(height: 5),
141+
FormBuilderTextField(
142+
name: 'isEqual (dynamic)',
143+
decoration: const InputDecoration(
144+
labelText: 'isEqual (dynamic)'),
145+
validator: isRequired(isInt(
146+
isEqual(null, dynValue: () => referenceValue))),
147+
),
148+
const SizedBox(height: 5),
149+
FormBuilderTextField(
150+
name: 'isEqual (old API)',
151+
decoration: const InputDecoration(
152+
labelText: 'isEqual (old API)'),
153+
validator: FormBuilderValidators.equal(
154+
referenceValue.toString()),
155+
),
156+
],
157+
),
158+
)
123159
],
124160
),
125-
)
126-
],
127-
),
161+
),
162+
),
163+
],
128164
),
129165
),
130166
);

0 commit comments

Comments
 (0)