Why does my image lose its gradient in flutter? - flutter

So I was trying to create a welcome page when I got this problem. At first, everything was fine, but when I insert an image using DecorationImage, it looks like my image has an error in the color gradient. The real image look like this:
But when i run my app, i get this:
I use PageView.Builder in Scaffold to show my images. My code look like this:
return Scaffold(
body: PageView.builder(
scrollDirection: Axis.vertical,
itemCount: img.length,
itemBuilder: (_,index){
return Container(
width: double.maxFinite,
height: double.maxFinite,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(
"assets/image/"+img[index]
),
fit: BoxFit.cover
)
),
I put all my image names in a list and use the index to call each images.
The goldfish looks pretty much the same but the gradient at the bottom is disturbed. At first, I thought it was because I was using a low spec virtual device, but then I tried with a different virtual device and still got the same result. Why this happened? Does anyone know where I went wrong?
Edit: i try to add FilterQuality
return Container(
width: double.maxFinite,
height: double.maxFinite,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(
"assets/image/"+img[index]
),
fit: BoxFit.cover,
filterQuality:FilterQuality.high
)
),
But nothing happen. Did I put it wrong?

i tried using real device and it works, but i don't know why

Related

Set container width according to image.network widh in flutter?

i want to fix my container size(width) according to the image which is getting from api(image.network..).So, how can i go for this?
i am trying to set dynamic width of container according to image which i get from image.network() in flutter.
You will get overflow error in your device when the image was bigger than your device screen. I recommend you to use this
Container(
width: 100,
height: 100,
decoration: const BoxDecoration(
image: DecorationImage(
fit: BoxFit.cover,
image: NetworkImage(
'image link'),
),
),
),

how to change image opacity within Image() widget - flutter

So am trying to change image opacity using the opacity property i found in Image() widget, this is a short code to be clear :
Padding(
padding: EdgeInsets.all(10.0),
child: Center(
child: ClipRRect(
borderRadius: BorderRadius.circular(15),
child: Image(
image: NetworkImage(challengeImage),
fit: BoxFit.cover,
height: 150,
width: 350,
opacity: //not sure how to use
),
),
),
),
the image is a network image i retrieved from Firestore and am not sure what is the value i should put if its not double in order to apply opacity on the image. i thought to create a stack and insert asset image as a layer above my image and use the filter property but i would really like to know how the opacity can work with my code above, Thank you.
You can use AlwaysStoppedAnimation or create an Animation<double>
Image(
image: NetworkImage(""),
opacity: AlwaysStoppedAnimation(.1),
),
Another solution : wrap the widget with Opacity Widget
it accepts a double value in range [0,1] where 1 is fully displaying and 0 is not

Flutter - Change image opacity of decoration image in container not going smooth

I have two containers 'Stack'ed one on top of another.
Both use decorationImage as a background. The one on TOP looks like the following:
Container(
margin: const EdgeInsets.symmetric(horizontal: 8.0),
decoration: BoxDecoration(
color: Colors.transparent,
image: widget.imageAfter.isEmpty
? const DecorationImage(image: AssetImage('images/camera.png'))
: DecorationImage(
image: MemoryImage(base64Decode(widget.imageAfter)),
colorFilter: ColorFilter.mode(Colors.transparent.withOpacity(OPACITY), BlendMode.dstATop),
fit: BoxFit.cover),
border: Border.all(color: Colors.black, width: 1.0)
),
),
I change the value of opacity using a slider. when it goes 1, I can only see the image on top and at value 0 I can see the image at the bottom.
The problem I am facing is that the transition of the image transparency is not smooth when I am moving the slider. I get the result when I stop moving the slider but I am unable to see the transition in a smooth way. I guess this is because flutter is not able to draw the images in time. Is there way to do it?

Container decoration image bug in Flutter web

Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/images/btn-img.png'),
fit: BoxFit.cover,
),
),
...
),
The bug is that the image of the container widget is misplaced (a little bottom relative to Container's position). Does anyone have experienced same problem?
Update
when I use another image with larger height, it works fine (My current image height is 302px)
Update2
The problem seems to be with color filter, when I disable color filter it works fine.

Use a Map with AssetImage

I have a scenario where I would like to load an image based on the text that is chosen to be displayed on the app.
For example, I have a map that looks like this:
final _activity = const [
{'Activity': 'Rock Climbing','Image':'assets/images/rockclimbing.jpg'},
{'Activity': 'Running','Image':'assets/images/running.jpg'},
];
If I want to display the text related to an Activity in a Text Widget I can do the following:
Text(
activity[activityNumber]['Activity'],
),
However, I would also like to display the corresponding image, here is what I have tried that does not work:
decoration: BoxDecoration(
color: const Color(0xff7c94b6),
image: const DecorationImage(
image:AssetImage (activity[activityNumber]['Image']),
fit: BoxFit.cover,
),
I have also tried wrapping this in quotes, curly braces etc but I cannot make this work.
The way you are doing should work:
Container(
decoration: BoxDecoration(
color: const Color(0xff7c94b6),
image: DecorationImage(
image: AssetImage(_activity[activityNumber]['Image']),
fit: BoxFit.cover,
),
),
);
Have you considered using Image.asset? Something like: Image.asset(_activity[activityNumber]['Image'])