Flutter 如何更改文本字段';s焦点上的文本标签颜色

Flutter 如何更改文本字段';s焦点上的文本标签颜色,flutter,flutter-layout,Flutter,Flutter Layout,我应该在代码中添加什么才能使TextField的文本标签颜色在焦点上显示为绿色 TextField( keyboardType: TextInputType.emailAddress, cursorColor: CustomColors.seaweed, keyboardAppearance: Brightness.light, autocorrect: false, style: TextStyle( color: Colors.black ), de

我应该在代码中添加什么才能使TextField的文本标签颜色在焦点上显示为绿色

 TextField(
  keyboardType: TextInputType.emailAddress,
  cursorColor: CustomColors.seaweed,
  keyboardAppearance: Brightness.light,
  autocorrect: false,
  style: TextStyle(
      color: Colors.black
  ),
  decoration: InputDecoration(
    fillColor: CustomColors.seaweed,
    hasFloatingPlaceholder: true,
    labelText: "Email",
    hintText: "Please enter email",
    focusedBorder: UnderlineInputBorder(
        borderSide: BorderSide(color: CustomColors.seaweed)
    ),

  ),

)

创建一个
FocusNode
并向其中添加一个侦听器。聚焦后,将标签颜色更改为绿色

class Foo扩展StatefulWidget{
@凌驾
createState()=>\u FooState();
}
类_FooState扩展了状态{
final FocusNode FocusNode=FocusNode();
文本样式标签样式;
@凌驾
void initState(){
super.initState();
addListener(onFocusChange);
}
void onFocusChange(){
设置状态(){
labelStyle=focusNode.hasFocus?文本样式(颜色:Colors.green):空;
});
}
@凌驾
无效处置(){
focusNode.removeListener(onFocusChange);
super.dispose();
}
...
TextField buildTextField(){
返回文本字段(
focusNode:focusNode,
装饰:输入装饰(
labelStyle:labelStyle,
...
),
...
);
}
}