Flutter——最详细(TextField)使用教程

TextField简介

文本输入框,拥有复杂的属性。可指定控制器、文字样式、装饰线、行数限制、游标样式等。监听输入框变动事件。

使用场景:

搜索框,输入账号密码等

属性作用
controller输入框监听器
decoration输入框装饰属性
textAlign内容对齐方式
textAlignVertical文本垂直对齐
textDirection文字方向
maxLength输入最大长度
cursorColor光标颜色
cursorHeight光标高度
cursorWidth光标宽度
showCursor是否显示光标
onEditingComplete编辑完成
onChanged文本改变时响应
onSubmitted点击确实时响应

InputDecoration属性

属性作用
icon边框左边的图标
iconColor左边图标的颜色
label标签Text()
labelText标签文本内容
labelStyle标签文本样式
helperText左侧底部文本内容
helperStyle左侧底部文本样式
helperMaxLines左侧底部文本最大行数
hintText提示文本内容
hintStyle使用TextStyle修改样式
hintTextDirection提示文本的方向
hintMaxLines提示文本内容最大行数
errorText输入异常提示文本
errorStyle输入异常提示文本样式
errorMaxLines输入异常提示文本最大行数
contentPadding输入内容的内边距
prefixIcon内部左侧图标
prefixIconConstraints内部左侧图标约束大小
prefix内部左侧文本
prefixText内部左侧文本
prefixStyle内部左侧文本样式
prefixIconColor内部左侧图标颜色
suffixIcon内部右侧图标
suffix内部右侧文本
suffixText内部右侧文本
suffixStyle内部右侧文本样式
suffixIconColor内部右侧图标颜色
suffixIconConstraints内部右侧图标约束大小
counter右侧底部文本内容
counterText右侧底部文本内容
counterStyle右侧底部文本内容
enabledBorder禁用之后显示边线
border边线相关
enabled是否禁用

label 属性效果图

在这里插入图片描述

icon 属性效果图
常用于左侧图标展示

在这里插入图片描述

border 属性效果图
输入框边框

在这里插入图片描述

hintText 属性效果图
未点击时文案提示

在这里插入图片描述

counter 属性效果图
在这里插入图片描述
helperText 属性效果图

在这里插入图片描述

prefixIcon 属性效果图

在这里插入图片描述

suffixIcon 属性效果图

在这里插入图片描述

整合部分属性代码块与效果图

TextField(
                controller: _controller,
                style: const TextStyle(color: Colors.blue),
                decoration: const InputDecoration(
                  label: Text("标签label"),
                  icon: Icon(Icons.favorite),
                  iconColor: Colors.black,
                  border: OutlineInputBorder(),
                  hintText: "提示文本hintText",
                  hintStyle: TextStyle(color: Colors.grey, fontSize: 15),
                  contentPadding: EdgeInsets.all(2),
                  counter: Text("提示文本counter"),
                  helperText: "帮助文本helperText",
                  prefixIcon: Icon(Icons.arrow_left),
                  suffixIcon: Icon(Icons.arrow_right),
                  suffix: Text('suffix'),
                ),
                onEditingComplete: () {
                  print('onEditingComplete');
                },
                onChanged: (v) {
                  print('onChanged:' + v);
                },
                onSubmitted: (v) {
                  FocusScope.of(context).requestFocus(_focusNode);
                  print('onSubmitted:' + v);
                  _controller.clear();
                },
              )

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

怀君

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值