How to add an extra label within TextFormField?

删除回忆录丶 提交于 2020-12-13 09:05:13

问题


Is there a way to position "Forget password" label inside a TextFormField?

sample

On a sample picture put forget password? right inside the input

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,
                  ),

回答1:


use the Suffix: property of - InputDecoration:

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,
          ),



来源:https://stackoverflow.com/questions/55396967/how-to-add-an-extra-label-within-textformfield

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!