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 ←
上述错误由以下代码给出。我在另一个customScrollview中编写了customScrollView。第二个customScrollView给出了错误。每当我在没有第二个customScrollview的情况下编写代码时,代码会执行,但在有第二个customScrollview的情况下会出现错误。我尝试了使用和不使用RepaintBoundary、sliverToBoxAdapter的情况,但再次出现相同的错误
代码:
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,
),
),
),
],
),
],
),
],
),
应用程序结构为:
- 脚手架
- 自定义滚动视图
- 银应用程序栏
- 薄片到盒适配器
- 集装箱
- 选项卡栏视图
- 重绘边界
- 银条列表
列表项
2条答案
按热度按时间jvlzgdj91#
您可以将ListView.builder与repaintBoundary一起使用
y0u0uwnf2#
slivers
接受Sliver
小部件系列中的小部件,例如SliverList
、SliverPadding
......,但您直接添加的是非银小部件,即使它内部包含银小部件,您也需要在slivers
中直接公开银小部件。有一个
SliverToBoxAdapter()
可以将任何Flutter小部件作为一个小块使用,只需将RepaintBoundary
如下所示: