【问题标题】:How to position two widget in a same Row?如何将两个小部件放置在同一行中?
【发布时间】:2019-06-17 10:47:03
【问题描述】:

我有一个国家代码(DropdownMenu)和电话(TextFormField),我怎样才能把它们放在同一级别? 我试过对齐小部件。

Row(
                children: <Widget>[
                  Flexible(
                    flex: 1,
                    child: DropdownButtonFormField(
                      value: _selectedCountryCode ?? 'TR',
                      onChanged: (value) {
                        setState(() {
                          _selectedCountryCode = value;
                        });
                      },
                      items: countryCodes,
                    ),
                  ),
                  Flexible(
                    flex: 4,
                    child: Padding(
                      padding: const EdgeInsets.all(16.0),
                      child: TextFormField(
                        decoration: InputDecoration(labelText: "Phone"),
                      ),
                    ),
                  ),
                ],
              ),

【问题讨论】:

  • 别忘了添加小部件的代码。
  • Row() 小部件中你可以使用crossAxisAlignment: CrossAxisAlignment.baseline
  • @danish-khan-I crossAxisAlignment != I/flutter (2417): CrossAxisAlignment.baseline || textBaseline != null': 不正确。

标签: flutter


【解决方案1】:

感谢@danish-khan-I,我使用crossAxisAlignment: CrossAxisAlignment.baseline 解决了问题。但是您还必须提供textBaseline 否则它会给出异常。

所以在我的行中我使用过:

crossAxisAlignment: CrossAxisAlignment.baseline
textBaseline: TextBaseline.ideographic,

【讨论】:

  • 感谢textBaseline 提示
猜你喜欢
  • 2011-01-18
  • 2017-03-23
  • 1970-01-01
  • 2019-01-30
  • 1970-01-01
  • 1970-01-01
  • 2020-03-08
  • 2023-03-19
  • 1970-01-01
相关资源
最近更新 更多