I’m trying to create an overlay above an image, which should match the size of the image no matter which size I give the Container.
This is my code I tried so far.
Container(
width: double.infinity,
height: double.infinity,
color: Colors.red,
child: Stack(
children: [
Image.memory(
snapshot.data!,
fit: BoxFit.contain,
),
Positioned.fill(
child: Container(
color: Colors.grey.withOpacity(0.5),
),
),
],
),
),
This results to this image (https://i.stack.imgur.com/eL3Ig.png)
I expect that the grey overlay matches the size of the image.
2
Answers
Give your Stack a fit: Stackfit.expand, so it expands to the Container size.
If this doesn’t work you can try it with a BoxDecoration – found here https://medium.com/ariel-mejia-dev/make-an-image-with-opacity-layer-in-flutter-fca77e453731
Move the
Stack
into aFittedBox
: