Home > database >  Change opacity of image in CachedNetworkImage Flutter
Change opacity of image in CachedNetworkImage Flutter

Time:02-21

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

CodePudding user response:

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.

  • Related