参数详解
TextField同时也使用Text 的部分属性:

属性 作用
controller 控制器,如同 Android View id
decoration 输入器装饰
keyboardType
输入的类型

- TextInputType.text(普通完整键盘)

- TextInputType.number(数字键盘)

- TextInputType.emailAddress(带有“@”的普通键盘)

- TextInputType.datetime(带有“/”和“:”的数字键盘)

- TextInputType.multiline(带有选项以启用有符号和十进制模式的数字键盘)

- TextInputType.url

obscureText 是否隐藏输入(密码设置为true)
onChanged 监听  文字改变触发
onSubmitted 监听  键盘提交
cursorWidth 光标显示宽度
cursorRadius 光标显示圆角
cursorColor 光标显示颜色
autofocus 是否自动聚焦,默认是 false。
textCapitalization
用户输入的类型

- TextCapitalization.none 无
- TextCapitalization.sentences 首句大写
- TextCapitalization.characters 所有字符大写
- TextCapitalization.word 每个单词首字母大写

enabled 是否禁用。如果是 false 不聚焦
inputFormatters 官方提供了三种校验方法,分别是
WhitelistingTextInputFormatter(RegExp("[a-z]")) 白名单校验,也就是只允许输入符合规则的字符
BlacklistingTextInputFormatter(RegExp("[a-z]")) 黑名单校验,除了规定的字符其他的都可以输入
LengthLimitingTextInputFormatter(number) 长度限制,跟 maxLength 作用类似

代码示例
body: new ListView(
children: <Widget>[
TextField(
decoration: new InputDecoration(hintText: "This is a hint",helperText: '官方表单Demo'),
),
TextField(
keyboardType: TextInputType.number,
decoration: new InputDecoration(
labelText: '数字优先的文本框',
),
),
TextField(
decoration: new InputDecoration(
icon: Icon(Icons.phone),//添加一个图标
labelText: '请输入你的用户名',
helperText: '带图标和Label的文本输入框',
),
),
TextField(
decoration: new InputDecoration(
icon: Icon(Icons.lock),//添加一个图标
labelText: '请输入密码',
helperText: '带图标和Label的密码输入框',
),
obscureText: true, //是否隐藏输入
),

//--------------------------------模拟登陆---------------------------
Text('模拟登陆',style: TextStyle(fontSize: 20,height: 3,fontWeight: FontWeight.bold),textAlign: TextAlign.center,),
TextField(
controller: userController, //控制器,控制TextField文字 同 Android View id
decoration: new InputDecoration(
icon: Icon(Icons.phone),//添加一个图标
labelText: '请输入你的用户名',
),
autofocus: false,
),
TextField(
controller: passController,
decoration: new InputDecoration(
icon: Icon(Icons.lock),//添加一个图标
labelText: '请输入密码',
),
obscureText: true, //
),
new Container(
width: 340.0,
padding: new EdgeInsets.all(20),
child: new Card(
color: Colors.blue,
elevation: 16.0,
child: new FlatButton(
child: new Padding(
padding: new EdgeInsets.all(10.0),
child: new Text(
'登 录',
style: new TextStyle(
color: Colors.white, fontSize: 16.0),
),
),
onPressed: _login
)
)
),

],
)

//登陆校验
void _login() {
print({'用户名': userController.text, '密码': passController.text});
if(userController.text.isEmpty){
myDialog('请输入用户名!');
}else if(passController.text.isEmpty){
myDialog('请输入密码!');
}else if(userController.text == 'mzw' && passController.text == '123'){
myDialog('登陆成功!');
userController.clear();
passController.clear();
}else {
myDialog('用户密码错误!');
}
}

//对话框
void myDialog(String msg){
print(myContext);
showDialog(
context: myContext,
barrierDismissible: false,
child: new AlertDialog(
title: new Text(
'温馨提示',
style: new TextStyle(
color: Colors.black54,
fontSize: 18.0,
),
),
content: new Text(msg),
actions: <Widget>[
new FlatButton(
onPressed: () {
Navigator.pop(myContext);
},
child: new Text('确定')),
],
),
);
}

