首页 > 解决方案 > Textformfield输入文本位置不等于图标颤动

问题描述

我有带有图标的textformfield,但输入文本的位置与我有的图标不相等

我该如何解决?

我试过的代码

class TestPage extends StatefulWidget {
  @override
  _TestPageState createState() => _TestPageState();
}

class _TestPageState extends State<TestPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          TextFormField(
            decoration: InputDecoration(
                prefixIcon: Icon(Icons.person),
                filled: true,
                hintText: 'Email',
                fillColor: Colors.white
            ),
          ),
          TextFormField(
            decoration: InputDecoration(
                prefixIcon: Icon(Icons.https),
                filled: true,
                hintText: 'Password',
                fillColor: Colors.white
            ),
          ),
        ],
      )
    );
  }
}

对此

标签: flutterflutter-layout

解决方案


请遵循以下方法:

contentPadding: EdgeInsets.fromLTRB(20.0, 15.0, 20.0, 15.0),

请在 InputDecoration 中使用内容填充,并尝试将 TextFormField 放入容器中以更好地对齐。


推荐阅读