[英]How to change TextField underline border color when it is desabled
I want to change TextFiled underline color when it is disabled我想在禁用时更改 TextFiled 下划线颜色
child: TextField(
***enabled: false,***
controller: resultController,
style: TextStyle(
color: Colors.orange, fontSize: 18, fontWeight: FontWeight.bold),
keyboardType: TextInputType.number,
decoration: InputDecoration(
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.white)),
labelText: resultLableText,
labelStyle: TextStyle(color: Colors.white)),
),
I am unsure that there is a method you can use to check if a TextField
is disabled, but a way you can do it is you can create a bool
that keeps track if the TextField
is disabled.我不确定是否可以使用一种方法来检查TextField
是否被禁用,但可以这样做的一种方法是,您可以创建一个bool
来跟踪TextField
是否被禁用。
bool isDisabled = false;
Function<void> changeDisabled() {
setState() {
isDisabled ? isDisabled = false : isDisabled = true
}
}
isDisabled
in your code.检查代码中isDisabled
的状态。child: TextField(
enabled: false,
controller: resultController,
style: TextStyle(
color: Colors.orange, fontSize: 18, fontWeight: FontWeight.bold),
keyboardType: TextInputType.number,
decoration: InputDecoration(
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: isDisabled ? Colors.white : Colors.black)),
labelText: resultLableText,
labelStyle: TextStyle(color: Colors.white)),
),
You can specify the underline color of the TextField if its disabled in the same way you did for when its enabled by using the disabledBorder
property of the InputDecoration
like:您可以使用InputDecoration
的disabledBorder
属性指定 TextField 的下划线颜色(如果它被禁用,则与启用它时所做的相同),例如:
InputDecoration(
enabledBorder:
UnderlineInputBorder(borderSide: BorderSide(color: Colors.white)),
labelText: resultLableText,
labelStyle: TextStyle(color: Colors.white),
disabledBorder:
UnderlineInputBorder(borderSide: BorderSide(color: Colors.green)),
),
or specifying it in the ThemeData like:或在 ThemeData 中指定它,例如:
MaterialApp(
theme: ThemeData.light().copyWith(
inputDecorationTheme: InputDecorationTheme(
disabledBorder:
UnderlineInputBorder(borderSide: BorderSide(color: Colors.green)),
)),
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: MyWidget(),
),
),
);
}
Look at the below code, it will easily solve your problem:看看下面的代码,它会很容易地解决你的问题:
TextField(
decoration: InputDecoration(
hintText: "Your hint here",
//defalult border
border: OutlineInputBorder(
borderSide: BorderSide(width: 1, color: Colors.green)),
//disabled border
disabledBorder: OutlineInputBorder(
borderSide: BorderSide(width: 1, color: Colors.grey)),
//enabled border
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(width: 1, color: Colors.blue)),
//error boreder
errorBorder: OutlineInputBorder(
borderSide: BorderSide(width: 1, color: Colors.red)),
//focused border
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(width: 1, color: Colors.purple)),
//error while focused border
focusedErrorBorder: OutlineInputBorder(
borderSide: BorderSide(width: 1, color: Colors.amber)),
),
),
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.