【问题标题】:Textfield alignment文本字段对齐
【发布时间】:2020-07-19 15:43:33
【问题描述】:

我想将我的 TextField 与我的文本对齐。目前它看起来像这样:

我尝试了不同的方式来对齐它,但是我尝试过的任何方式都搞砸了,我可以点击使 TextField 处于活动状态(只能点击文本字段顶部的右侧) 代码如下:

    Container(
                  padding: EdgeInsets.all(5),
                  decoration: BoxDecoration(
                      color: Colors.white,
                      borderRadius: BorderRadius.circular(10)),
                  margin: EdgeInsets.all(20),
                  width: 300,
                  height: 45,
                  child: Row(
                    children: <Widget>[
                      Text(
                        'Name: ',
                        style: TextStyle(
                            fontSize: 25, fontWeight: FontWeight.bold),
                      ),
                      Expanded(
                        child: Container(
                          child: TextField(
                            decoration: InputDecoration.collapsed(
//                                border: InputBorder.none,
                                hintText: '                               ',
                                hintStyle: TextStyle(fontSize: 23)),
                            controller:
                                _nameController ?? TextEditingController()
                                  ..text = widget.name,
                            onChanged: (text) => {},
                            style: TextStyle(fontSize: 23),
                          ),
                        ),
                      )
                    ],
                  ),
                )

谢谢

【问题讨论】:

标签: flutter flutter-layout


【解决方案1】:

我刚刚删除了您的填充,因为它使您的元素不对齐。现在它工作正常。

Container(
                 // padding: EdgeInsets.all(5),
                  decoration: BoxDecoration(
                      color: Colors.white,
                      borderRadius: BorderRadius.circular(10)),
                 margin: EdgeInsets.all(20),
                  width: 300,
                  height: 45,
                  child: Row(
                    children: <Widget>[
                      Text(
                        'Name: ',
                        style: TextStyle(
                            fontSize: 25, fontWeight: FontWeight.bold),
                      ),
                      Expanded(
                        //child: Container(
                          child: TextField(
                            decoration: InputDecoration.collapsed(
//                                border: InputBorder.none,
                                hintText: '                               ',
                                hintStyle: TextStyle(fontSize: 23)),
                            controller:
                                TextEditingController()
                                  ..text = 'widget.name',
                            onChanged: (text) => {},
                            style: TextStyle(fontSize: 23),
                          ),
                       // ),
                      )
                    ],
                  ),
                )

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-27
    • 1970-01-01
    • 2020-03-12
    相关资源
    最近更新 更多