I am trying to fit an image to the entire space, I am wrapping the Image.asset into an Expanded Widget but the image does not covers the entire space, I have used all the options in BoxFit enum and it doesnt really change the way the application looks. Does any of you has an idea what can be changed?
this is the code of the body inside the Scaffold:
body: Column(
children: [
Container(
width: MediaQuery.of(context).size.width,
color: Colors.brown[200],
padding: const EdgeInsets.all(20),
alignment: Alignment.center,
child: const Text('How I like my coffe...'),
),
Container(
color: Colors.brown[100],
padding: const EdgeInsets.all(20),
child: const CoffeePrefs(),
),
Expanded(
child: Image.asset(
'assets/coffee-beans-bg.jpg',
fit: BoxFit.fill, // Ensures the image fits the full width
),
),
],
And this is how it looks:
I have wraped the image inside a SizedBox, a FittedBox, and change the BoxFit enums.
2
Answers
The attributes
width
andheight
must be applied onImage
explicitly.You will find comments on flutter source code as follows.
/packages/flutter/lib/src/widgets/image.dart
Here is an example:
Add height and width to image