android - 如何将 SliverGrid 集成到 TabBarView 中?

标签 android ios flutter customscrollview

我正在尝试使用 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

希望能帮到你

关于android - 如何将 SliverGrid 集成到 TabBarView 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56783576/

相关文章:

Flutter Icons 小部件在 vscode 中没有预览

android - 使用 cygwin 下载 Android 源代码不起作用

android - 制作可以在 Windows/Linux 上执行任务的 Android 应用程序的任何建议/正确方法?

Android HTTPUrlConnection : how to set post data in http body?

android - 翻译 X 动画无论持续时间如何都会立即结束

iphone - iOS - 如何使用用户名和密码获取 twitter OAuthtoken

ios - 带有 firebase Google Sdk 的旧 iOS firebase 项目

android - Flutter 中即使应用已断开连接,如何查看日志?

http - 由于 '_InternalLinkedHashMap<String, dynamic>'不是 'Iterable<dynamic>'类型的子类型,反序列化失败

iphone - startMonitoringSignificantLocationChanges 是否可以终止我的应用程序