小编chi*_*oks的帖子

Flutter DropdownButtonFormField 不显示在行中

我在行内并排添加一个DropdownFormField和。TextFormField这就是构建函数的样子

Widget build(BuildContext context) {
    return Form(
      key: _formKey,
      child: SingleChildScrollView(
        child: Column(
          children: <Widget>[
            Row(
              mainAxisAlignment: MainAxisAlignment.start,
              children: <Widget>[
                DropdownButton(
                  hint: new Text('Select Gender'),
                  items: _salutations,
                  value: client.salutation,
                ),
                SizedBox(width: 20),
                new Expanded(
                  child: TextFormField(
                    decoration: InputDecoration(labelText: 'Name'),
                    validator: (value) {
                      return value.isEmpty ? 'Empty name.' : '';
                    },
                  ),
                ),
              ]
            )
          ],
        )
      ),
    );
  }
Run Code Online (Sandbox Code Playgroud)

该代码当前显示,因为它是 DropdownButton。但如果我将其更改为 DropdownButtonFormField,只要它位于 Row() 中,它就不会显示。为什么是这样?

我希望使用 DropdownButtonFormField ,以便 Dropdown 的高度与 TextFormField 相同,因为当前代码显示的下拉菜单高度较小。

flutter flutter-layout

2
推荐指数
1
解决办法
2743
查看次数

标签 统计

flutter ×1

flutter-layout ×1