TextField(
decoration: new InputDecoration(
labelText: '带边框的文本输入眶',
border: OutlineInputBorder(http://www.amjmh.com),
),
),
TextField(
maxLines: 10,
minLines: 5,
decoration: new InputDecoration(
labelText: '多行文本输入框',
border: OutlineInputBorder(),
),
),

效果图
             
————————————————

Flutter文本框TextField的更多相关文章

  1. EXT学习之——Extjs 文本框 TextField 添加点击(onclick)事件方法

    { xtype:'textfield', listeners: { render: function(p) { // Append the Panel to the click handler's a ...

  2. Flutter学习笔记(21)--TextField文本框组件和Card卡片组件

    如需转载,请注明出处:Flutter学习笔记(21)--TextField文本框组件和Card卡片组件 今天来学习下TextField文本框组件和Card卡片组件. 只要是应用程序就少不了交互,基本上 ...

  3. Flutter——TextField组件(文本框组件)

    TextField组件的常用属性: 属性 描述 maxLines 设置此参数可以把文本框改为多行文本框 onChanged 文本框改变的时候触发的事件 decoration hintText 类似 h ...

  4. 24Flutter中常见的表单有TextField单行文本框,TextField多行文本框、CheckBox、Radio、Switch

    一.Flutter常用表单介绍: CheckboxListTile.RadioListTile.SwitchListTile.Slide. 二.TextField:表单常见属性: maxLines:设 ...

  5. TextField文本框

    1)失去第一响应者状态方法(即关闭键盘) 要先将视图view的底层类设置为UIControl类 再设置view的touch down事件,在事件中写入以下方法 [self.textField resi ...

  6. 无废话ExtJs 入门教程五[文本框:TextField]

    无废话ExtJs 入门教程五[文本框:TextField] extjs技术交流,欢迎加群(201926085) 继上一节内容,我们在表单里加了个两个文本框.如下所示代码区的第42行位置,items: ...

  7. Flutter控制某个TextField获取焦点及失去焦点

    在项目中有时需要点击某个地方的时候让一个文本框获取焦点以弹起键盘~~比如前端经常使用的input.focus(),但是在flutter中没有.focus()这个方法~~不过我们可以通过FocusSco ...

  8. UITextField常用属性归纳:文本框样式、文字样式、键盘样式、左右视图样式、清除按钮设置等

    (1)可以根据需要设置文本框的样式(包括形状.边框颜色.背景等). (2)可以根据需要设置文字显示样式(包括输入密码时的密文显示.文字横向居中.纵向居中上下.输入的文字是否首席木大写.文字超过后是否缩 ...

  9. 由 s:hidden 引起的文本框内容不能传到 struts的Action中

    <s:form id="startForm" name ="startForm" action="/hall/hall_startList.do ...

随机推荐

  1. 无障碍开发(四)之ARIA aria-***状态值

    aria-***状态值

  2. 精心整理的一些 Python 学习资料

    今天花了些时间给大家精心整理一份 Python 学习资料.我觉得不错的资料我都整理进来了,如果你是学习python的,我觉得这一份资料对你应该有用. 1.知乎上超过 10k 的python相关回答 Y ...

  3. springboot2.0集成webSocket

    WebSocket和http的区别? http协议是用在应用层的协议,他是基于tcp协议的,http协议建立链接也必须要有三次握手才能发送信息. http链接分为短链接,长链接,短链接是每次请求都要三 ...

  4. /etc/ld.so.conf.d/目录下文件的作用

    在了解/etc/ld.so.conf.d/目录下文件的作用之前,先介绍下程序运行是加载动态库的几种方法: 第一种,通过ldconfig命令     ldconfig命令的用途, 主要是在默认搜寻目录( ...

  5. Cowrie蜜罐部署教程

      0.蜜罐分类: 低交互:模拟服务和漏洞以便收集信息和恶意软件,但是攻击者无法和该系统进行交互: 中等交互:在一个特有的控制环境中模拟一个生产服务,允许攻击者的部分交互: 高交互:攻击者可以几乎自由 ...

  6. C获取数组长度

    c语言中,定义数组后可以用sizeof命令获得数组的长度(可容纳元素个数) 如: { int data[4]; int length; length=sizeof(data)/sizeof(data[ ...

  7. 基于partition的递归

    partition算法可以应用在快速排序算法中,也可以应用到 Selection algorithm(在无序数组中寻找第K大的值) Partition 实现 快速排序中用到的 partition 算法 ...

  8. Linux配置JDK环境

    wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-co ...

  9. Elasticsearch索引操作

    一.索引初始化操作 插件推荐使用head.marvel (收费) 1.1 创建新索引 curl -XPUT 'http://localhost:9200/test' -d ' { "sett ...

  10. mysql.sock丢失问题

    执行下面命令即可 /usr/local/bin/mysqld_safe 摘录于:https://blog.csdn.net/qq_20008173/article/details/87280834