Created
December 1, 2019 03:19
-
-
Save long25vn/8528a4f396034043ae6a86c34b055969 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'package:flutter/material.dart'; | |
| import 'package:validators/validators.dart' as thuvienkiemtra; | |
| void main() { | |
| return runApp(MyApp()); | |
| } | |
| class MyApp extends StatelessWidget { | |
| @override | |
| Widget build(BuildContext context) { | |
| return MaterialApp( | |
| home: MyHomePage(), | |
| ); | |
| } | |
| } | |
| class MyHomePage extends StatefulWidget { | |
| @override | |
| _MyHomePageState createState() => _MyHomePageState(); | |
| } | |
| class _MyHomePageState extends State<MyHomePage> { | |
| final _formKey = GlobalKey<FormState>(); | |
| String email; | |
| String password; | |
| @override | |
| Widget build(BuildContext context) { | |
| return Scaffold( | |
| appBar: AppBar( | |
| title: Text("Example about form"), | |
| ), | |
| body: Center( | |
| child: Column( | |
| children: <Widget>[ | |
| Text("Xin chao moi nguoi"), | |
| Form( | |
| key: _formKey, | |
| child: Column(children: <Widget>[ | |
| Padding( | |
| padding: const EdgeInsets.all(8.0), | |
| child: TextFormField( | |
| decoration: InputDecoration( | |
| hintText: "email", | |
| border: InputBorder.none, | |
| fillColor: Colors.grey[300], | |
| filled: true, | |
| ), | |
| validator: (String value) { | |
| if (!thuvienkiemtra.isEmail(value)) { | |
| return "Email khong hop le"; | |
| } | |
| return null; | |
| }, | |
| onSaved: (String value) { | |
| this.email = value; | |
| }, | |
| ), | |
| ), | |
| Padding( | |
| padding: const EdgeInsets.all(8.0), | |
| child: TextFormField( | |
| decoration: InputDecoration( | |
| hintText: "password", | |
| border: InputBorder.none, | |
| fillColor: Colors.grey[300], | |
| filled: true, | |
| ), | |
| obscureText: true, | |
| validator: (String value) { | |
| if (value.length < 8) { | |
| return "Password khong hop le"; | |
| } | |
| return null; | |
| }, | |
| onSaved: (String value) { | |
| this.password = value; | |
| }, | |
| ), | |
| ), | |
| RaisedButton( | |
| onPressed: () { | |
| if (_formKey.currentState.validate()) { | |
| _formKey.currentState.save(); | |
| print("Email la: " + this.email.toString()); | |
| print("Password la: " + this.password.toString()); | |
| } | |
| }, | |
| child: Text("Kiem tra"), | |
| ) | |
| ],), | |
| ) | |
| ], | |
| ), | |
| ) | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment