我已经在视图中添加了一个dropdownbutton小部件,当我在控件上单击时,它不会打开以显示可用值。
我什至尝试使用示例代码,但仍未显示。该小部件位于SingleChildScrollView中。我将其更改为容器,以查看是否是滚动问题,但这甚至行不通。
Padding(
padding: const EdgeInsets.only(left: 10.0),
child: DropdownButton(
elevation: 2,
value: 'One',
onChanged: (val){
print(val);
},
hint: Text(
"Select the leach",
style: TextStyle(
color: Colors.black,
),
),
items: <String>['One', 'Two', 'Free', 'Four']
.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
})
.toList()
)
),
在控件上单击/点击时,它应该显示出来,但是我不确定缺少什么会导致它不显示值。
我在日志中(至少我熟悉的日志)没有看到任何错误
使用更多代码更新:
SafeArea(
child: Scaffold(
appBar: AppBar(
title: Hero(
tag: widget.film.title + widget.film.number,
child: Material(
type: MaterialType.transparency,
child: Text(
widget.film.title,
style: TextStyle(
color: Colors.white,
fontSize: 18.0,
fontFamily: Constant.fontRegular,
fontWeight: FontWeight.bold,
),
),
),
),
),
body:
Container(
//color: Colors.white,
height: MediaQuery.of(context).size.height,
child: SingleChildScrollView(
physics: new AlwaysScrollableScrollPhysics(),
controller: _controller,
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Stack(
overflow: Overflow.visible,
children: <Widget>[
MeetNetworkImage(
fit: BoxFit.cover,
width: MediaQuery.of(context).size.width,
imageUrl: widget.film.backdrop != null ? "https://image.tmdb.org/t/p/w400/" + widget.film.backdrop : "",
loadingBuilder: (context) => Center(
child: CircularProgressIndicator(),
),
errorBuilder: (context, e) => Center(
child: FadeInImage(
fit: BoxFit.fitWidth,
width: MediaQuery.of(context).size.width,
image: AssetImage('assets/images/placeholder.png'),
placeholder:
AssetImage('assets/images/placeholder.png'),
),
),
),
Positioned(
left: MediaQuery.of(context).size.width-60,
top: 10,
child: Container(
height: 40.0,
width: 50.0,
color: Colors.transparent,
child: new Container(
decoration: new BoxDecoration(
color: widget.film.checkedoutby == null ? Colors.green : Colors.red,
borderRadius: new BorderRadius.all(Radius.circular(10))),
child: new Center(
child: new Text(widget.film.number, style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18.0),),
)),
),
),
Positioned(
top: 180,
left: 15,
child: Container(
height: 200.0,
//color: Colors.grey[200],
child: MeetNetworkImage(
fit: BoxFit.contain,
imageUrl: widget.film.poster != null
? "https://image.tmdb.org/t/p/w200/" + widget.film.poster
: "",
loadingBuilder: (context) => Center(
child: CircularProgressIndicator(),
),
errorBuilder: (context, e) => Center(
child: FadeInImage(
fit: BoxFit.fill,
width: MediaQuery.of(context).size.width,
image:
AssetImage('assets/images/placeholder.png'),
placeholder:
AssetImage('assets/images/placeholder.png'),
),
),
),
),
),
Positioned(
left: 155,
top: 225,
child: Column(
children: <Widget>[
Container(
padding: EdgeInsets.all(8.0),
child: Row(
children: <Widget>[
Text(
'Check Out',
style: TextStyle(
fontFamily: Constant.fontRegular,
fontWeight: FontWeight.bold),
),
Padding(
padding: const EdgeInsets.only(left: 10.0),
child: widget.users != null ?
DropdownButton(
elevation: 2,
value: widget.film.checkedoutby != null ? widget.film.checkedoutby : null,
onChanged: (val){
print(val);
},
hint: Text(
"Select the leach",
style: TextStyle(
color: Colors.black,
),
),
items: <String>['One', 'Two', 'Free', 'Four']
.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
})
.toList())
),
],
),
),
Container(
padding: EdgeInsets.all(8.0),
alignment: FractionalOffset.centerLeft,
child: Wrap(
children: <Widget>[
Text(
'Rating -',
style: TextStyle(
fontFamily: Constant.fontRegular,
fontWeight: FontWeight.bold),
),
Padding(
padding: const EdgeInsets.only(left: 10.0),
child: Text(
widget.film.rating,
style: TextStyle(
fontFamily: Constant.fontRegular,
color: Colors.grey[500]),
),
),
],
),
),
Container(
padding: EdgeInsets.all(8.0),
child: Row(
children: <Widget>[
Text(
'Duration -',
style: TextStyle(
fontFamily: Constant.fontRegular,
fontWeight: FontWeight.bold),
),
Padding(
padding: const EdgeInsets.only(left: 10.0),
child: Text(
widget.film.runtime == null ? "" : widget.film.runtime,
style: TextStyle(
fontFamily: Constant.fontRegular,
color: Colors.grey[500]),
),
),
],
),
),
Container(
padding: EdgeInsets.all(8.0),
alignment: FractionalOffset.centerLeft,
child: Wrap(
children: <Widget>[
Text(
'Released -',
style: TextStyle(
fontFamily: Constant.fontRegular,
fontWeight: FontWeight.bold),
),
Padding(
padding: const EdgeInsets.only(left: 10.0),
child: Wrap(
alignment: WrapAlignment.start,
children: <Widget>[
Text(
widget.film.released ?? "",
style: TextStyle(
fontFamily: Constant.fontRegular,
color: Colors.grey[500]),
)
],
),
)
],
),
),
],
),
),
Positioned(
top: 395,
left: 10,
width: MediaQuery.of(context).size.width-10,
child: Column(
children: <Widget>[
Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Expanded(child: Text(widget.film.plot)),
],
),
Divider(),
Wrap(
children: widget.film.genre
.split(',')
.map<Widget>(
(f) => Padding(
padding: EdgeInsets.symmetric(horizontal: 8.0),
child: Chip(
labelPadding:
EdgeInsets.symmetric(horizontal: 8.0),
label: Text(f,
style: TextStyle(
color: Colors.white,
fontFamily: Constant.fontMedium,
)),
backgroundColor:
Theme.of(context).primaryColor,
),
),
).toList(),
),
],
),
),
],
),
],
),
),
),
),
);
答案 0 :(得分:0)
不确定我上面发布的内容和最终解决方案为何有所不同,但这是我将视图更改为为了显示下拉弹出框的原因。
在调试时,我将其一点一点分解,并注意到当我添加一个高度要占据一半视图的容器时,弹出窗口将显示出来,但在该容器的底部清晰可见,实际上是在推动下拉列表的顶部位置,到它所在的容器的底部。因此,我假设显示该列表的弹出窗口是“显示中”,但在容器下方,因此它似乎无法使用。不确定为什么会附加到主父容器的“外部”,但这看起来就是它的作用。
所以....我将脚手架body:属性的设置更改为:
SingleChildScrollView(
physics: new AlwaysScrollableScrollPhysics(),
controller: _controller,
child: ConstrainedBox(
constraints: BoxConstraints.tightFor(
height: MediaQuery.of(context).size.height,
),
child: Stack(
.....