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

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 {
  @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: [
        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: [
              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学习笔记(四)-输入框的使用)