0

我正在尝试使用 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),
              ),
            ],
          ),
        )
      ],
    ));
  }

这些是我的错误:

颤振:引发了另一个异常:水平视口被赋予了无限的高度。颤振:引发另一个异常:未布置 RenderBox:RenderViewport#fee96 NEEDS-LAYOUT NEEDS-PAINT 颤动:引发了另一个异常:未布置 RenderBox:RenderViewport#fee96 NEEDS-PAINT 颤动:引发了另一个异常:RenderBox 是未布置:RenderIgnorePointer#ab99e relayoutBoundary=up7 NEEDS-PAINT 颤动:引发了另一个异常:RenderBox 未布置:RenderSemanticsAnnotations#4a391 relayoutBoundary=up6 NEEDS-PAINT 颤动:引发了另一个异常:RenderBox 未布置:RenderPointerListener# c322e relayoutBoundary=up5 NEEDS-PAINT 颤动:引发了另一个异常:RenderBox 未布置:RenderSemanticsGestureHandler#4f759 relayoutBoundary=up4 NEEDS-PAINT 颤动:引发了另一个异常:未布置 RenderBox:RenderPointerListener#fa8f5 relayoutBoundary=up3 NEEDS-PAINT 颤动:引发了另一个异常:未布置 RenderBox:_RenderScrollSemantics#c84ee relayoutBoundary=up2 NEEDS-PAINT 颤动:引发了另一个异常:NoSuchMethodError :在 null 上调用了方法“debugAssertIsValid”。⣽flutter:引发了另一个异常:NoSuchMethodError:在 null 上调用了 getter 'visible'。在 null 上调用。⣽flutter:引发了另一个异常:NoSuchMethodError:在 null 上调用了 getter 'visible'。在 null 上调用。⣽flutter:引发了另一个异常:NoSuchMethodError:在 null 上调用了 getter 'visible'。

4

1 回答 1

0

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

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

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

希望能帮到你

于 2019-07-16T08:05:29.930 回答