/**
const TextField({
Key key,
this.controller,//控制器,TextField的相关信息存储在里面
this.focusNode,
this.decoration = const InputDecoration(),//输入器装饰
TextInputType keyboardType, //弹出键盘的类型
this.textInputAction,//更改TextField的textInputAction可以更改键盘右下角的操作按钮,搜索,完成
this.textCapitalization = TextCapitalization.none,//户输入中的字母大写的选项,TextCapitalization.sentences每个句子的首字母大写,TextCapitalization.characters:句子中的所有字符都大写,TextCapitalization.words : 将每个单词的首字母大写。
this.style,
this.textAlign = TextAlign.start, //文字显示位置
this.autofocus = false,//自动获取焦点
this.obscureText = false,//是否隐藏输入,true密码样式显示,false明文显示
this.autocorrect = true,
this.maxLines = 1,//编辑框最多显示行数
this.maxLength,//输入最大长度,并且默认情况下会将计数器添加到TextField
this.maxLengthEnforced = true,
this.onChanged, //输入监听
this.onEditingComplete,//当用户提交时调用
this.onSubmitted, //文字提交触发(键盘按键)
this.inputFormatters,
this.enabled,
this.cursorWidth = 2.0,//更改光标宽度
this.cursorRadius,//更改光标半径
this.cursorColor,//更改光标颜色
this.keyboardAppearance,
this.scrollPadding = const EdgeInsets.all(20.0),
}) : assert(textAlign != null),
assert(autofocus != null),
assert(obscureText != null),
assert(autocorrect != null),
assert(maxLengthEnforced != null),
assert(scrollPadding != null),
assert(maxLines == null || maxLines > 0),
assert(maxLength == null || maxLength > 0),
keyboardType = keyboardType ?? (maxLines == 1 ? TextInputType.text : TextInputType.multiline),
super(key: key);
*/
/**
const InputDecoration({
this.icon,
this.labelText,//Material Design风格的输入提示
this.labelStyle,//设置labeltext的样式
this.helperText,//显示在输入的下面
this.helperStyle,
this.hintText,//普通的输入提示
this.hintStyle,
this.errorText,//显示在输入的下面,输入框会变成红色
this.errorStyle,
this.errorMaxLines,//错误提示最多显示的行数
this.isDense,
this.contentPadding,//显示内容的padding
this.prefixIcon,//输入框内侧左面的Icon
this.prefix,//输入框内侧左面的Widget
this.prefixText,//输入框内侧左面的Text
this.prefixStyle,//设置prefixText的样式
this.suffixIcon,//输入框内侧右面的Icon
this.suffix,//输入框内侧右面的Widget
this.suffixText,//输入框内侧右面的Text
this.suffixStyle,//设置suffixText的样式
this.counterText,//输入框右下角的计数器文本
this.counterStyle,
this.filled,//是否显示输入框背景色,true显示,false不显示
this.fillColor,
this.errorBorder,
this.focusedBorder,
this.focusedErrorBorder,
this.disabledBorder,
this.enabledBorder,
this.border,//InputBorder.none没有边框,UnderlineInputBorder下边框,OutlineInputBorder四周都有边框
this.enabled = true,
this.semanticCounterText,
}) : assert(enabled != null),
assert(!(prefix != null && prefixText != null), 'Declaring both prefix and prefixText is not allowed'),
assert(!(suffix != null && suffixText != null), 'Declaring both suffix and suffixText is not allowed'),
isCollapsed = false;
*/
body: ListView(
padding: EdgeInsets.all(10.0),
children: [
TextField(
decoration: InputDecoration(
contentPadding: EdgeInsets.all(5.0),
labelText: "labelText",
),
),
TextField(
decoration: InputDecoration(
helperText: "helperText",
),
),
TextField(
decoration: InputDecoration(
labelText: "更改光标颜色、宽度、半径",
),
cursorColor: Color(0xffff0000),
cursorWidth: 4.0,
cursorRadius: Radius.circular(2.0),
),
TextField(
decoration: InputDecoration(
labelText: "enabled: false 编辑框不可用",
),
enabled: false,
),
TextField(
decoration: InputDecoration(
labelText: "textInputAction",
),
textInputAction: TextInputAction.newline
),
TextField(
decoration: InputDecoration(
labelText: "onChanged输入监听,onEditingComplete当用户提交时调用,onSubmitted文字提交触发(键盘按键),controller编辑框的相关信息存储在里面",
),
textInputAction: TextInputAction.go,
onChanged: (text) => print("onChanged:$text"),
onSubmitted: (text) => print("onSubmitted:$text"),
onEditingComplete: () =>
print("onEditingComplete:${controller.text.toString()}"),
controller: controller
),
TextField(
decoration: InputDecoration(
labelText: "maxLength 编辑框最多输入字数,maxLengthEnforced:true时,只能输入限制字数;maxLengthEnforced:false达到最大限制输入数仍然可以输入,这时labelText和计数器会变成红色,提示超出限制",
),
maxLength: 8
),
TextField(
decoration: InputDecoration(
labelText: "maxLength 编辑框最多输入字数,maxLengthEnforced:true时,只能输入限制字数;maxLengthEnforced:false达到最大限制输入数仍然可以输入,这时labelText和计数器会变成红色,提示超出限制",
),
maxLengthEnforced: false,
maxLength: 8
),
TextField(
decoration: InputDecoration(
labelText: "maxLines 编辑框最多显示行数",
),
maxLines: 2,
),
TextField(
decoration: InputDecoration(
labelText: "obscureText 是否隐藏输入,true密码样式显示,false明文显示",
),
obscureText: true
),
TextField(
decoration: InputDecoration(
labelText: "obscureText 是否隐藏输入,true密码样式显示,false明文显示",
),
obscureText: false
),
TextField(
decoration: InputDecoration(
labelText: "autofocus 自动获取焦点",
),
autofocus: true
),
TextField(
decoration: InputDecoration(
labelText: "keyboardType 弹出键盘的类型",
),
keyboardType: TextInputType.number,
),
TextField(
decoration: InputDecoration(
labelText: "labelText是Material Design风格的输入提示,通过labelStyle设置样式",
labelStyle: TextStyle(
color: Color(0xff999999),
fontSize: 12.0
)
),
),
TextField(
decoration: InputDecoration(
hintText: "hintText 普通的输入提示",
hintStyle: TextStyle(
color: Color(0xff999999),
fontSize: 12.0
)
),
),
TextField(
decoration: InputDecoration(
helperText: "helperText 显示在输入的下面",
helperStyle: TextStyle(
color: Color(0xff999999),
fontSize: 12.0
)
),
),
TextField(
decoration: InputDecoration(
errorText: "errorText 显示在输入的下面,输入框会变成红色 显示在输入的下面,输入框会变成红色 显示在输入的下面,输入框会变成红色 显示在输入的下面,输入框会变成红色 显示在输入的下面,输入框会变成红色 显示在输入的下面,输入框会变成红色",
errorStyle: TextStyle(
color: Color(0xffff0000),
fontSize: 12.0
),
errorMaxLines: 2,
),
),
TextField(
decoration: InputDecoration(
labelText: "prefixIcon 输入框内侧左面的Icon",
prefixIcon: Icon(Icons.phone)
),
),
TextField(
decoration: InputDecoration(
labelText: "prefixIcon 输入框内侧左面的prefixText,可以通过prefixStyle设置样式",
prefixText: "手机号",
),
),
TextField(
decoration: InputDecoration(
labelText: "prefix 输入框内侧左面的Widget",
prefix: Text("手机号"),
),
),
TextField(
decoration: InputDecoration(
labelText: "prefix 输入框内侧左面的Widget",
prefix: Icon(Icons.phone),
),
),
TextField(
decoration: InputDecoration(
labelText: "suffix 输入框内侧右面的Widget",
suffix: Icon(Icons.phone),
),
),
TextField(
decoration: InputDecoration(
labelText: "counterText 输入框右下角的计数器文本",
counterText: "0/10",
counterStyle: TextStyle(
color: Color(0xffff0000)
),
),
),
TextField(
decoration: InputDecoration(
labelText: "filled 是否显示输入框背景,true显示,false不显示",
filled: true,
fillColor: Color(0xffff0000),
),
),
Container(
padding: EdgeInsets.all(5.0),
child: TextField(
decoration: InputDecoration(
labelText: "border InputBorder.none没有边框,UnderlineInputBorder下边框,OutlineInputBorder四周都有边框",
border: OutlineInputBorder(
)
),
),
),
],
),
练习demo,链接https://gitee.com/xgljh/Flutter