zoukankan      html  css  js  c++  java
  • Flutter——TextField组件(文本框组件)

    TextField组件的常用属性:

    属性 描述
    maxLines
    设置此参数可以把文本框改为多行文本框
    onChanged
    文本框改变的时候触发的事件
    decoration
    hintText 类似 html 中的 placeholder
    border 配置文本框边框 OutlineInputBorder 配合使用
    labelText lable 的名称
    labelStyle 配置 lable 的样式
    obscureText
    把文本框框改为密码框
    controller
    controller 结合 TextEditingController()可以配置表单默认显示的内容

    import 'package:flutter/material.dart';
    
    void main() {
      runApp(MaterialApp(
        title: "Form",
        home: MyApp(),
      ));
    }
    
    class MyApp extends StatefulWidget {
      @override
      _MyAppState createState() => _MyAppState();
    }
    
    class _MyAppState extends State<MyApp> {
      var _username = TextEditingController(); //初始化时给表单赋值,需要用这个
      var _password;
    
      @override
      void initState() {
        super.initState();
        _username.text = "初始值";
      }
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(title: Text("Form")),
          body: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              TextField(
                decoration: InputDecoration(
                  hintText: "请输入用户名",
                ),
                controller: _username,
                onChanged: (value) {
                  setState(() {
                    _username.text = value;
                  });
                },
              ),
              SizedBox(height: 10.0),
              TextField(
                obscureText: true,
                decoration: InputDecoration(
                  hintText: "请输入密码",
                  labelText: "123",
                  border: OutlineInputBorder()  // 外部包裹框框
                ),
                onChanged: (value) {
                  setState(() {
                    this._password = value;
                  });
                },
              ),
              SizedBox(height: 10.0),
              Container(
                 double.infinity,
                height: 40,
                child: RaisedButton(
                  child: Text("登录"),
                  onPressed: () {
                    print(this._username);
                    print(this._password);
                  },
                  color: Colors.blue,
                  textColor: Colors.white,
                ),
              )
            ],
          ),
        );
      }
    }
  • 相关阅读:
    pandas常用操作
    python读取文件并写入内容到文件
    《软件工程》学习进度博客13
    01梦断代码读后感1—上帝游戏
    软件工程学习进度博客12
    《软件工程》个人作业5----单词统计
    用户模板和用户场景
    软件工程学习进度博客11
    PHP学习3:简单的流程控制
    《软件工程》个人作业6---找水王
  • 原文地址:https://www.cnblogs.com/chichung/p/12020719.html
Copyright © 2011-2022 走看看