美文网首页
Flutter学习笔记(四)-输入框的使用

Flutter学习笔记(四)-输入框的使用

作者: 过往不恋纵情向前 | 来源:发表于2019-03-19 16:57 被阅读0次
    import 'package:flutter/material.dart';
    
    typedef LoginObserver = void Function();
    
    class LoginWidget extends StatefulWidget {
      final LoginObserver loginObserver;
    
      LoginWidget({this.loginObserver});
    
      @override
      _LoginState createState() {
        return _LoginState();
      }
    }
    
    class _LoginState extends State<LoginWidget> {
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(
            title: new Text("登录"),
          ),
          body: Padding(
            padding: EdgeInsets.only(left: 15.0, right: 15.0),
            child: buildTextField(),
          ),
        );
      }
    
      Widget buildTextField() {
        return Column(
          children: <Widget>[
            Container(
              child: TextField(
                decoration:
                    InputDecoration(labelText: "请输入姓名", icon: Icon(Icons.phone)),
                keyboardType: TextInputType.phone,
                obscureText: false,
              ),
              margin: EdgeInsets.only(top: 15.0),
            ),
            Container(
              child: TextField(
                decoration:
                    InputDecoration(labelText: "请输入密码", icon: Icon(Icons.lock)),
                keyboardType: TextInputType.text,
                obscureText: true,
              ),
              margin: EdgeInsets.only(top: 5.0),
            ),
            Container(
              child: Row(
                children: <Widget>[
                  new Expanded(
                      child: RaisedButton(
                          colorBrightness: Brightness.light,
                          textTheme: ButtonTextTheme.primary,
                          onPressed: () => widget.loginObserver(),
                          child: new Text(
                            "登录",
                            style: TextStyle(fontSize: 18.0),
                          )))
                ],
              ),
              margin: EdgeInsets.only(top: 5.0),
            ),
            Expanded(
              child: Container(
                margin: EdgeInsets.only(bottom: 50.0),
                child: Align(
                    child: Text("©1999-2019 北京xxx网络技术有限公司"),
                    alignment: FractionalOffset(0.5, 1.0)),
              ),
            ),
          ],
        );
      }
    }
    
    

    相关文章

      网友评论

          本文标题:Flutter学习笔记(四)-输入框的使用

          本文链接:https://www.haomeiwen.com/subject/bfjnmqtx.html