@@ -2,6 +2,8 @@ import 'package:flutter/material.dart';
22import 'package:flutter_localizations/flutter_localizations.dart' ;
33import 'package:form_builder_validators/form_builder_validators.dart' ;
44
5+ import 'home_page.dart' ;
6+
57void main () {
68 runApp (const MyApp ());
79}
@@ -14,78 +16,35 @@ class MyApp extends StatelessWidget {
1416 return MaterialApp (
1517 title: 'Form Builder Validators Demo' ,
1618 theme: ThemeData (primarySwatch: Colors .blue),
17- home: const MyHomePage (),
19+ home: const HomePage (),
1820 supportedLocales: const [
21+ Locale ('ar' ),
1922 Locale ('bn' ),
23+ Locale ('ca' ),
2024 Locale ('de' ),
2125 Locale ('en' ),
2226 Locale ('es' ),
27+ Locale ('et' ),
28+ Locale ('fa' ),
2329 Locale ('fr' ),
30+ Locale ('hu' ),
31+ Locale ('id' ),
2432 Locale ('it' ),
33+ Locale ('ja' ),
34+ Locale ('ko' ),
2535 Locale ('lo' ),
26- Locale ('uk' ),
36+ Locale ('nl' ),
37+ Locale ('ro' ),
2738 Locale ('sw' ),
39+ Locale ('uk' ),
40+ Locale ('zh_Hans' ),
41+ Locale ('zh_Hant' ),
2842 ],
2943 localizationsDelegates: const [
30- GlobalMaterialLocalizations .delegate ,
44+ ... GlobalMaterialLocalizations .delegates ,
3145 GlobalWidgetsLocalizations .delegate,
3246 FormBuilderLocalizations .delegate,
3347 ],
3448 );
3549 }
3650}
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