ScrollView 内的 TabView 渲染错误 - Flutter

Posted

技术标签:

【中文标题】ScrollView 内的 TabView 渲染错误 - Flutter【英文标题】:TabView Render Error inside ScrollView - Flutter 【发布时间】:2020-11-28 20:50:02 【问题描述】:

我想显示一个TabView,它最终位于SingleChildScrollView 内。小部件树就像 -: Some_animation_widget > Safearea > SingleChildScrollView > Padding > Column > [ Row, TabViews]。

TabView 仅包含 2 个Text 小部件。但是,在构建项目时,我反复收到以下错误。我尝试了各种方法,包括 BoxConstraintsExpanded/Flexible 小部件,但没有结果。

错误

I/flutter ( 9005): ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
I/flutter ( 9005): The following assertion was thrown during performResize():
I/flutter ( 9005): Horizontal viewport was given unbounded height.
I/flutter ( 9005): Viewports expand in the cross axis to fill their container and constrain their children to match
I/flutter ( 9005): their extent in the cross axis. In this case, a horizontal viewport was given an unlimited amount of
I/flutter ( 9005): vertical space in which to expand.
I/flutter ( 9005):
I/flutter ( 9005): The relevant error-causing widget was:
I/flutter ( 9005):   TabBarView file:///D:/Story/story/lib/Code/code.dart:120:30
I/flutter ( 9005):
I/flutter ( 9005): When the exception was thrown, this was the stack:
I/flutter ( 9005): #0      RenderViewport.performResize.<anonymous closure> (package:flutter/src/rendering/viewport.dart:1289:15)
I/flutter ( 9005): #1      RenderViewport.performResize (package:flutter/src/rendering/viewport.dart:1301:6)
I/flutter ( 9005): #2      RenderObject.layout (package:flutter/src/rendering/object.dart:1746:9)
I/flutter ( 9005): #3      RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:111:13)
I/flutter ( 9005): #4      RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
I/flutter ( 9005): #5      RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:111:13)
I/flutter ( 9005): #6      RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
I/flutter ( 9005): #7      RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:111:13)
I/flutter ( 9005): #8      RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
I/flutter ( 9005): #9      RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:111:13)
I/flutter ( 9005): #10     RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
I/flutter ( 9005): #11     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:111:13)
I/flutter ( 9005): #12     RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
I/flutter ( 9005): #13     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:111:13)
I/flutter ( 9005): #14     RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
I/flutter ( 9005): #15     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:111:13)
I/flutter ( 9005): #16     RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
I/flutter ( 9005): #17     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:111:13)
I/flutter ( 9005): #18     RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
I/flutter ( 9005): #19     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:111:13)
I/flutter ( 9005): #20     RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
I/flutter ( 9005): #21     RenderFlex.performLayout (package:flutter/src/rendering/flex.dart:746:15)
I/flutter ( 9005): #22     RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
I/flutter ( 9005): #23     RenderFlex.performLayout (package:flutter/src/rendering/flex.dart:746:15)
I/flutter ( 9005): #24     RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
I/flutter ( 9005): #25     RenderPadding.performLayout (package:flutter/src/rendering/shifted_box.dart:207:11)
I/flutter ( 9005): #26     RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
I/flutter ( 9005): #27     _RenderSingleChildViewport.performLayout (package:flutter/src/widgets/single_child_scroll_view.dart:512:13)
I/flutter ( 9005): #28     RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
I/flutter ( 9005): #29     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:111:13)
I/flutter ( 9005): #30     RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
I/flutter ( 9005): #31     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:111:13)
I/flutter ( 9005): #32     RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
I/flutter ( 9005): #33     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:111:13)
I/flutter ( 9005): #34     RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
I/flutter ( 9005): #35     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:111:13)
I/flutter ( 9005): #36     RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
I/flutter ( 9005): #37     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:111:13)
I/flutter ( 9005): #38     RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
I/flutter ( 9005): #39     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:111:13)
I/flutter ( 9005): #40     RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
I/flutter ( 9005): #41     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:111:13)
I/flutter ( 9005): #42     RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
I/flutter ( 9005): #43     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:111:13)
I/flutter ( 9005): #44     RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
I/flutter ( 9005): #45     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:111:13)
I/flutter ( 9005): #46     RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
I/flutter ( 9005): #47     RenderPadding.performLayout (package:flutter/src/rendering/shifted_box.dart:207:11)
I/flutter ( 9005): #48     RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
I/flutter ( 9005): #49     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:111:13)
I/flutter ( 9005): #50     RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
I/flutter ( 9005): #51     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:111:13)
I/flutter ( 9005): #52     RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
I/flutter ( 9005): #53     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:111:13)
I/flutter ( 9005): #54     _RenderCustomClip.performLayout (package:flutter/src/rendering/proxy_box.dart:1248:11)
I/flutter ( 9005): #55     RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
I/flutter ( 9005): #56     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:111:13)
I/flutter ( 9005): #57     RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
I/flutter ( 9005): #58     RenderStack.layoutPositionedChild (package:flutter/src/rendering/stack.dart:487:11)
I/flutter ( 9005): #59     RenderStack.performLayout (package:flutter/src/rendering/stack.dart:583:30)
I/flutter ( 9005): #60     RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
I/flutter ( 9005): #61     MultiChildLayoutDelegate.layoutChild (package:flutter/src/rendering/custom_layout.dart:171:11)
I/flutter ( 9005): #62     _ScaffoldLayout.performLayout (package:flutter/src/material/scaffold.dart:484:7)
I/flutter ( 9005): #63     MultiChildLayoutDelegate._callPerformLayout (package:flutter/src/rendering/custom_layout.dart:240:7)
I/flutter ( 9005): #64     RenderCustomMultiChildLayoutBox.performLayout (package:flutter/src/rendering/custom_layout.dart:399:14)
I/flutter ( 9005): #65     RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
I/flutter ( 9005): #66     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:111:13)
I/flutter ( 9005): #67     RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
I/flutter ( 9005): #68     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:111:13)
I/flutter ( 9005): #69     _RenderCustomClip.performLayout (package:flutter/src/rendering/proxy_box.dart:1248:11)
I/flutter ( 9005): #70     RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
I/flutter ( 9005): #71     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:111:13)
I/flutter ( 9005): #72     RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
I/flutter ( 9005): #73     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:111:13)
I/flutter ( 9005): #74     RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
I/flutter ( 9005): #75     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:111:13)
I/flutter ( 9005): #76     RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
I/flutter ( 9005): #77     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:111:13)
I/flutter ( 9005): #78     RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
I/flutter ( 9005): #79     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:111:13)
I/flutter ( 9005): #80     RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
I/flutter ( 9005): #81     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:111:13)
I/flutter ( 9005): #82     RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
I/flutter ( 9005): #83     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:111:13)
I/flutter ( 9005): #84     RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
I/flutter ( 9005): #85     RenderOffstage.performLayout (package:flutter/src/rendering/proxy_box.dart:3223:14)
I/flutter ( 9005): #86     RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
I/flutter ( 9005): #87     _RenderTheatre.performLayout (package:flutter/src/widgets/overlay.dart:700:15)
I/flutter ( 9005): #88     RenderObject._layoutWithoutResize (package:flutter/src/rendering/object.dart:1630:7)
I/flutter ( 9005): #89     PipelineOwner.flushLayout (package:flutter/src/rendering/object.dart:887:18)
I/flutter ( 9005): #90     RendererBinding.drawFrame (package:flutter/src/rendering/binding.dart:402:19)
I/flutter ( 9005): #91     WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:884:13)
I/flutter ( 9005): #92     RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:284:5)
I/flutter ( 9005): #93     SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1113:15)
I/flutter ( 9005): #94     SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1052:9)
I/flutter ( 9005): #95     SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:968:5)
I/flutter ( 9005): #99     _invoke (dart:ui/hooks.dart:261:10)
I/flutter ( 9005): #100    _drawFrame (dart:ui/hooks.dart:219:3)
I/flutter ( 9005): (elided 3 frames from dart:async)
I/flutter ( 9005):
I/flutter ( 9005): The following RenderObject was being processed when the exception was fired: RenderViewport#7ed4e NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE:
I/flutter ( 9005):   needs compositing
I/flutter ( 9005):   creator: Viewport ← IgnorePointer-[GlobalKey#a40b7] ← Semantics ← _PointerListener ← Listener ←
I/flutter ( 9005):     _GestureSemantics ← RawGestureDetector-[LabeledGlobalKey<RawGestureDetectorState>#de5cd] ←
I/flutter ( 9005):     _PointerListener ← Listener ← _ScrollableScope ← _ScrollSemantics-[GlobalKey#c62fc] ←
I/flutter ( 9005):     RepaintBoundary ← ⋯
I/flutter ( 9005):   parentData: <none> (can use size)
I/flutter ( 9005):   constraints: BoxConstraints(0.0<=w<=391.4, 0.0<=h<=Infinity)
I/flutter ( 9005):   size: MISSING
I/flutter ( 9005):   axisDirection: right
I/flutter ( 9005):   crossAxisDirection: down
I/flutter ( 9005):   offset: _PagePosition#d3477(offset: null, range: null..null, viewport: null, ScrollableState,
I/flutter ( 9005):     _ForceImplicitScrollPhysics -> PageScrollPhysics -> PageScrollPhysics -> ClampingScrollPhysics ->
I/flutter ( 9005):     ClampingScrollPhysics, IdleScrollActivity#f271a, ScrollDirection.idle)
I/flutter ( 9005):   anchor: 0.0
I/flutter ( 9005): This RenderObject had the following descendants (showing up to depth 5):
I/flutter ( 9005):     center child: _RenderSliverFractionalPadding#527e3 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
I/flutter ( 9005):       child: RenderSliverFillViewport#2ff31 NEEDS-LAYOUT NEEDS-PAINT
I/flutter ( 9005): ════════════════════════════════════════════════════════════════════════════════════════════════════
I/flutter ( 9005): Another exception was thrown: RenderBox was not laid out: RenderViewport#7ed4e NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE       
I/flutter ( 9005): Another exception was thrown: RenderBox was not laid out: RenderViewport#7ed4e NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
I/flutter ( 9005): Another exception was thrown: RenderBox was not laid out: RenderIgnorePointer#7fd04 relayoutBoundary=up12 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
I/flutter ( 9005): Another exception was thrown: RenderBox was not laid out: RenderSemanticsAnnotations#adf40 relayoutBoundary=up11 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
I/flutter ( 9005): Another exception was thrown: RenderBox was not laid out: RenderPointerListener#cd057 relayoutBoundary=up10 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
I/flutter ( 9005): Another exception was thrown: RenderBox was not laid out: RenderSemanticsGestureHandler#60c5e relayoutBoundary=up9 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
I/flutter ( 9005): Another exception was thrown: RenderBox was not laid out: RenderPointerListener#37d6e relayoutBoundary=up8 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
I/flutter ( 9005): Another exception was thrown: RenderBox was not laid out: _RenderScrollSemantics#a9b96 relayoutBoundary=up7 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
I/flutter ( 9005): Another exception was thrown: RenderBox was not laid out: RenderRepaintBoundary#2b2ab relayoutBoundary=up6 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
I/flutter ( 9005): Another exception was thrown: RenderBox was not laid out: RenderCustomPaint#68de8 relayoutBoundary=up5 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
I/flutter ( 9005): Another exception was thrown: RenderBox was not laid out: RenderRepaintBoundary#d2635 relayoutBoundary=up4 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
I/flutter ( 9005): Another exception was thrown: RenderBox was not laid out: RenderFlex#a22ec relayoutBoundary=up3 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE   
I/flutter ( 9005): Another exception was thrown: RenderBox was not laid out: RenderFlex#1fa6d relayoutBoundary=up2 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE   
I/flutter ( 9005): Another exception was thrown: RenderBox was not laid out: RenderPadding#d21cf relayoutBoundary=up1 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATEI/flutter ( 9005): Another exception was thrown: RenderBox was not laid out: _RenderSingleChildViewport#5e409 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
I/flutter ( 9005): Another exception was thrown: RenderBox was not laid out: RenderIgnorePointer#9c280 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
I/flutter ( 9005): Another exception was thrown: RenderBox was not laid out: RenderSemanticsAnnotations#02268 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE        
I/flutter ( 9005): Another exception was thrown: RenderBox was not laid out: RenderPointerListener#3eb26 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
I/flutter ( 9005): Another exception was thrown: RenderBox was not laid out: RenderSemanticsGestureHandler#384eb NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE     
I/flutter ( 9005): Another exception was thrown: RenderBox was not laid out: RenderPointerListener#241c3 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
I/flutter ( 9005): Another exception was thrown: RenderBox was not laid out: _RenderScrollSemantics#c8403 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
I/flutter ( 9005): Another exception was thrown: RenderBox was not laid out: RenderRepaintBoundary#7a9c4 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
I/flutter ( 9005): Another exception was thrown: RenderBox was not laid out: RenderCustomPaint#ea52d NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
I/flutter ( 9005): Another exception was thrown: RenderBox was not laid out: RenderRepaintBoundary#81e47 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
I/flutter ( 9005): Another exception was thrown: RenderBox was not laid out: RenderPadding#e1b20 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
I/flutter ( 9005): Another exception was thrown: RenderBox was not laid out: _RenderInkFeatures#174d2 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
I/flutter ( 9005): Another exception was thrown: RenderBox was not laid out: RenderCustomPaint#97023 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
I/flutter ( 9005): Another exception was thrown: RenderBox was not laid out: RenderPhysicalShape#3274a NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
I/flutter ( 9005): Another exception was thrown: RenderBox was not laid out: RenderTransform#b1d97 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
I/flutter ( 9005): Another exception was thrown: RenderBox was not laid out: RenderTransform#b1d97

我的代码(仅显示小部件树)

child: Material(
                borderRadius: BorderRadius.all(
                    isCollapsed ? Radius.circular(0) : Radius.circular(25)),
                elevation: 8,
                child: SafeArea(
                  child: SingleChildScrollView(
                    child: Padding(
                      padding: EdgeInsets.fromLTRB(10, 8, 10, 10),
                      child: Column(
                        mainAxisSize: MainAxisSize.min,
                        crossAxisAlignment: CrossAxisAlignment.end,
                        children: <Widget>[
                          Row(
                            mainAxisAlignment: MainAxisAlignment
                                .spaceBetween,
                            crossAxisAlignment: CrossAxisAlignment.end,
                            children: <Widget>[
                              GestureDetector(
                                onTap: () 
                                  setState(() 
                                    if (isCollapsed)         // Some animation related stuff
                                      _controller.forward();
                                    else
                                      _controller.reverse();
                                    isCollapsed = !isCollapsed;
                                    print(isCollapsed);
                                  );
                                ,
                                child: Image.asset(
                                  isCollapsed? 'assets/menu.png': 'assets/back.png',
                                  width: size.width *
                                      (isCollapsed ? 0.08 : 0.1),),
                              ),
                              GestureDetector(
                                onTap: ()Navigator.pushReplacementNamed(context, '/');,
                                child: Image.asset('assets/logo.png',
                                  width: size.width * 0.2,),
                              ),
                              Image.asset('assets/profilePic.png',
                                width: size.width * 0.09,)
                            ],
                          ),


         // ->           /*
                         Here is the point where I am starting my Tab Bar view
                         */
                         
                          DefaultTabController(
                            length: 2,
                          child: Column(
                          mainAxisSize: MainAxisSize.min,
                          children: <Widget>[
                            TabBar(
                              tabs: <Widget>[
                                Tab(text: 'Tab1'),
                                Tab(text: 'Tab2'),
                              ],
                              labelColor: Colors.black,
                              indicatorColor: Colors.redAccent,
                            ),
                             TabBarView(
                                         children: [
                                       Text("Some Text"),
                                       Text("Some Text"),
                                         ],
                                 ),
                        
                              ],
                            ),
                          ),
                         ],
                      ),
                    ),
                  ),
                ),
              ),

一种解决方案可能是将 tabview 包含在固定高度的容器中,但如果我在 tabview 中有一些更大的子元素,这将导致溢出。如果有人可以提供解决方案,那将有很大帮助。提前致谢!

【问题讨论】:

【参考方案1】:

您可以使用NestedScrollView 并将TabView 设置为正文,将图像行设置为标题:

var _tabController;
  @override
  void initState() 
    super.initState();
    _tabController =  new TabController(length: 2, vsync: this);
  

  @override
  Widget build(BuildContext context) 
    return Scaffold(
      body: NestedScrollView(
        controller: _scrollController,
        headerSliverBuilder: (context, value) 
          return [
            SliverToBoxAdapter(child: Row(
              mainAxisAlignment: MainAxisAlignment
                  .spaceBetween,
              crossAxisAlignment: CrossAxisAlignment.end,
              children: <Widget>[
                GestureDetector(
                  onTap: () 
                    setState(() 
                      if (isCollapsed)         // Some animation related stuff
                        _controller.forward();
                      else
                        _controller.reverse();
                      isCollapsed = !isCollapsed;
                      print(isCollapsed);
                    );
                  ,
                  child: Image.asset(
                    isCollapsed? 'assets/menu.png': 'assets/back.png',
                    width: size.width *
                        (isCollapsed ? 0.08 : 0.1),),
                ),
                GestureDetector(
                  onTap: ()Navigator.pushReplacementNamed(context, '/');,
                  child: Image.asset('assets/logo.png',
                    width: size.width * 0.2,),
                ),
                Image.asset('assets/profilePic.png',
                  width: size.width * 0.09,)
              ],
            ),),
            
            SliverToBoxAdapter(
              child: TabBar(
                controller: _tabController,
                tabs: <Widget>[
                  Tab(text: 'Tab1'),
                  Tab(text: 'Tab2'),
                ],
                labelColor: Colors.black,
                indicatorColor: Colors.redAccent,
              ),
            ),
          ];
        ,
        body: Container(
          child: TabBarView(
            controller: _tabController,
            children: [
              Text("Some Text"),
              Text("Some Text"),
            ],
          ),
        ),
      ),
    );
  

【讨论】:

太棒了!谢谢莫比娜。我之前不知道这个小部件。太棒了。

以上是关于ScrollView 内的 TabView 渲染错误 - Flutter的主要内容,如果未能解决你的问题,请参考以下文章

TabView 内的条件

如何更新或读取 TabView 中的 GridLayout 内的文本字段

动态 TabView primefaces,选项卡渲染属性不起作用

SwiftUI:避免使用 MKMapView+UIViewRepresentable 在 TabView 中重新创建/重新渲染视图

SwiftUI - 如何将工具栏添加到 NavigationView 内的 TabView 选项卡?

ios 13 SwiftUI向后导航时如何避免导航视图内的TabView应用崩溃