我正在检查的代码,DropDown
没有属性设置的高度Dialog
,它几乎填满了整个屏幕。
我对该类进行了一些小的更改,如果需要,您可以将其包含在您的项目中:
https://gist.github.com/tudor07/9f886102f3cb2f69314e159ea10572e1
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",
),