首页 > 解决方案 > 无法将容器放在可滚动的 sliverlist 内的堆栈中

问题描述

无法将容器放在可滚动银色列表内的堆栈中。我的代码是

SliverList(
            delegate: SliverChildListDelegate([
          Stack(
            children: [
              Container(
                decoration: BoxDecoration(
                    image: DecorationImage(
                        fit: BoxFit.cover,
                        image: NetworkImage(
                            'https://idsb.tmgrup.com.tr/ly/uploads/images/2020/05/13/35552.jpeg'))),
                height: createSize(347, context),
                width: createSize(375, context),
              ),
              Align(
                alignment: Alignment.bottomCenter,
                child: Container(
                  color: Colors.blue,
                  height: createSize(307, context),
                ),
              ),
            ],
          )
        ])

我想要一个像这样的可滚动用户界面

标签: flutterstack

解决方案


将您的 SliverList 放在 CustomScrollView 中,如下所示:

return CustomScrollView(
  slivers: [
    SliverList(
        delegate: SliverChildListDelegate([
      Stack(
        children: [
          Container(
            decoration: BoxDecoration(
                image: DecorationImage(
                    fit: BoxFit.cover,
                    image: NetworkImage(
                        'https://idsb.tmgrup.com.tr/ly/uploads/images/2020/05/13/35552.jpeg'))),
            height: createSize(347, context),
            width: createSize(375, context),
          ),
          Align(
            alignment: Alignment.bottomCenter,
            child: Container(
              color: Colors.blue,
              height: createSize(307, context),
            ),
          ),
        ],
      )
    ]),
    ),
  ],
);

推荐阅读