无法将堆栈放入条子内。颤动

问题描述 投票:0回答:2

我的错误是 RenderViewport 需要 RenderSliver 类型的子级,但收到了 RenderStack 类型的子级。

Scaffold(
        body: CustomScrollView(
      slivers: [
        appbar(context),
        Stack(
          children: [
            Container(
              decoration: BoxDecoration(
                  image: DecorationImage(
                      image: NetworkImage(
                          'https://idsb.tmgrup.com.tr/ly/uploads/images/2020/05/13/35552.jpeg'))),
              height: createSize(347, context),
              width: createSize(375, context),
            )
          ],
        )
      ],
    ));
flutter stack
2个回答
2
投票

您必须使用 SliverToBoxAdapter 小部件在自定义滚动视图中呈现任何非 sliver 小部件,如下所示:

                    SliverToBoxAdapter(
                      child: Stack(
                        children: [
                          Container(
                            decoration: BoxDecoration(
                                image: DecorationImage(
                                    image: NetworkImage(
                                        'https://idsb.tmgrup.com.tr/ly/uploads/images/2020/05/13/35552.jpeg'))),
                            height: createSize(347, context),
                            width: createSize(375, context),
                          )
                        ],
                      ),
                    ),

0
投票

您可以在

SliverStack
中使用
CustomScrollView
,因为您需要使用 https://pub.dev/packages/sliver_tools 这个包

我分享示例代码

Scaffold(
  body: CustomScrollView(
    slivers: [
      SliverStack(
        children: [
          Container(
            decoration: const BoxDecoration(
              image: DecorationImage(
                image: NetworkImage(
                  'https://idsb.tmgrup.com.tr/ly/uploads/images/2020/05/13/35552.jpeg',
                ),
              ),
            ),
            height: 400,
            width: double.infinity,
          ),
        ],
      ),
    ],
  ),
)
© www.soinside.com 2019 - 2024. All rights reserved.