1

我在视图中添加了一个下拉按钮小部件,当我在控件顶部时,它不会打开以显示可用值。

我什至尝试使用示例代码,但它仍然没有显示。此小部件位于 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(),
                          ),
                        ],
                      ),
                    ),

                  ],
                ),
              ],
            ),
          ),
        ),
        ),
        );
4

1 回答 1

0

不完全确定为什么我在上面发布的内容和最终的解决方案存在差异,但这是我为了让下拉弹出框显示而将视图更改为的内容。

当我调试时,我一点一点地分解它,并注意到当我添加一个高度占据一半视图的容器时,弹出框会显示,但在该容器的底部清晰,基本上推动了顶部位置下拉列表,位于它所在容器的底部。所以我假设显示列表的弹出框是“显示”,但在容器下方,因此它似乎无法正常工作。不知道为什么它会附加到主父容器的“外部”,但看起来这就是它正在做的事情。

所以....我将脚手架 body: 属性的设置改为:

SingleChildScrollView(
          physics: new AlwaysScrollableScrollPhysics(),
          controller: _controller,
          child: ConstrainedBox(
            constraints: BoxConstraints.tightFor(
              height: MediaQuery.of(context).size.height,
            ),
            child: Stack(
.....
于 2019-09-04T22:48:32.517 回答