简体   繁体   English

Flutter:未应用 TextField 边框颜色

[英]Flutter: TextField Border Color Not Applied

   decoration: InputDecoration(
                      border: OutlineInputBorder(
                          borderSide: BorderSide(
                              width: 2,
                              color: _isPasswordValidated
                                  ? Colors.orange
                                  : Colors.white)),
                      errorBorder: OutlineInputBorder(
                          borderSide: BorderSide(
                              width: 2,
                              color: _isPasswordValidated
                                  ? Colors.orange
                                  : Colors.red)),
                      focusedErrorBorder: OutlineInputBorder(
                          borderSide: BorderSide(
                              width: 2,
                              color: _isPasswordValidated
                                  ? Colors.orange
                                  : Colors.red)),

在此处输入图像描述

I am trying to apply Red color when password has not been typed or _isPasswordValidated value is false.我正在尝试在未输入密码或_isPasswordValidated值为 false 时应用Red However, only orange color has been applied.但是,只应用了橙色。

Is there anyway that I can change the color without using Theme ?无论如何,我可以在不使用Theme的情况下更改颜色吗?

On idle, you need to use enabledBorder , also check focusedBorder and goes on.在闲置时,您需要使用enabledBorder ,同时检查focusedBorder并继续。

  • enabledBorder: The border to display when the InputDecorator is enabled and is not showing an error. enabledBorder:启用 InputDecorator 且未显示错误时显示的边框。
  • disabledBorder: The border to display when the InputDecorator is disabled and is not showing an error. disabledBorder:当 InputDecorator 被禁用且未显示错误时显示的边框。
  • focusedBorder: The border to display when the InputDecorator has the focus and is not showing an error. focusedBorder:当 InputDecorator 具有焦点且未显示错误时要显示的边框。

Full details on inputDecoration-class inputDecoration 类的完整详细信息

 TextField(
              decoration: InputDecoration(
                border: OutlineInputBorder(
                  borderSide: BorderSide(
                    width: 2,
                    color: _isPasswordValidated ? Colors.orange : Colors.white,
                  ),
                ),
                focusedBorder: OutlineInputBorder(
                  borderSide: BorderSide(
                    width: 2,
                    color: Colors.pink,
                  ),
                ),
                enabledBorder: OutlineInputBorder(
                  borderSide: BorderSide(
                    width: 2,
                    color: _isPasswordValidated ? Colors.orange : Colors.red,
                  ),
                ),
                errorBorder: OutlineInputBorder(
                  borderSide: BorderSide(
                    width: 2,
                    color: _isPasswordValidated ? Colors.orange : Colors.red,
                  ),
                ),
                focusedErrorBorder: OutlineInputBorder(
                  borderSide: BorderSide(
                    width: 2,
                    color: _isPasswordValidated ? Colors.orange : Colors.red,
                  ),
                ),
              ),
            ),

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

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