设置 DropdownButtonFormField 列表的高度 [英] Set height of DropdownButtonFormField list
问题描述
在 Flutter 中,DropdownButtonFormField
的模态列表不断增长以填充一些高度限制,该高度限制似乎是屏幕的 90%(或者可能,更有可能是 Container
代码>它在).当它达到该限制时,它变得可滚动.可以设置那个高度限制吗?
这是我正在使用的代码
脚手架(appBar: AppBar(title: Text(widget.title)),主体:容器(填充:EdgeInsets.fromLTRB(5, 5, 5, 5),孩子:形式(孩子:列表视图(滚动方向:Axis.vertical,孩子们:<小部件>[//这里的其他小部件DropdownButtonFormField(items: this.dropDownItems),],),)),);
我查看了DropDown
的代码,没有设置Dialog
高度的属性,它几乎填满了屏幕.
我对类做了一个小改动,如果你愿意,你可以将其添加到你的项目中:
https://gist.github.com/tudor07/9f886102f3cb2f693>ea115e
使用
1- 将文件添加到您的项目中.
2- 使用别名导入文件以避免冲突.
import 'custom_dropdown.dart' 作为自定义;
3- 在与 DropDown 相关的小部件中使用别名,并添加高度属性:
脚手架(appBar: AppBar(title: Text(widget.title)),主体:容器(填充:EdgeInsets.fromLTRB(5, 5, 5, 5),孩子:形式(孩子:列表视图(滚动方向:Axis.vertical,孩子们:<小部件>[//这里的其他小部件custom.DropdownButtonFormField(高度:200.0,项目:this.dropDownItems),],),)),);
4- 不要忘记在您的 DropdownMenuItem
中添加别名,如下所示:
custom.DropdownMenuItem(孩子:文本(样本文本"),值:any_value",),
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?
Here's the code I'm working with
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),
],
),
)),
);
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
Usage
1- Add the file into your project.
2- Import the file with an alias to avoid conflicts.
import 'custom_dropdown.dart' as custom;
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- Don't forget to add the alias also in your DropdownMenuItem
like this :
custom.DropdownMenuItem(
child: Text("Sample Tex"),
value: "any_value",
),
这篇关于设置 DropdownButtonFormField 列表的高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!