【问题标题】:How to align the TextFormField at left如何在左侧对齐 TextFormField
【发布时间】:2018-10-15 02:59:26
【问题描述】:

对 Flutter 非常陌生。我希望 MI TextFormField 像 lastname 和 firstname 字段一样左对齐。

下面的 MI 代码:

                    new Container(
                        width: 50.0,
                        child: new TextFormField(
                            controller: miController,
                            obscureText: true,
                            decoration: new InputDecoration(labelText: 'MI'),
                            inputFormatters: [new LengthLimitingTextInputFormatter(1)],
                        ),
                    ),

Stackoverflow 没有让我有比描述更多的代码。所以请看这里:https://pastebin.com/VaqUGH9g

【问题讨论】:

  • 您在使用列吗?你能再显示一些代码吗
  • 如何包装所有文本字段。粘贴更多代码。
  • Stackoverflow 没有让我有比描述更多的代码。所以请看这里:pastebin.com/VaqUGH9g
  • crossAxisAlignment: CrossAxisAlignment.start,因为您的 Column 应该将小部件向左移动。

标签: flutter


【解决方案1】:

正如@sreeramu 在您的代码中提到的那样简单添加 crossAxisAlignment:CrossAxisAlignment.start :其余代码都很好。

body: Container(
                padding: const EdgeInsets.all(20.0),
                child: new Column(
                    mainAxisAlignment: MainAxisAlignment.start,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: <Widget>[
                        new TextFormField(.....//Code Cont.

【讨论】:

    【解决方案2】:

    你可以用 Align 包裹你的 Mi TextFormField 容器来实现你想要的布局。

    Align(
          alignment: Alignment.topLeft,
          child: Container(
          width: 50.0,
          alignment: Alignment.topLeft,
          child: new TextFormField(
              controller: miController,
              decoration: new InputDecoration(labelText: 'MI'),
              inputFormatters: [new LengthLimitingTextInputFormatter(1)],
             ),
         ),
    ),
    

    【讨论】:

      【解决方案3】:

      要对所有 TextFormFields 进行处理,您需要将它们添加到列中。

      new Column(
             mainAxisAlignment: MainAxisAlignment.start,
             children: new TextFormField(), // <- username
                       new TextFormField(), // <- password
                       new TextFormField()  // <- MI
                )
      

      您的 MI TextFormField 已对齐已左对齐。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-01-04
        • 1970-01-01
        • 2016-08-31
        • 1970-01-01
        • 1970-01-01
        • 2014-07-31
        • 1970-01-01
        相关资源
        最近更新 更多