简体   繁体   English

如何更改文本字段 header 颜色?

[英]How to change textField header color?

How to change "Name" form TextField to Purple when Focus on this i have a problem here that i try to solve this but it's not work关注此问题时如何将“名称”表单文本字段更改为紫色我在这里遇到问题,我尝试解决此问题但它不起作用

在此处输入图像描述

here is my code这是我的代码

class NewName extends StatefulWidget {
  @override
  _NewNomeState createState() => _NewNomeState();
}

class _NewNomeState extends State<NewName> {
  @override
  Widget build(BuildContext context) {
    FocusNode myFocusNode = new FocusNode();
    return Padding(
      padding: const EdgeInsets.only(top: 0, left: 50, right: 50),
      child: Container(
        height: 60,
        width: MediaQuery.of(context).size.width,
        child: TextField(
          focusNode: myFocusNode,
          style: TextStyle(
            color: Colors.purple,
          ),
          decoration: InputDecoration(
            enabledBorder: UnderlineInputBorder(
              borderSide: BorderSide(color: Colors.black),
            ),
            focusedBorder: UnderlineInputBorder(
              borderSide: BorderSide(color: Colors.purple),
            ),
            border: UnderlineInputBorder(
              borderSide: BorderSide(color: Colors.purple),
            ),
            labelText: 'Name',
            labelStyle: TextStyle(
                fontFamily: 'SukumvitSetSemiBold',
                fontSize: 14,
                color: myFocusNode.hasFocus ? Colors.purple : Colors.black),
          ),
        ),
      ),
    );
  }

}

i have seen some Question that similar but i still don't know how to fixed it.我见过一些类似的问题,但我仍然不知道如何解决它。 i'm too confuse here please help #Thank you very much我在这里太困惑了请帮助#非常感谢

Well first you should declare your focusNode outside the build function, try moving FocusNode myFocusNode = new FocusNode();首先你应该在构建 function 之外声明你的 focusNode,尝试移动FocusNode myFocusNode = new FocusNode(); outside of Build(BuildContext context) and check if that solved it.Build(BuildContext context)之外并检查是否解决了它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM