设置DropdownButtonFormField列表的高度

时间:2018-12-31 05:04:52

标签: dart flutter

在Flutter中,./count.sh: line 5: [102: command not found 102 is less than 100 的模式列表不断增长,以填补大约90%的屏幕高度限制(或更可能是它所在的DropdownButtonFormField)。当达到该限制时,它将变为可滚动。可以设置该高度限制吗?

这是我正在使用的代码

Container

3 个答案:

答案 0 :(得分:4)

使用此行,您可以像便宜商品一样使用def display_values(self, attribute, type, r, c, cs): try: if self.display_label: self.display_label.destroy() except AttributeError: lambda *args: None self.display_label = tk.Label(self.parent, text=str(attribute) + " (" + type + ")") self.display_label.grid(row=r, column=c, columnspan=cs, sticky=tk.W)

DropdownButtonFormField

所以您的代码将是这样:

isDense: false,
itemHeight: 60,//what you need for height

答案 1 :(得分:2)

我正在检查DropDown的代码,没有属性设置Dialog的高度,它几乎填满了整个屏幕。

我对该类做了一些小的更改,如果需要,您可以将其包含在您的项目中

https://gist.github.com/diegoveloper/11887a66e1439135a95133139954b133

用法

1-将文件添加到您的项目中。

2-使用别名导入文件以避免冲突。

 import 'custom_dropdown.dart' as custom;

3-在小部件中使用与DropDown相关的别名,并添加height属性:

    Scaffold(
      appBar: AppBar(title: Text(widget.title)),
      body: Container(
          padding: EdgeInsets.fromLTRB(5, 5, 5, 5),
          child: Form(
            child: ListView(
              scrollDirection: Axis.vertical,
              children: <Widget>[
                //other widgets here
                custom.DropdownButtonFormField(
                height: 200.0,
                items: this.dropDownItems),
              ],
            ),
          )),
    );

4-不要忘了像这样在您的DropdownMenuItem中添加别名:

 custom.DropdownMenuItem(
                child: Text("Sample Tex"),
                value: "any_value",
              ),

答案 2 :(得分:0)

DropdownButtonHideUnderline(
            child: Container(
              height: // some height,
              padding: // add padding 
              decoration: // add decoration
              child: DropdownButtonFormField(
                decoration: InputDecoration.collapsed(hintText: ''),  
                // add some function according to you
              ),
            ),
          )

**此容器装饰负责在下拉按钮中显示装饰**