FlutterError(RenderViewport需要RenderSliver类型的子级,但收到RenderRepaintBoundary类型的子级

siotufzp  于 2023-02-09  发布在  Flutter
关注(0)|答案(2)|浏览(261)
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,
            ),
          ),
        ),
       
      ],
    ),
  ],
),



        ],
      ),

应用程序结构为:

  • 脚手架
  • 自定义滚动视图
  • 银应用程序栏
  • 薄片到盒适配器
  • 集装箱
  • 选项卡栏视图
  • 重绘边界
  • 银条列表

列表项

jvlzgdj9

jvlzgdj91#

您可以将ListView.builder与repaintBoundary一起使用

@override
Widget build(BuildContext context) {
  return Scaffold(
    body: CustomScrollView(
      slivers: [
        SliverAppBar(
          floating: true,
          pinned: true,
          automaticallyImplyLeading: false,
          elevation: 0,
          // backgroundColor: Colors.white,
          bottom: PreferredSize(
            preferredSize: Size.fromHeight(80),
            child: Container(
              padding: EdgeInsets.only(bottom: 10),
              height: 80,
              child: TabBar(
                isScrollable: true,
                controller: _controller,
                tabs: [
                  Tab(
                    child: Text("a"),
                  ),
                  Tab(
                    child: Text("a"),
                  ),
                ],
              ),
            ),
          ),
        ),
        SliverFillRemaining(
          child: TabBarView(
            controller: _controller,
            children: [
              RepaintBoundary(
                child: ListView.builder(
                  itemBuilder: (context, index) {
                    return Text("$index");
                  },
                  itemCount: 4,
                ),
              ),
              RepaintBoundary(
                child: ListView.builder(
                  itemBuilder: (context, index) {
                    return Text("$index");
                  },
                  itemCount: 4,
                ),
              ),
            ],
          ),
        ),
      ],
    ),
  );
}
y0u0uwnf

y0u0uwnf2#

slivers接受Sliver小部件系列中的小部件,例如SliverListSliverPadding ......,但您直接添加的是非银小部件,即使它内部包含银小部件,您也需要在slivers中直接公开银小部件。
有一个SliverToBoxAdapter()可以将任何Flutter小部件作为一个小块使用,只需将RepaintBoundary如下所示:

SliverToBoxAdapter(
  child: RepaintBounder(
   // ...
 ),
),

相关问题