Exception has occurred.
FlutterError (A RenderViewport expected a child of type RenderSliver but received a child of type RenderRepaintBoundary.
RenderObjects expect specific types of children because they coordinate with their children during layout and paint. For example, a RenderSliver cannot be the child of a RenderBox because a RenderSliver does not understand the RenderBox layout protocol.
The RenderViewport that expected a RenderSliver child was created by:
Viewport ← IgnorePointer-[GlobalKey#4d030] ← Semantics ← Listener ← _GestureSemantics ← RawGestureDetector-[LabeledGlobalKey<RawGestureDetectorState>#5be01] ← Listener ← _ScrollableScope ← _ScrollSemantics-[GlobalKey#c19df] ← NotificationListener<ScrollMetricsNotification> ← RepaintBoundary ← CustomPaint ← ⋯
The RenderRepaintBoundary that did not match the expected child type was created by:
RepaintBoundary ← NotificationListener<ScrollNotification> ← GlowingOverscrollIndicator ← Scrollable ← CustomScrollView ← Viewport ←
The above error is given by below code.I have written customScrollView inside another customScrollview.The second customScrollView is giving the error.Whenever i write without second customscrollview the code executed,but with second customscrollview the error is occured.I have tried with and without RepaintBoundary,sliverToBoxAdapter,but again again same error occur
code:
CustomScrollView(
slivers: [
SliverAppBar(
floating: true,
pinned: true,
automaticallyImplyLeading: false,
elevation: 0,
backgroundColor: Colors.white,
bottom: PreferredSize(preferredSize: Size.fromHeight(48),
child: Container(
padding: EdgeInsets.only(bottom: 10),
height: 80,
child: TabBar(
isScrollable: true,
controller: _controller,
tabs: [
Tab(
child: tab(text: "tab1",conIn:_controller.index,index:0)
,),
Tab(child: tab(text: "tab2",conIn:_controller.index,index:1)
,),
Tab(child: tab(text: "tab3",conIn:_controller.index,index:2)
,),
]),
),),
),
CustomScrollView(
slivers: [
TabBarView(
controller: _controller,
children: [
RepaintBoundary(
child: SliverList(
delegate: SliverChildBuilderDelegate(
(context, index) {
return Text("");
},
childCount: 4,
),
),
),
RepaintBoundary(
child: SliverList(
delegate: SliverChildBuilderDelegate(
(context, index) {
return Text("");
},
childCount: 4,
),
),
),
RepaintBoundary(
child: SliverList(
delegate: SliverChildBuilderDelegate(
(context, index) {
return Text("");
},
childCount: 4,
),
),
),
],
),
],
),
],
),
App structure is:
-
scaffold
-
customScrollView
-
sliverAppBar
-
SliverToBoxAdapter
-
Container
-
TabbarView
-
RepaintBoundary
-
SliverList
List item
2
Answers
the
slivers
accepts widgets from theSliver
widgets family, such asSliverList
,SliverPadding
…, but you’re adding directly a non-silver’s, even if it contains inside of it a sliver one, you need to expose a sliver directly inslivers
.There is a
SliverToBoxAdapter()
that adapts any Flutter widget to be used inside as a sliver, just wrap theRepaintBoundary
with it like this:You can use ListView.builder with repaintBoundary