如何使图像在堆栈中可见溢出容器区域在 Flutter

4xy9mtcn  于 2023-03-31  发布在  Flutter
关注(0)|答案(2)|浏览(85)

我在堆栈中有一个容器和圆形头像。头像被放置在顶部中心对齐,并被定位为用作容器边界上的覆盖图像。但是图像在溢出容器边界时消失了。是否有任何小部件可以用来产生所需的结果?

Stack(
          alignment: Alignment.topCenter,
          children: [
            Container(
              height: screenWidth / 1.25,
              width: screenWidth / 1.4,
              decoration: BoxDecoration(
                color: kAppBarColor,
                borderRadius: BorderRadius.circular(12.0),
              ),
              child: Column(
                children: [
                  const SizedBox(height: 45.0),
                  Text(
                    'Joey',
                    style: kTitleTextStyle.copyWith(
                      fontSize: 22.0,
                      fontWeight: FontWeight.w500,
                    ),
                  ),
                  const SizedBox(height: 3.0),
                  Text(
                    'WhatsApp contact',
                    style: kSubTitleTextStyle.copyWith(fontSize: 12.0),
                  ),
                  const SizedBox(height: 10.0),
                  SizedBox(
                    height: 210.0,
                    width: 210.0,
                    child: Image.asset(
                      'images/qr_whatsapp.jpg',
                      scale: 1.2,
                    ),
                  ),
                  const SizedBox(height: 5.0),
                ],
              ),
            ),
            const Positioned(
              top: -20,
              child: CircleAvatar(
                radius: 25.0,
                backgroundImage: AssetImage('images/p1.jpg'),
              ),
            )
          ],
        ),

w8ntj3qf

w8ntj3qf1#

你在堆栈中有一个clipBehavior属性,你可以尝试它来解决这个问题。

Stack(
  clipBehavior: Clip.none,
    ...rest of your code
)
e0bqpujr

e0bqpujr2#

ClipOval Package CircleAvatar,如下所示:

Stack(
  alignment: Alignment.topCenter,
  children: [
    Container(
      height: screenWidth / 1.25,
      width: screenWidth / 1.4,
      decoration: BoxDecoration(
        color: kAppBarColor,
        borderRadius: BorderRadius.circular(12.0),
      ),
      child: Column(
        children: [
          const SizedBox(height: 45.0),
          Text(
            'Joey',
            style: kTitleTextStyle.copyWith(
              fontSize: 22.0,
              fontWeight: FontWeight.w500,
            ),
          ),
          const SizedBox(height: 3.0),
          Text(
            'WhatsApp contact',
            style: kSubTitleTextStyle.copyWith(fontSize: 12.0),
          ),
          const SizedBox(height: 10.0),
          SizedBox(
            height: 210.0,
            width: 210.0,
            child: Image.asset(
              'images/qr_whatsapp.jpg',
              scale: 1.2,
            ),
          ),
          const SizedBox(height: 5.0),
        ],
      ),
    ),
    Positioned(
      top: -20,
    // this is changed
      child: ClipOval(
        child: CircleAvatar(
          radius: 25.0,
          backgroundImage: AssetImage('images/p1.jpg'),
        ),
      ),
    )
  ],
)

相关问题