简体   繁体   English

如何在 PageView 中嵌套 ListView

[英]How to nest a ListView inside a PageView

I have a horizontal PageView with some nested vertical LIstView on each page.我有一个水平的 PageView,每页都有一些嵌套的垂直 LIstView。

the Issue is I am unable to scroll those nested listview as I am only registering the PageView gestures.问题是我无法滚动那些嵌套的列表视图,因为我只注册了PageView手势。

note: when I use SliverChildBuilderDelegate inside customSCrollView with no limits the scroll is actually active but everything else no注意:当我在customSCrollView中无限制地使用SliverChildBuilderDelegate时,滚动实际上是活动的,但其他一切都没有

this is what the code look like这就是代码的样子

class ProductDetail extends StatefulWidget {
  
  @override
  State<StatefulWidget> createState() => ProductDetailState();
}

class ProductDetailState extends State {
  

  @override
  Widget build(BuildContext context) {
    return Material(
      child: DefaultTabController(
        length: 2,
        child: Column(
          children: [
            Expanded(
              child: NestedScrollView(
//                 physics: BouncingScrollPhysics(),
                headerSliverBuilder:
                    (BuildContext context, bool innerBoxIsScrolled) {
                  return <Widget>[];
                },
                body: PageView( // this is a pageView container
                  children: <Widget>[
                    CustomScrollView(
                      slivers: [
                       SliverList(
                          delegate: SliverChildBuilderDelegate(
                            (context, index) {
                              return ListTile(
                                title: Text('index $index'),
                              );
                            },
                            childCount: 10
                          ),
                        )
                       ]
                    ),
                    CustomScrollView(
                      slivers: [
                       SliverList(
                          delegate: SliverChildBuilderDelegate(
                            (context, index) {
                              return ListTile(
                                title: Text('index $index'),
                              );
                            },
                            childCount: 10
                          ),
                        )
                       ]
                    ),
                  ],
                ),
              ),
            ),
            Container(
              height: 30,
//               child: 
            )
          ],
        ),
      ),
    );
  }
}

NestedScrollView is messing up here. NestedScrollView在这里搞砸了。 Since, you're not using headerSliverBuilder , you can just remove the widget entirely.由于您没有使用headerSliverBuilder ,因此您可以完全删除小部件。 Here's the working code.这是工作代码。

@override
Widget build(BuildContext context) {
  return Material(
    child: PageView(
      children: <Widget>[
        CustomScrollView(
          slivers: [
            SliverList(
              delegate: SliverChildBuilderDelegate(
                (context, index) => ListTile(title: Text('index $index')),
                childCount: 20,
              ),
            )
          ],
        ),
        CustomScrollView(
          slivers: [
            SliverList(
              delegate: SliverChildBuilderDelegate(
                (context, index) => ListTile(title: Text('index $index')),
                childCount: 20,
              ),
            )
          ],
        ),
      ],
    ),
  );
}

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

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