首页 > 解决方案 > 如何在颤动中制作可调整的图像容器

问题描述

当容器的高度大于图像但覆盖范围不同时,图像应该覆盖。在 sliverappbar 上使用 boxfill 封面不会改变图像尺寸。

SliverAppBar(
      title: Text('SliverAppBar'),
      backgroundColor: Colors.green,
      expandedHeight: MediaQuery.of(context).size.height,
      flexibleSpace: FlexibleSpaceBar(
        background:
            Image.asset('assets/caesar-salad.png', fit: BoxFit.cover),
      ),
    ),

下面的图像是我希望实现的过渡,但是使用上面的代码,图像尺寸保持不变并且不会调整大小。

在此处输入图像描述

在此处输入图像描述

标签: flutterdartflutter-layoutflutter-animation

解决方案


解决了它;

 flexibleSpace: Container(
        decoration: BoxDecoration(
          image: DecorationImage(
              image: ExactAssetImage('assets/caesar-salad.png'),
              fit: BoxFit.cover),
        ),
      ),

推荐阅读