Flutter中输入装饰中为labelText添加强制(*)

2024-04-04

我想添加星号登录InputDecorationlabelText 并更改其颜色(如红色),以便用户轻松理解此字段是必需的。

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

预期结果如下图所示示例图片 https://i.stack.imgur.com/dMOJ4.png


您可以使用label里面的争论InputDecoration参数。这两个小部件都可以工作TextField or TextFormField

TextField(
        decoration: InputDecoration(
          label: Row(
            children: [
              const Text('*', style: TextStyle(color: Colors.red)),
              Padding(
                padding: EdgeInsets.all(3.0),
              ),
              Text("Name")
            ],
          ),
        ),
        controller: _nameCtrlr,
        autofocus: true,
        keyboardType: TextInputType.text,
       );
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Flutter中输入装饰中为labelText添加强制(*) 的相关文章

随机推荐