简体   繁体   English

嵌套列表视图在 Flutter 中导致问题

[英]Nested listview causing issue in Flutter

I want to have nested listview where there will be vertical listview inside a horizontal listview and that will be wrapped with SingleChildScrollView because I want to scroll all the vertical lists together.我想要嵌套列表视图,其中水平列表视图内有垂直列表视图,并且将用 SingleChildScrollView 包裹,因为我想一起滚动所有垂直列表。

So here's what I have done所以这就是我所做的

Expanded(
                    child: Stack(
                  children: [
                    Container(
                      height: double.infinity,
                      width: double.infinity,
                      decoration: BoxDecoration(
                          gradient: LinearGradient(
                        begin: Alignment.topCenter,
                        end: Alignment.bottomCenter,
                        colors: [
                          Theme.of(context).primaryColorDark,
                          Theme.of(context).primaryColorLight,
                        ],
                      )),
                    ),
                    SingleChildScrollView(
                        scrollDirection: Axis.vertical,
                        physics: const BouncingScrollPhysics(),
                        child: SizedBox(
                          height: 200.w,
                          child: ListView.builder(
                            scrollDirection: Axis.horizontal,
                            physics: const BouncingScrollPhysics(),
                            itemCount: 5,
                            itemBuilder: (context, index) {
                              return SizedBox(
                                height: double.infinity,
                                width: 24.w,
                                child: Column(
                                  children: [
                                    Container(
                                        width: double.infinity,
                                        padding: EdgeInsets.fromLTRB(
                                            0.w, 3.w, 0, 3.w),
                                        color: Colors.white,
                                        child:
                                        Center(child: Text("Header"))),
                                    ListView.builder(
                                      physics:
                                      const NeverScrollableScrollPhysics(),
                                      itemCount: 20,
                                      shrinkWrap: true,
                                      itemBuilder: (context, index) {
                                        return GestureDetector(
                                          onTap: () {},
                                          child: Padding(
                                            padding: EdgeInsets.fromLTRB(
                                                0.w, 2.w, 0.w, 2.w),
                                            child: Center(
                                              child: Text(
                                                  "8:44",
                                                  style: TextStyle(
                                                      color: Colors.white,
                                                      fontSize: 14.sp)),
                                            ),
                                          ),
                                        );
                                      },
                                    )
                                  ],
                                ),
                              );
                            },
                          ),
                        ))
                  ],
                ))

Desired output:所需的 output:

在此处输入图像描述

But in this if I don't put vertical listview in SizedBox and don't give fixed height then it causes an issue.但是在这种情况下,如果我不将垂直列表视图放在 SizedBox 中并且不提供固定高度,则会导致问题。

I want to have expanded or something like wrap_content for vertical inside listview so it takes the required space on it's own.我想在 listview 中扩展或类似 wrap_content 的内容,以便它自己占用所需的空间。

So what to do for this?那么为此要做什么呢? Can someone help?有人可以帮忙吗?

Thanks in advance.提前致谢。

have you tried height: double.maxFinite,你试过 height: double.maxFinite,

in the SizedBox... this will le在 SizedBox 中...这将

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM