[英]Flutter: Is there any way I can change the color of the hintText in just one text field?
Padding(
padding: const EdgeInsets.all(20),
child: TextFormField(
style: TextStyle(fontSize: 18),
decoration: InputDecoration(
labelText: 'Balance',
labelStyle: TextStyle(fontSize: 18),
prefixText: '\$',
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
),
),
keyboardType: TextInputType.number,
validator: (input) =>
input.trim().isEmpty ? 'Required' : null,
onSaved: (input) {
_giftCardBalance = input;
},
initialValue: _giftCardBalance,
),
),
如何将仅美元符号的颜色更改为黑色,但将文本字段中占位符的 rest 保留为灰色? 我尝试更改主题数据中的提示颜色,但这会将所有字段的颜色更改为黑色。
InputDecoration
有一个prefixStyle
属性。 你可以这样设置:
Padding(
padding: const EdgeInsets.all(20),
child: TextFormField(
style: TextStyle(fontSize: 18),
decoration: InputDecoration(
labelText: 'Balance',
labelStyle: TextStyle(fontSize: 18),
prefixText: '\$',
// Here we can define the style!
prefixStyle: TextStyle(
color: Colors.blue,
),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
),
),
keyboardType: TextInputType.number,
validator: (input) =>
input.trim().isEmpty ? 'Required' : null,
onSaved: (input) {
_giftCardBalance = input;
},
initialValue: _giftCardBalance,
),
),
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.