[英]Align labelText of TextField when focused
labelText 屬性https://api.flutter.dev/flutter/material/InputDecoration/labelText.html向上移動,當文本字段被聚焦並且你有一個 Inputdecoration 時:
InputDecoration(
labelText: labelText,
filled: true,
enabledBorder: OutlineInputBorder(
borderSide: const BorderSide(
color: ImpexColors.grey,
width: 1.0,
),
),
focusedBorder: OutlineInputBorder(
borderSide: const BorderSide(
color: ImpexColors.secondaryColor,
width: 2.0,
),
),
labelStyle: TextStyle(
color: ImpexColors.blue,
),
)
然后在上邊框的中間對齊。 當 TextField 聚焦時,是否有可能更改 labelText 的 position?
有可能嗎,基達?
FocusNode myFocusNode = FocusNode();
...
TextFormField(
focusNode: myFocusNode,
decoration: InputDecoration(
labelStyle: TextStyle(
height: myFocusNode.hasFocus ? 0.1 : 1, // 0,1 - label will sit on top of border
),
labelText: labelText,
...
));
還必須添加:
onTap: () => setState(() {FocusScope.of(context).requestFocus(myFocusNode);})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.