我的错误是 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),
)
],
)
],
));
您必须使用 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),
)
],
),
),
您可以在
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,
),
],
),
],
),
)