Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter CircleAvatar backgroundImage not filling up the circle

I am using a CircleAvatar with a backgroundImage property to load an image took from a camera but the image shown does not fill the entire circle avatar. It looks like a rectangular image in a circle.

How do I make the image expand to cover the circle avatar? Thanks.

like image 295
Edmand Looi Avatar asked Apr 18 '18 18:04

Edmand Looi


People also ask

How do I increase my circle Avatar size in flutter?

To change the avatar size, you can use radius property. There are two other properties related to size: minRadius and maxRadius . The are used to set the minimum and maximum radius respectively. If you alredy use radius , you are not allowed to use minRadius and/or maxRadius .

How do you use a circular avatar in flutter?

This property applies a background image to the CircleAvatar widget. child: The child property takes the widget to be placed below the CircleAvatar widget inside the widget tree or the widget to be displayed inside the circle. foregroundColor: This property holds the Color class (final) as the parameter value.


2 Answers

You can always create an image and manually clip it:

ClipOval(
  child: Image.network(
    "url.jpg",
    fit: BoxFit.cover,
    width: 90.0,
    height: 90.0,
  )
),
like image 195
Ian Avatar answered Sep 17 '22 17:09

Ian


If you are using a local image from asset then you can use CircleAvatar as,

CircleAvatar(
          backgroundImage: ExactAssetImage('assets/images/cook.jpeg'),
          // Optional as per your use case
          // minRadius: 30,
          // maxRadius: 70,
        ),

If you are using a network image then you can use CircleAvatar as,

CircleAvatar(
     radius: 30.0,
     backgroundImage: NetworkImage(imageURL),
     backgroundColor: Colors.transparent,
     ));
like image 29
Ameer Avatar answered Sep 17 '22 17:09

Ameer