@@ -2,6 +2,8 @@ import 'package:flutter/material.dart';
2
2
import 'package:flutter_localizations/flutter_localizations.dart' ;
3
3
import 'package:form_builder_validators/form_builder_validators.dart' ;
4
4
5
+ import 'home_page.dart' ;
6
+
5
7
void main () {
6
8
runApp (const MyApp ());
7
9
}
@@ -14,78 +16,35 @@ class MyApp extends StatelessWidget {
14
16
return MaterialApp (
15
17
title: 'Form Builder Validators Demo' ,
16
18
theme: ThemeData (primarySwatch: Colors .blue),
17
- home: const MyHomePage (),
19
+ home: const HomePage (),
18
20
supportedLocales: const [
21
+ Locale ('ar' ),
19
22
Locale ('bn' ),
23
+ Locale ('ca' ),
20
24
Locale ('de' ),
21
25
Locale ('en' ),
22
26
Locale ('es' ),
27
+ Locale ('et' ),
28
+ Locale ('fa' ),
23
29
Locale ('fr' ),
30
+ Locale ('hu' ),
31
+ Locale ('id' ),
24
32
Locale ('it' ),
33
+ Locale ('ja' ),
34
+ Locale ('ko' ),
25
35
Locale ('lo' ),
26
- Locale ('uk' ),
36
+ Locale ('nl' ),
37
+ Locale ('ro' ),
27
38
Locale ('sw' ),
39
+ Locale ('uk' ),
40
+ Locale ('zh_Hans' ),
41
+ Locale ('zh_Hant' ),
28
42
],
29
43
localizationsDelegates: const [
30
- GlobalMaterialLocalizations .delegate ,
44
+ ... GlobalMaterialLocalizations .delegates ,
31
45
GlobalWidgetsLocalizations .delegate,
32
46
FormBuilderLocalizations .delegate,
33
47
],
34
48
);
35
49
}
36
50
}
37
-
38
- class MyHomePage extends StatefulWidget {
39
- const MyHomePage ({Key key}) : super (key: key);
40
-
41
- @override
42
- _MyHomePageState createState () => _MyHomePageState ();
43
- }
44
-
45
- class _MyHomePageState extends State <MyHomePage > {
46
- @override
47
- Widget build (BuildContext context) {
48
- return Scaffold (
49
- appBar: AppBar (title: const Text ('Form Builder Validators' )),
50
- body: Padding (
51
- padding: const EdgeInsets .all (8.0 ),
52
- child: Column (
53
- children: < Widget > [
54
- TextFormField (
55
- decoration: const InputDecoration (labelText: 'Name' ),
56
- validator: FormBuilderValidators .required (),
57
- autovalidateMode: AutovalidateMode .always,
58
- ),
59
-
60
- // Composing multiple validators
61
- TextFormField (
62
- decoration: const InputDecoration (labelText: 'Age' ),
63
- keyboardType: TextInputType .number,
64
- autovalidateMode: AutovalidateMode .always,
65
- validator: FormBuilderValidators .compose ([
66
- /// Makes this field required
67
- FormBuilderValidators .required (),
68
-
69
- /// Ensures the value entered is numeric - with custom error message
70
- FormBuilderValidators .numeric (
71
- errorText: 'La edad debe ser numérica.' ),
72
-
73
- /// Sets a maximum value of 70
74
- FormBuilderValidators .max (70 ),
75
-
76
- /// Include your own custom `FormFieldValidator` function, if you want
77
- /// Ensures positive values only. We could also have used `FormBuilderValidators.min( 0)` instead
78
- (val) {
79
- final number = int .tryParse (val);
80
- if (number == null ) return null ;
81
- if (number < 0 ) return 'We cannot have a negative age' ;
82
- return null ;
83
- }
84
- ]),
85
- ),
86
- ],
87
- ),
88
- ),
89
- );
90
- }
91
- }
0 commit comments