Flutter 一个漂亮的登录页面

登录界面

用了整整一天的时间,终于整出来一个自己满意的登录界面 github地址,分享出来和大家一起学习和进步。

import 'package:flutter/material.dart';

class Login extends StatefulWidget {

  @override

  _Login createState() => new _Login();

}

class _Login extends State<Login> {

  //获取Key用来获取Form表单组件

  GlobalKey<FormState> loginKey = new GlobalKey<FormState>();

  String userName;

  String password;

  bool isShowPassWord = false;

  void login(){

    //读取当前的Form状态

    var loginForm = loginKey.currentState;

    //验证Form表单

    if(loginForm.validate()){

      loginForm.save();

      print('userName: ' + userName + ' password: ' + password);

    }

  }

  void showPassWord() {

    setState(() {

      isShowPassWord = !isShowPassWord;

    });

  }

  @override

  Widget build(BuildContext context){

    return new MaterialApp(

      title: 'Form表单示例',

      home: new Scaffold(

        body: new Column(

          children: <Widget>[

            new Container(

              padding: EdgeInsets.only(top: 100.0, bottom: 10.0),

              child: new Text(

                'LOGO',

                style: TextStyle(

                  color: Color.fromARGB(255, 53, 53, 53),

                  fontSize: 50.0

                ),

              )

            ),

            new Container(

              padding: const EdgeInsets.all(16.0),

              child: new Form(

                key: loginKey,

                autovalidate: true,

                child: new Column(

                  children: <Widget>[

                    new Container(

                      decoration: new BoxDecoration(

                        border: new Border(

                          bottom: BorderSide(

                            color: Color.fromARGB(255, 240, 240, 240),

                            width: 1.0

                          )

                        )

                      ),

                      child: new TextFormField(

                        decoration: new InputDecoration(

                          labelText: '请输入手机号',

                          labelStyle: new TextStyle( fontSize: 15.0, color: Color.fromARGB(255, 93, 93, 93)),

                          border: InputBorder.none,

                          // suffixIcon: new IconButton(

                          //  icon: new Icon(

                          //    Icons.close,

                          //    color: Color.fromARGB(255, 126, 126, 126),

                          //  ),

                          //  onPressed: () {


                          //  },

                          // ),

                        ),

                        keyboardType: TextInputType.phone,

                        onSaved: (value) {

                          userName = value;

                        },

                        validator: (phone) {

                          // if(phone.length == 0){

                          //  return '请输入手机号';

                          // }

                        },

                        onFieldSubmitted: (value) {

                        }, 

                      ),

                    ),

                    new Container(

                      decoration: new BoxDecoration(

                        border: new Border(

                          bottom: BorderSide(

                            color: Color.fromARGB(255, 240, 240, 240),

                            width: 1.0

                          )

                        )

                      ),

                      child: new TextFormField(

                        decoration:  new InputDecoration(

                          labelText: '请输入密码',

                          labelStyle: new TextStyle( fontSize: 15.0, color: Color.fromARGB(255, 93, 93, 93)),

                          border: InputBorder.none,

                          suffixIcon: new IconButton(

                            icon: new Icon(

                              isShowPassWord ? Icons.visibility : Icons.visibility_off,

                              color: Color.fromARGB(255, 126, 126, 126),

                            ),

                            onPressed: showPassWord,

                          )

                        ),

                        obscureText: !isShowPassWord,

                        onSaved: (value) {

                          password = value;

                        },

                      ),

                    ),

                    new Container(

                      height: 45.0,

                      margin: EdgeInsets.only(top: 40.0),

                      child: new SizedBox.expand( 

                        child: new RaisedButton(

                          onPressed: login,

                          color: Color.fromARGB(255, 61, 203, 128),

                          child: new Text(

                            '登录',

                            style: TextStyle(

                              fontSize: 14.0,

                              color: Color.fromARGB(255, 255, 255, 255)

                            ),

                          ),

                          shape: new RoundedRectangleBorder(borderRadius: new BorderRadius.circular(45.0)),

                        ),

                      ), 

                    ),

                    new Container(

                      margin: EdgeInsets.only(top: 30.0),

                      padding: EdgeInsets.only(left: 8.0, right: 8.0),

                      child: new Row(

                        mainAxisAlignment: MainAxisAlignment.spaceBetween,

                        children: <Widget>[

                          new Container(

                            child:  Text(

                              '注册账号',

                              style: TextStyle(

                                fontSize: 13.0,

                                color: Color.fromARGB(255, 53, 53, 53)

                              ),

                            ),


                          ),


                          Text(

                            '忘记密码?',

                            style: TextStyle(

                              fontSize: 13.0,

                              color: Color.fromARGB(255, 53, 53, 53)

                            ),

                          ),

                        ],

                      ) ,

                    ),


                  ],

                ),

              ),

            )

          ],

        ),

      ),

    );

  }

}

最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容