【问题标题】:Flutter my Listview is not scrolling even I have alwayscrollable即使我总是可滚动,我的 Listview 也不会滚动
【发布时间】:2021-01-01 22:46:54
【问题描述】:

我真的不明白是什么导致了错误。

我的代码在一个带有返回 Widget 方法的单独类中,该方法返回一个包含我的 Listview 的 Stack。

注意:当我使用 Listview 复制 Container 并修改了相应的值时;然后再次粘贴到一个以 A Stack 为父项的新项目中,它似乎工作正常。

代码如下:

AddStockUI(){
    Widget getAddStockUI() {
        final mediaSize = MediaQuery.of(context).size;
        return Container(
          width: mediaSize.width,
          height: mediaSize.height,
          color: Colors.white,
          child: Stack(
            children: <Widget>[
              //Head - image
              Container(
                width: mediaSize.width * .8,
                height: mediaSize.height * .2,
                margin: EdgeInsets.only(
                  left: mediaSize.width * .1,
                  right: mediaSize.width * .1,
                  top: mediaSize.height * .05,
                ),
                child: Row(
                  children: <Widget>[
                    Container(
                      width: mediaSize.width * .37,
                      height: mediaSize.height * .2,
                      child: Image.asset(
                        'assets/images/image_add_image.png',
                        width: mediaSize.width * .37,
                        height: mediaSize.height * .2,
                        filterQuality: FilterQuality.high,
                        fit: BoxFit.fill,
                      ),
                    ),
                    Spacer(),
                    Container(
                        constraints: BoxConstraints(
                            maxHeight: mediaSize.height * .2,
                            maxWidth: mediaSize.width * .37),
                        padding: EdgeInsets.all(0),
                        child: ListView.builder(
                            padding: EdgeInsets.all(0),
                            physics: AlwaysScrollableScrollPhysics(),
                            itemCount: myMapDesc.keys.length + 1,
                            itemBuilder: (BuildContext ctx, int index) {
                              if (index == 0) {
                                return Container(
                                  width: mediaSize.width * .35,
                                  height: mediaSize.height * .03,
                                  child: Row(
                                    children: <Widget>[
                                      Center(
                                          child: Container(
                                        width: mediaSize.width * .14,
                                        child: AutoSizeText(
                                          "variation",
                                          style: TextStyle(color: myLightDarkColor),
                                          maxFontSize: 14,
                                          minFontSize: 12,
                                          maxLines: 1,
                                        ),
                                      )),
                                      Spacer(),
                                      Center(
                                          child: Container(
                                        width: mediaSize.width * .1,
                                        child: AutoSizeText(
                                          "value",
                                          style: TextStyle(color: myLightDarkColor),
                                          maxFontSize: 14,
                                          minFontSize: 12,
                                          maxLines: 1,
                                        ),
                                      )),
                                      Spacer(),
                                      Container(width: mediaSize.width * .11)
                                    ],
                                  ),
                                );
                              } else {
                                return Container(
                                  margin:
                                      EdgeInsets.only(top: mediaSize.height * .025),
                                  width: mediaSize.width * .35,
                                  height: mediaSize.height * .03,
                                  child: Row(
                                    children: <Widget>[
                                      Center(
                                          child: Container(
                                        width: mediaSize.width * .1,
                                        child: AutoSizeText(
                                          myMapDesc.keys
                                              .toList()[index - 1]
                                              .toString(),
                                          style: TextStyle(color: myLightDarkColor),
                                          maxFontSize: 14,
                                          minFontSize: 12,
                                          maxLines: 1,
                                        ),
                                      )),
                                      Spacer(),
                                      Center(
                                          child: Container(
                                        width: mediaSize.width * .1,
                                        child: AutoSizeText(
                                          myMapDesc.values
                                              .toList()[index - 1]
                                              .toString(),
                                          style: TextStyle(color: myLightDarkColor),
                                          maxFontSize: 14,
                                          minFontSize: 12,
                                          maxLines: 1,
                                        ),
                                      )),
                                      Spacer(),
                                      Icon(
                                        Icons.remove_circle,
                                        color: Colors.red,
                                      )
                                    ],
                                  ),
                                );
                              }
                            }))
                  ],
                ),
              ),
       }
    }

【问题讨论】:

    标签: flutter listview user-interface flutter-layout scrollable


    【解决方案1】:

    尝试用 SingleChildScrollView 包装您的 ListView

    【讨论】:

    • 如何包装父小部件?
    • 第一个容器??
    • 最后一次尝试.. 用SingleChildScrollView 包装你的Stack() 小部件,如果这不起作用,我很抱歉我没有想法...... :(
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-19
    • 1970-01-01
    相关资源
    最近更新 更多