如何将 SliverGrid 集成到 TabBarView 中?

How do I integrate a SliverGrid inside a TabBarView?

我正在尝试使用 CustomScrollView 和 TabBar,但我不确定为什么我的实现不起作用。

我将 TabBar 包装在 SliverToBoxAdapter 中,但仍然没有成功。 以前我尝试过 GridView,但它给出了不需要的行为。

Widget build(BuildContext context) {
    return Scaffold(
        body: CustomScrollView(
      slivers: <Widget>[
        SliverToBoxAdapter(
          child: CarouselSlider(
            items: imgList.map((i) {
              return Builder(
                builder: (BuildContext context) {
                  return Container(
                    child: ClipRRect(
                      borderRadius: BorderRadius.all(Radius.circular(30.0)),
                      child: Image.network(
                        i,
                        fit: BoxFit.cover,
                        width: 1000.0,
                      ),
                    ),
                  );
                },
              );
            }).toList(),
            viewportFraction: 1.0,
            height: 300.0,
          ),
        ),
        SliverToBoxAdapter(
          child: Container(
            margin: EdgeInsets.all(10.0),
            child: Padding(
              padding: EdgeInsets.only(top: 10.0),
              child: Container(
                margin: EdgeInsets.only(left: 15.0, bottom: 15.0),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.start,
                  children: <Widget>[
                    Container(
                      child: CircleAvatar(
                        backgroundImage: AssetImage(
                            'assets/images/cut1.png'), // put image here
                        radius: 50,
                      ),
                    ),
                    Expanded(
                        child: Column(
                      children: <Widget>[
                        Text('Frank Palma',
                            style: TextStyle(
                              fontSize: 25,
                              fontWeight: FontWeight.bold,
                            )),
                        IconTheme(
                          data: IconThemeData(
                            color: Colors.amber,
                            size: 25,
                          ),
                          child: StarDisplay(value: 4),
                        ),
                        Text(
                          '546 Cuts',
                        ),
                      ],
                    ))
                  ],
                ),
              ),
            ),
          ),
        ),
        SliverToBoxAdapter(
            child: TabBar(
              controller: _tabcontroller,
              unselectedLabelColor: Colors.blue,
              indicator: BubbleTabIndicator(
                  indicatorHeight: 25.0,
                  indicatorColor: Colors.blue,
                  tabBarIndicatorSize: TabBarIndicatorSize.tab),
              tabs: <Widget>[
                Tab(icon: Icon(Icons.location_on)),
                Tab(icon: Icon(Icons.calendar_view_day)),
                Tab(icon: Icon(Icons.picture_in_picture))
              ],
            ),
        ),
        SliverToBoxAdapter(
          child: TabBarView(
            controller: _tabcontroller,
            children: [
              Center(
                  child: Card(
                    elevation: 15.0,
                    margin: EdgeInsets.all(10.0),
                    child: Container(
                      width: MediaQuery.of(context).size.width,
                      height: 200.0,
                      child: GoogleMap(
                          onMapCreated: _onMapCreated,
                          initialCameraPosition: CameraPosition(
                            target: _center,
                            zoom: 11.0,
                          )),
                    ),
                  ),
                ),
                Calendar(
                      isExpandable: true,
                      onSelectedRangeChange: (range) =>
                          print("Range is ${range.item1}, ${range.item2}"),
                      onDateSelected: (date) => print(date)),    
              SliverGrid(
                delegate: SliverChildBuilderDelegate((context, index) {
                  return Container(
                    child: FadeInImage.memoryNetwork(
                      placeholder: kTransparentImage,
                      image: 'https://picsum.photos/${300}/${300}/',
                    ),
                  );
                }, childCount: 10),
                gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                    crossAxisCount: 3),
              ),
            ],
          ),
        )
      ],
    ));
  }

这些是我的错误:

flutter: Another exception was thrown: Horizontal viewport was given unbounded height. flutter: Another exception was thrown: RenderBox was not laid out: RenderViewport#fee96 NEEDS-LAYOUT NEEDS-PAINT flutter: Another exception was thrown: RenderBox was not laid out: RenderViewport#fee96 NEEDS-PAINT flutter: Another exception was thrown: RenderBox was not laid out: RenderIgnorePointer#ab99e relayoutBoundary=up7 NEEDS-PAINT flutter: Another exception was thrown: RenderBox was not laid out: RenderSemanticsAnnotations#4a391 relayoutBoundary=up6 NEEDS-PAINT flutter: Another exception was thrown: RenderBox was not laid out: RenderPointerListener#c322e relayoutBoundary=up5 NEEDS-PAINT flutter: Another exception was thrown: RenderBox was not laid out: RenderSemanticsGestureHandler#4f759 relayoutBoundary=up4 NEEDS-PAINT flutter: Another exception was thrown: RenderBox was not laid out: RenderPointerListener#fa8f5 relayoutBoundary=up3 NEEDS-PAINT flutter: Another exception was thrown: RenderBox was not laid out: _RenderScrollSemantics#c84ee relayoutBoundary=up2 NEEDS-PAINT flutter: Another exception was thrown: NoSuchMethodError: The method 'debugAssertIsValid' was called on null. ⣽flutter: Another exception was thrown: NoSuchMethodError: The getter 'visible' was called on null.

当嵌套两个可滚动小部件时,我需要限制内部小部件的可滚动性。当我遇到这个问题时,解决方案是在内部小部件中添加代码:

ShrinkWrap: true, // Solve the problem of infinite height

Physics: NeverScrollable ScrollPhysics (), // Disable Sliding Events

希望能帮到你