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

2019-03-19  本文已影响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)),
          ),
        ),
      ],
    );
  }
}

上一篇下一篇

猜你喜欢

热点阅读