1

这是我在屏幕上的内容:

https://i.imgur.com/oSblgWD.png

如何对齐姓氏,使其在名字下?我不想在姓氏旁边放一个图标,只是名字。

这是我的代码。谢谢。

            body: Center(
            child: Form(
                key: _formKey,
                child: Column(
                    children: <Widget>[
                        ListTile(
                            leading: const Icon(Icons.person),
                            title: new TextField(
                                decoration: new InputDecoration(
                                    hintText: "First name",
                                ),
                            ),
                        ),
                        ListTile(
                            title: new TextField(
                                decoration: new InputDecoration(
                                    hintText: "Last name",
                                ),
                            ),
                        ),
                    ],
                ),
            )
        )
4

4 回答 4

2

简单而优雅的方式是使用Padding小部件。

@override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
          child: Form(
        //  key: _formKey,
        child: Column(
          children: <Widget>[
            ListTile(
              leading: const Icon(Icons.person),
              title: new TextField(
                decoration: new InputDecoration(
                  hintText: "First name",
                ),
              ),
            ),
            ListTile(
              leading: Padding(padding: EdgeInsets.all(16.0)),
              title: new TextField(
                decoration: new InputDecoration(
                  hintText: "Last name",
                ),
              ),
            ),
          ],
        ),
      )),
    );
  }
于 2019-02-13T08:28:55.193 回答
1

There's a quick hack by changing icon color to colors.transparent. I don't know if it's proper way though.

     body: Center(
        child: Form(
            key: _formKey,
            child: Column(
                children: <Widget>[
                    ListTile(
                        leading: const Icon(Icons.person),
                        title: new TextField(
                            decoration: new InputDecoration(
                                hintText: "First name",
                            ),
                        ),
                    ),
                    ListTile(
                        leading: const Icon(Icons.person,color: Colors.transparent),
                        title: new TextField(
                            decoration: new InputDecoration(
                                hintText: "Last name",
                            ),
                        ),
                    ),
                ],
            ),
        )
    )
于 2019-02-13T07:49:59.897 回答
1

您可以为 Last Name添加一个Container固定宽度的空白,或者您可以将您的 Last Name 包装在里面并从左侧提供一些。leadingTextFieldTextFieldPaddingpadding

例子:

ListTile(
  leading: Container(
    width: 200.0, //You can adjust the width as required
  ),
  title: new TextField(
    decoration: new InputDecoration(
      hintText: "Last name",
    ),
  ),
),

或者

ListTile(
  title: Padding(
    padding: padding: EdgeInsets.only(left: 200.0) //Adjust as required
    child: new TextField(
      decoration: new InputDecoration(
        hintText: "Last name",
      ),
    ),
  ),
),
于 2019-02-13T04:26:50.513 回答
0

我所做的是给它一个大小为 0 的图标,即使没有可见的东西,ListTile 也会节省空间

于 2022-01-02T10:07:18.583 回答