@@ -45,6 +45,7 @@ class MyHomePageState extends State<MyHomePage> {
45
45
final ValueChanged _onChanged = (val) => print (val);
46
46
var genderOptions = ['Male' , 'Female' , 'Other' ];
47
47
final _ageController = TextEditingController (text: '45' );
48
+ bool _ageHasError = false ;
48
49
49
50
@override
50
51
Widget build (BuildContext context) {
@@ -236,7 +237,7 @@ class MyHomePageState extends State<MyHomePage> {
236
237
label: RichText (
237
238
text: TextSpan (
238
239
children: [
239
- TextSpan (text: 'I have read and agree to the ' ),
240
+ TextSpan (text: 'I have read and agree to the ' , style : TextStyle (color : Colors .black) ),
240
241
TextSpan (
241
242
text: 'Terms and Conditions' ,
242
243
style: TextStyle (color: Colors .blue),
@@ -256,26 +257,30 @@ class MyHomePageState extends State<MyHomePage> {
256
257
],
257
258
),
258
259
SizedBox (height: 15 ),
259
- Text (
260
- 'This value is passed along to the [Text.maxLines] attribute of the [Text] widget used to display the hint text.' ,
261
- style: Theme .of (context).inputDecorationTheme.labelStyle,
262
- ),
263
260
FormBuilderTextField (
264
261
attribute: 'age' ,
262
+ // autovalidate: true,
265
263
controller: _ageController,
266
- decoration: const InputDecoration (
267
- labelText:
268
- 'This value is passed along to the [Text.maxLines] attribute of the [Text] widget used to display the hint text.' ,
264
+ decoration: InputDecoration (
265
+ labelText: 'Age' ,
266
+ suffixIcon: _ageHasError ?
267
+ Icon (Icons .error, color: Colors .red)
268
+ : Icon (Icons .check, color: Colors .green),
269
269
),
270
- onChanged: _onChanged,
270
+ onChanged: (val) {
271
+ print (val);
272
+ setState (() {
273
+ _ageHasError = ! _fbKey
274
+ .currentState.fields['age' ].currentState
275
+ .validate ();
276
+ });
277
+ },
271
278
valueTransformer: (text) {
272
279
return text == null ? null : num .tryParse (text);
273
280
},
274
281
validators: [
275
282
FormBuilderValidators .required (),
276
283
FormBuilderValidators .numeric (),
277
- // FormBuilderValidators.max(70),
278
- FormBuilderValidators .minLength (2 , allowEmpty: true ),
279
284
],
280
285
keyboardType: TextInputType .number,
281
286
),
@@ -596,3 +601,5 @@ class MyHomePageState extends State<MyHomePage> {
596
601
);
597
602
}
598
603
}
604
+
605
+
0 commit comments