设置DropdownButtonFormField列表的高度 [英] Set height of DropdownButtonFormField list

查看:582
本文介绍了设置DropdownButtonFormField列表的高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Flutter中, DropdownButtonFormField 的模式列表不断增长,以填补似乎占屏幕约90%的高度限制(或者可能,而且更有可能是容器)。当达到该限制时,它将变为可滚动。

In Flutter, DropdownButtonFormField's modal list keeps growing to fill some height limit that seems to be ~90% of the screen (or possibly, and more likely, the Container it's in). When it reaches that limit, it becomes scrollable. Is it possible to set that height limit?

这是我正在使用的代码

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
            DropdownButtonFormField(items: this.dropDownItems),
          ],
        ),
      )),
);


推荐答案

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

I was checking the code of DropDown and there is no property to set the height of the Dialog, it just fill almost the screen.

我对该类进行了小幅更改,如果需要,您可以将其包括在您的项目中:

I made a small change to the class and you can include to your project if you want:

https://gist.github.com/tudor07/9f886102f3cb2f69314e159ea10572e1

用法

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

1- Add the file into your project.

2-导入文件

 import 'custom_dropdown.dart' as custom;

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

3- Use the alias in your Widgets related to the DropDown, and add the height property:

    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 <中添加别名/ code>像这样:

4- Don't forget to add the alias also in your DropdownMenuItem like this :

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

这篇关于设置DropdownButtonFormField列表的高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