首页 > 解决方案 > 如何将两个小部件放置在同一行中?

问题描述

我有国家代码(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"),
                      ),
                    ),
                  ),
                ],
              ),

截屏

标签: flutter

解决方案


感谢@danish-khan-I,我解决了使用crossAxisAlignment: CrossAxisAlignment.baseline. 但是你也必须提供,textBaseline否则它会给出一个例外。

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

crossAxisAlignment: CrossAxisAlignment.baseline
textBaseline: TextBaseline.ideographic,

推荐阅读