Textformfield输入文本位置与图标颤动不相等

问题描述 投票:0回答:1

我有带图标的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
            ),
          ),
        ],
      )
    );
  }
}

from

to this

flutter flutter-layout
1个回答
0
投票

尝试一下,这可以按预期工作。

根据InputDecorator文档,suffix小部件基线与输入基线对齐。

如果要使其居中对齐,请改用suffixIcon

希望它将解决您的问题。

© www.soinside.com 2019 - 2024. All rights reserved.