9

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,
),

enter image description here

JAgüero
  • 403
  • 1
  • 4
  • 14

2 Answers2

21

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.

Md. Yeasin Sheikh
  • 54,221
  • 7
  • 29
  • 56
5

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

Dmitry Rodionov
  • 333
  • 2
  • 6