简体   繁体   中英

How do I integrate a SliverGrid inside a TabBarView?

I am trying to use a CustomScrollView and a TabBar but I am unsure why my implementation does not work.

I wrapped the TabBar in a SliverToBoxAdapter and still no luck. Previously I tried a GridView but that was giving unwanted behavior.

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),
              ),
            ],
          ),
        )
      ],
    ));
  }

These are my errors:

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.

When nesting two scrollable widgets, I need to limit the scrollability of internal widget. When I encounter this problem, the solution is to add code to internal widget:

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

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

Hope to help you

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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