简体   繁体   中英

Change Image.asset opacity using opacity parameter in Image widget

I have a simple image that I want to put semi transparent. I have seen some methods to do it, but none of them was talking about the parameter opacity of the own Image.asset that accepts a widget of type Animation . Is it possible to change the opacity permanently with this parameter?

Image.asset(
  "assets/images/triangles_small.png",
  height: 380,
),

在此处输入图像描述

If you want to use parameter inside the Image widget, you can construct something like this:

Image.asset(
        "assets/images/triangles_small.png",
        height: 380,
        opacity: AnimationController(
            vsync: this,
            value: 0.5
        )
      ),

But it's better to use @Hippo Fish receipt, to wrap Image inside Opacity widget:

Opacity(
          opacity: 0.5,
          child: Image.asset(
            "image/link",
            height: 380,
            width: 380,
          ),
        )

Of cause you need to use mixin like

with SingleTickerProviderStateMixin

to use vsync: this

Actually, the question point using opcaity on Image.asset . You can use AlwaysStoppedAnimation

Image.asset(
  "image/link",
  opacity: const AlwaysStoppedAnimation(.5),

To have animation, you can pass animation here.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM