gpt4 book ai didi

flutter - 在 Flutter 的 Input Decoration 中为 labelText 添加 mandatory(*)

转载 作者:行者123 更新时间:2023-12-03 04:00:38 25 4
gpt4 key购买 nike

我想在 InputDecoration labelText 中添加星号并更改它的颜色(如红色),以便用户轻松理解此字段是必需的。

TextField(
autofocus: true,
controller: _nameCtrlr,
keyboardType: TextInputType.text,
decoration: InputDecoration(
labelText: "Name *",
))

像这张图片的预期结果 Sample Image

最佳答案

您可以像这样使用 Rich Text Widget

RichText getRequiredLabel(String fieldName) {
return RichText(
text: TextSpan(
style: TextStyle(color: Colors.black),
text: fieldName,
children: [
TextSpan(text: '*', style: TextStyle(color: Colors.red))
]));
}

关于flutter - 在 Flutter 的 Input Decoration 中为 labelText 添加 mandatory(*),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57320684/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com