【问题标题】:How to give elevation to an image in Flutter?如何在 Flutter 中为图像赋予高度?
【发布时间】:2019-07-11 13:56:32
【问题描述】:

我必须在图像小部件上实现高程(如阴影),但我找不到解决方案。有没有办法实现图像的提升?

我要删除的图像示例:

我使用了Material 小部件,但它呈现空白空间!!原图没有空格,怎么去掉?

【问题讨论】:

标签: dart flutter elevation


【解决方案1】:

您可以简单地使用MaterialCard 小部件:

Center(
  child: Material( // with Material
    child: Image.network('https://placeimg.com/640/480/any'),
    elevation: 18.0,
    shape: CircleBorder(),
    clipBehavior: Clip.antiAlias,

  ),
),
Center(
  child: Card( // with Card
    child: Image.network('https://placeimg.com/640/480/any'),
    elevation: 18.0,
    shape: CircleBorder(),
    clipBehavior: Clip.antiAlias,

  ),
),

如果您想对图像的Radius 进行更多控制。然后就可以使用CircleAvatar

Center(
  child: Card(
    child: CircleAvatar(
      maxRadius: 54.0,
      backgroundImage:
          NetworkImage('https://placeimg.com/640/480/any'),
    ),
    elevation: 18.0,
    shape: CircleBorder(),
    clipBehavior: Clip.antiAlias,
  ),
),

【讨论】:

  • @PrivacyofAnimal 看起来您在两者之间使用了 padding 小部件。我的解决方案可以独立运行,您可以运行它们。 - 没有看到你的代码很难调试。
猜你喜欢
  • 2021-08-24
  • 2017-06-13
  • 1970-01-01
  • 2020-01-27
  • 2020-10-19
  • 1970-01-01
  • 2021-02-23
  • 2021-12-09
  • 1970-01-01
相关资源
最近更新 更多