【问题标题】:unable to place container iside a stack inside scrollable sliverlist无法将容器放在可滚动的 sliverlist 内的堆栈中
【发布时间】:2021-08-14 18:03:53
【问题描述】:

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

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),
                ),
              ),
            ],
          )
        ])

I want a scrollable ui like this

【问题讨论】:

  • 你为什么不使用“CustomScrollView”并使用 SliverAppBar 作为图像部分。喜欢这个实现youtube.com/watch?v=R9C5KMJKluE&t=20s
  • 已经在coustomscrollview里面了。底部容器的位置没有改变

标签: flutter stack


【解决方案1】:

将您的 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),
            ),
          ),
        ],
      )
    ]),
    ),
  ],
);

【讨论】:

  • 定位的小部件在 singlechildscrollview 中不起作用。
【解决方案2】:

向容器添加边距解决了我的问题

 CustomScrollView(
              slivers: [
                appbar(context),
                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, fromHeight: true),
                            width: createSize(375, context),
                          ),
                          Container( margin: EdgeInsets.only(
                                top: createSize(320, context, fromHeight: true)),)

【讨论】:

    猜你喜欢
    • 2015-03-03
    • 2021-03-10
    • 1970-01-01
    • 2020-12-01
    • 2021-08-14
    • 1970-01-01
    • 1970-01-01
    • 2014-12-10
    • 1970-01-01
    相关资源
    最近更新 更多