Hi, 我是鱼板伯爵今天要教大家 TextField 这个元件,这可以让使用者用键盘输入文字,教学内容只会撷取片段程序码,建议大家搭配完整程序码来练习。
controller
:TextField控制元件可以取得相关属性keyboardType
:键盘的型态TextInputType.text
(文字)、TextInputType.text
(数字)maxLines
:最大行数onChanged
:当输入有变更时会调用class DeomBaseTextField extends StatelessWidget {
const DeomBaseTextField({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
final TextEditingController myController = new TextEditingController();
return Column(
children: [
TextField(
controller: myController,
keyboardType: TextInputType.text,
maxLines: 4,
onChanged: (String value) {
log("${value}");
},
),
ElevatedButton(
child: Text('送出'),
onPressed: () {
log("${myController.text}");
},
),
],
);
}
}
contentPadding
: 文字间距hintText
: 文字输入框内提示的字hintStyle
: 文字输入框内提示字的风格filled
: 是否使用背景颜色fillColor
: 背景颜色helperText
: 文字输入框外的提示字prefixIcon
: 左边文字输入框的图示suffixIcon
: 右边文字输入框的图示enabledBorder
: 未点击时外框颜色focusedBorder
: 点即时外框颜色border
:外框颜色InputDecoration(
isDense: true,
contentPadding: EdgeInsets.only(left: 15, top: 12, bottom: 12),
hintText: hintText,
hintStyle: TextStyle(
color: Colors.redAccent,
),
filled: true,
fillColor: Colors.tealAccent,
helperText: helperText,
prefixIcon: Icon(Icons.ac_unit),
suffixIcon: Icon(Icons.cabin_rounded),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.amber,
width: 1,
),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.blueAccent,
width: 1,
),
),
border: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.limeAccent,
width: 1,
),
),
);
>>: [烧烤吃到饱-2] 好好吃肉韩式烤肉吃到饱-台中公益店 #中秋节烤肉精选店家
鬼故事 - 我是不是来过这里 Credit: 蜘蛛人 灵感来源:UCCU Hacker 故事开始 小...
本节是以 Golang 上游 1a708bcf1d17171056a42ec1597ca8848c...
昨天了解了Hook的概观之後,今天要利用Hook的规则打造一个客制化的Hook。 以下用React官...
类别 类别(class)在JAVA中是不可缺少的,而且至少会存在一个或一个以上。主要是让程序语言能更...
yo, what's up Semigroup II 多组 Semigroup 进形合并 到目前为止...