I have to implement elevation (like a shadow) on an image widget, but I couldn't find a solution to this. Is there a way to implement elevation to an image?
An image example of what I want to remove:
I used the Material
widget, but it renders empty space!! The original image has no spaces, how can I remove them?
To change the elevation of AlertDialog in Flutter, set the elevation property of AlertDialog with an integer value. Elevation is the amount by which the AlertDialog is raised from the background screen, making shadow like effect.
we can use ElevatedButton. styleFrom and this property has shadowColor Property with Elevation property. so you can simply give shadow with elevation in ElevatedButton.
To set specific height for Image widget in Flutter Application, set height property of Image object with required double value. In the following example, we create a Flutter Application with two Image widgets. The height of first Image widget is set to 100, and the height of second Image widget is set to 200.
In this example, we are going to show you the easiest way to set auto aspect ratio on Image size in Flutter App. We will use AspectRatio () widget to achieve aspect ratio on the Image widget in Flutter. In this way, you can set the Aspect Ratio on the Image widget in Flutter.
While in Android the images must be stored in res/drawable folder by default, in Flutter you can define where the images are stored. What you need to do is adding a list of image paths or a list of directories that contain images in pubspec.yaml file.
Unfortunately there is no elevation property for Container, you need to use other Widget such as Card, but if you really do want to give Container an elevation property, you could take a look at division and watch this tutorial about using that package. Division: Simple to use yet powerfull style widgets with syntax inspired by CSS.
You can simply use the Material
or the Card
widget:
Center(
child: Material( // with Material
child: Image.network('https://placeimg.com/640/480/any'),
elevation: 18.0,
shape: const CircleBorder(),
clipBehavior: Clip.antiAlias,
),
),
Center(
child: Card( // with Card
child: Image.network('https://placeimg.com/640/480/any'),
elevation: 18.0,
shape: const CircleBorder(),
clipBehavior: Clip.antiAlias,
),
),
If you want more control on the Radius
of the Image. Then you can use CircleAvatar
:
Center(
child: Card(
child: CircleAvatar(
maxRadius: 54.0,
backgroundImage:
NetworkImage('https://placeimg.com/640/480/any'),
),
elevation: 18.0,
shape: const CircleBorder(),
clipBehavior: Clip.antiAlias,
),
),
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With