A user login page
Input validation
import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; void main() { debugPaintSizeEnabled = false; runApp(new LoginAlertDemoApp()); } class LoginAlertDemoApp extends StatelessWidget { @override Widget build(BuildContext context) { return new MaterialApp( theme: new ThemeData( primarySwatch: Colors.green, ), home: Scaffold( body: new LoginHomePage(), )); } } class LoginHomePage extends StatefulWidget { @override _LoginHomePageState createState() { // TODO: implement createState return new _LoginHomePageState(); } } class _LoginHomePageState extends State<LoginHomePage> { @override Widget build(BuildContext context) { return Stack( children: <Widget>[ Column( mainAxisSize: MainAxisSize.max, crossAxisAlignment: CrossAxisAlignment center, the children: "Widget > [Container (height: 120.0, alignment, alignment centerLeft, padding: EdgeInsets. Only (left:30.0), color: color.white, child: Icon(Icons. Access_alarm),), Container(color: Color.white, alignment.center, padding: EdgeInsets. Only (left:30.0,right: 30.0), child: new Container( child: buildForm(), ), ), ], ), ], ); } TextEditingController unameController = new TextEditingController(); TextEditingController pwdController = new TextEditingController(); GlobalKey formKey = new GlobalKey<FormState>(); Widget buildForm() {return Form(// Set globalKey for FormState key: formKey, // enable autovalidate: true, child: Column( children: <Widget>[ TextFormField( autofocus: false, keyboardType: TextInputAction: TextinputAction. next, Controller: unameController, decoration: InputDecoration(labelText: "user name ", hintText:" user name ", icon: icon (Icons. Person)), // Validate user name validator: (v) {return v.rim ().length > 0? Null: "username cannot be empty ";}), TextFormField(autofocus: false, Controller: PwdController, decoration: InputDecoration(labelText: "password ", hintText:" your login password ", icon: icon (Icons. Lock)), obscureText: {return v.rim ().length > 5? Null: "Password must not be less than 6 characters ";}), // Login button Padding(Padding: Const EdgeInsets. Only (top: 28.0), child: Row(children: <Widget>[Expanded(child: RaisedButton(padding: EdgeInsets. All (15.0), Child: Text(" login "), color: Theme. Of (context). PrimaryColor, textColor: colors.white, onPressed: //print(form.of (context)); // After _formkey.currentState is used to obtain FormState, // call validate() to verify that the user name and password are valid. If ((formKey. CurrentState as FormState). The validate ()) {/ / verification by submitting data}},),),),),),),); }}Copy the code