【问题标题】:Rounded corner Textfiled without border color无边框颜色的圆角文本字段
【发布时间】:2025-12-10 13:50:01
【问题描述】:

我需要一个圆角TextField,我可以这样做,但它显示的是默认边框颜色。我尝试更改borderSide,但无法更改颜色(仍然是黑色):

       TextFormField(
                decoration: InputDecoration(
                    prefixIcon: Icon(
                      Icons.person,
                      color: Colors.white,
                    ),
                    border: OutlineInputBorder(
                      // width: 0.0 produces a thin "hairline" border
                      borderRadius: BorderRadius.all(Radius.circular(90.0)),
                      borderSide: BorderSide(color: Colors.white24)
                      //borderSide: const BorderSide(),
                    ),

                    hintStyle: TextStyle(color: Colors.white,fontFamily: "WorkSansLight"),
                    filled: true,
                    fillColor: Colors.white24,
                    hintText: 'Password'),
              ),

我需要这个,我不想要焦点线,但光标应该是白色的。我尝试更改 border 参数中的所有内容,但仍然没有更改。

我想要:

我明白了:

【问题讨论】:

    标签: android text flutter


    【解决方案1】:

    设置:

    borderSide: BorderSide.none,
    

    如:

       TextFormField(
                decoration: InputDecoration(
                    prefixIcon: Icon(
                      Icons.person,
                      color: Colors.white,
                    ),
                    border: OutlineInputBorder(
                      // width: 0.0 produces a thin "hairline" border
                      borderRadius: BorderRadius.all(Radius.circular(90.0)),
                      borderSide: BorderSide.none,
                      //borderSide: const BorderSide(),
                    ),
    
                    hintStyle: TextStyle(color: Colors.white,fontFamily: "WorkSansLight"),
                    filled: true,
                    fillColor: Colors.white24,
                    hintText: 'Password'),
              ),
    

    【讨论】:

      【解决方案2】:

      创建透明边框:

            final border = OutlineInputBorder(
                  borderRadius: BorderRadius.all(Radius.circular(90.0)),
                  borderSide: BorderSide(
                    color: Colors.transparent,
                  )
                  );
      

      另一个选项是使用:

      borderSide: BorderSide.none
      

      并在focusedBorderborder 属性中使用,还添加一个主题来设置光标和提示颜色:

          Theme(
                        data: Theme.of(context).copyWith(
                          cursorColor: Colors.red,
                          hintColor: Colors.transparent,
                        ),
                        child: TextFormField(
                          decoration: InputDecoration(
                              focusedBorder: border,
                              border: border,
                              prefixIcon: Icon(
                                Icons.person,
                                color: Colors.white,
                              ),
                              hintStyle: TextStyle(
                                  color: Colors.white, fontFamily: "WorkSansLight"),
                              filled: true,
                              fillColor: Colors.white24,
                              hintText: 'Password'),
                        ),
                      ),
      

      【讨论】:

      • 仍然显示黑色,cursorColor 未在 TextFormField 中定义,但在焦点上,它正在改变。
      • 对不起,我使用的是高版本的颤振,请检查我的答案是否更新
      • 我应该更改materialApp中的ThemeData吗?
      • 取决于您,如果您希望所有视图都使用相同的主题属性,那么您应该,否则只需更改文本字段的主题。
      • yes :) ,如果您多次使用该文本字段,我建议您创建一个包含文本字段和主题的无状态小部件。