Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.7k views
in Technique[技术] by (71.8m points)

flutter - Making an Image widget disabled / grayed out

I have a bunch of Image widgets which when in a disabled state, should look grayed out.

Is there a way to alter an existing image make it look disabled / grayed out?

I want to avoid having both an enabled image asset and a disabled image asset increasing the overall APK size instead of having the single asset.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Set the widget as the child of a container, and add foregroundDecoration like this:

Container(
  foregroundDecoration: BoxDecoration(
    color: Colors.grey,
    backgroundBlendMode: BlendMode.saturation,
  ),
  child: child,
)

-- Update: Based on this new video from flutter team, there is another widget for this. The code is basically the same, and it is like this:

ColorFiltered(
  colorFilter: ColorFilter.mode(
    Colors.grey,
    BlendMode.saturation,
  ),
  child: child,
)

But I still prefer the method using Container forgroundDecoration, since container gives you more flexibilities in the same place.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...