Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to give elevation to an image in Flutter?

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: 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?

like image 308
Privacy of Animal Avatar asked Feb 18 '19 08:02

Privacy of Animal


People also ask

How do you change the elevation in Flutter?

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.

How do you give color elevation in Flutter?

we can use ElevatedButton. styleFrom and this property has shadowColor Property with Elevation property. so you can simply give shadow with elevation in ElevatedButton.

How to set specific height for image widget in flutter application?

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.

How to set aspect ratio on image size in Flutter App?

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.

Where are images stored 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.

Is there a way to add elevation to a container?

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.


Video Answer


1 Answers

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,
  ),
),
like image 139
anmol.majhail Avatar answered Oct 16 '22 06:10

anmol.majhail