Ad

Change Opacity Of Image In CachedNetworkImage Flutter

- 1 answer

Hello I have multiple images.

I want change the opacity of the image with the imageUrl.

My goal is that when user click on a image, it change his opacity.

My question is how to change the opacity while keeping the image ?

My CachedNetworkImage :

         CachedNetworkImage(
                imageUrl : _getImageUrl(),
                width: MediaQuery.of(context).size.width,
                height: MediaQuery.of(context).size.height,
                fit: BoxFit.cover,
                placeholder: (context, url) => const Center(child: CircularProgressIndicator()),
                errorWidget: (context, exception, stacktrace)
                {
                  return const Icon(Icons.warning);
                },
              )
Ad

Answer

You can wrap CachedNetworkImage with Opacity widget and provide opacity:x based on your need.

double _opacity =.3;
 ......

Opacity(
  opacity: _opacity.
  child:CachedNetworkImage(...)

More about Opacity.

Ad
source: stackoverflow.com
Ad