【问题标题】:Flutter: TextFormField and RaisedButton alignment on the same rowFlutter:TextFormField和RaisedButton对齐在同一行
【发布时间】:2020-04-17 01:00:10
【问题描述】:

在屏幕底部,优惠券代码文本表单字段和申请按钮有错位。 如何将这些小部件设置为相同的高度并完美对齐?

      Row(
        mainAxisAlignment: MainAxisAlignment.end,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Container(
            width: 150,
            //color: Colors.blue,
            child: TextFormField(
              decoration: new InputDecoration(
                hintText: 'Coupon Code',
                contentPadding: EdgeInsets.all(8),
                isDense: true,
                border: new OutlineInputBorder(
                    borderSide: new BorderSide(color: Colors.grey)),
              ),
            ),
          ),
          Container(
            //color: Colors.green,
            padding: EdgeInsets.fromLTRB(15, 0, 0, 15),
            child: RaisedButton(
              onPressed: () {},
              color: Colors.grey[400],
              textColor: Colors.black,
              child: Text('Apply', style: TextStyle(fontSize: 12)),
            ),

          ),
        ],
      )

【问题讨论】:

    标签: flutter


    【解决方案1】:

    其实我想你会发现这样会有更好的结果。

    Container(
                  padding: EdgeInsets.only(top: 8),
                  width: 150,
                  //color: Colors.blue,
                  child: TextFormField(
                    decoration: new InputDecoration(
                      hintText: 'Coupon Code',
                      contentPadding: EdgeInsets.all(8),
                      isDense: true,
                      border: new OutlineInputBorder(
                          borderSide: new BorderSide(color: Colors.grey)),
                    ),
                  ),
                ),
    

    让我知道这对你有什么作用

    【讨论】:

    • 这对您有帮助吗?
    【解决方案2】:

    在找到这篇文章之前,我也为此苦苦挣扎:

    In Flutter, how to make Buttons and Textfields of same height?

    我仍然不明白为什么 TextField 小部件不能正确调整到它的父级,除非启用了 Expands 选项,然后排除了使用 ObstrucedText 选项的能力。

    这是一篇与在许多不同设备上管理文本和小部件大小相关的帖子:

    How to make flutter app responsive according to different screen size?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-21
      • 2017-11-28
      • 1970-01-01
      • 2023-03-31
      • 2011-03-20
      • 2020-07-05
      • 2016-06-05
      • 1970-01-01
      相关资源
      最近更新 更多