Flutter - AndroidStudio:如何将图像放置在容器下而不展开它?

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

我有一个使用粘性标题的列表。我想在每个标题下放置一个定制的阴影,所以我做了以下操作:

return StickyHeader(
      header: Material(
        color: Colors.transparent,
        child: Container(
          color: Colors.transparent,
          child: Column(
            mainAxisSize: MainAxisSize.min,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Container(
                color: AppColors.todaysTasks,
                height: 60.0,
                padding: EdgeInsets.symmetric(horizontal: spacing),
                alignment: Alignment.centerLeft,
                child: Text(
                  title,
                  style: FontStyles.taskListItemName.copyWith(color: Colors.black),
                ),
              ),
              Image.asset(
                'assets/images/BlurCropped.png',
              ),
            ],
          ),
        ),
      ),
      content: Column(

问题是我的影子扩展了标题的容器,并在每个标题和第一个任务之间创建了很大的边距。我提供了一张图片。请帮助我,我在这里迷路了。

我试图将阴影图像放在标题下,但它创建了一个奇怪的边距。

android flutter dart user-interface
1个回答
0
投票

由于您使用图像作为阴影,因此它不会覆盖在内容上。这里有两个解决方案:

  1. 使用
    decoration: BoxDecoration
    作为容器而不是图像(可以在此处找到示例:https://stackoverflow.com/a/52228086/13755145
  2. 或者,如果您想继续使用图像作为阴影,您可以在
    Stack
    中使用
    content
    并用
    Positioned
    包裹图像。 (可以在这里找到示例:https://stackoverflow.com/a/57233221/13755145

我会尝试使用第一种方法,因为定位不太容易。

© www.soinside.com 2019 - 2024. All rights reserved.