【问题标题】:How to add an extra label within TextFormField?如何在 TextFormField 中添加额外的标签?
【发布时间】:2019-03-28 11:53:10
【问题描述】:

有没有办法在 TextFormField 中放置“忘记密码”标签?

在示例图片上放忘记密码?就在输入内部

new TextFormField(
                    decoration: InputDecoration(labelText: 'Password',
                      labelStyle: TextStyle(
                        color: Colors.black87,
                        fontSize: 17,
                        fontFamily: 'AvenirLight'
                      ),
                      focusedBorder: UnderlineInputBorder(      
                        borderSide: BorderSide(color: Colors.purple),   
                      ),
                      enabledBorder: new UnderlineInputBorder(
                        borderSide: BorderSide(color: Colors.grey, 
                          width: 1.0)
                      ),
                    ),
                    style: TextStyle(
                      color: Colors.black87,
                      fontSize: 17,
                      fontFamily: 'AvenirLight'
                    ),
                    controller: _passwordController,
                    obscureText: true,
                  ),

【问题讨论】:

  • 您必须专门使用TextFormField 吗?如果没有,您可以使用包含两个 TextField 和一些额外小部件的列来创建相同的用户体验。
  • 嗯,基本上我可以使用你提到的方法重建 ui,但我很好奇是否可以使用 textformfield
  • 使用 InputDecoration。您可以尝试使用 suffix、suffixIcon、prefix、prefixIcon 等 docs.flutter.io/flutter/material/InputDecoration-class.html

标签: flutter flutter-layout


【解决方案1】:

使用 - InputDecoration:Suffix: 属性

TextFormField(
            decoration: InputDecoration(
              suffix: GestureDetector(
                onTap: () {
                  print('tapped');
                },
                child: Text(
                  'Forgot Password?',
                  style: TextStyle(
                      color: Colors.blue, fontWeight: FontWeight.bold),
                ),
              ),
              labelText: 'Password',
              labelStyle: TextStyle(
                  color: Colors.black87,
                  fontSize: 17,
                  fontFamily: 'AvenirLight'),
              focusedBorder: UnderlineInputBorder(
                borderSide: BorderSide(color: Colors.purple),
              ),
              enabledBorder: new UnderlineInputBorder(
                  borderSide: BorderSide(color: Colors.grey, width: 1.0)),
            ),
            style: TextStyle(
                color: Colors.black87, fontSize: 17, fontFamily: 'AvenirLight'),
            //  controller: _passwordController,
            obscureText: true,
          ),

【讨论】:

  • @anmol.majgail 您的方法有效,但有一个小问题 :) 如果我的密码字段处于非活动状态,表示未聚焦,标签不可见,labelText: 'Password' 在 InputDecoration 中覆盖它.有什么解决办法吗?
猜你喜欢
  • 1970-01-01
  • 2013-05-03
  • 1970-01-01
  • 1970-01-01
  • 2016-12-19
  • 1970-01-01
  • 1970-01-01
  • 2017-11-05
  • 1970-01-01
相关资源
最近更新 更多