首页 > 解决方案 > Flutter:TextFormField和RaisedButton对齐在同一行

问题描述

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

在此处输入图像描述

      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

解决方案


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

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)),
                ),
              ),
            ),

让我知道这对你有用


推荐阅读