聚焦时是否可以更改文本字体大小?
此方法不起作用
TextFormField(
focusNode: myFocusNode,
decoration: InputDecoration(
labelText: 'test',
labelStyle: TextStyle(
fontSize: myFocusNode.hasFocus ? 20 : 14
)
),
)
答案 0 :(得分:0)
我从项目中提取了一个小代码示例。如下更改您的TextFormField:
TextFormField(
focusNode: _focusNode,
style: TextStyle(
fontSize: _focusNode.hasFocus ? 30.0: 33.0,
decoration: InputDecoration(
hintText: "Search",
hintStyle: TextStyle(
fontSize:
_focusNode.hasFocus? 30.0: 33.0,
),
autofocus: false,
),
更改您的装饰代码。请在示例代码中注意这一点
style: TextStyle(
fontSize: _focusNode.hasFocus
? 30.0: 33.0,
在这里:
decoration: InputDecoration(
hintText: "Search",
hintStyle: TextStyle(
fontSize:
_focusNode.hasFocus? 30.0: 33.0,
),