Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter Network Image does not fit in Circular Avatar

I am trying to retrieve bunch of images from an api. I want the images to be displayed in Circular form so I am using CircleAvatar Widget, but I keep getting images in square format. Here is a screenshot of images

enter image description here

Here is the code I am using

ListTile(leading: CircleAvatar(child: Image.network("${snapshot.data.hitsList[index].previewUrl}",fit: BoxFit.scaleDown,)),),

I tryied using all the properties of BoxFit like cover, contain,fitWidth,fitHeight etc but none of them works.

like image 707
Pritish Avatar asked Nov 28 '18 06:11

Pritish


People also ask

How do I set the network image in CircleAvatar in flutter?

How to set Network image in circle avatar in flutter ? to set Network image in circle avatar in flutter use CircleAvatar we need to define our Network OR Asset Image in backgroundImage property. also, give radius that will our image radius.

Why is my network image not showing up on flutter?

“flutter network image not showing” Code Answer'sTry to add internet permission in android folder(do nothing with IOS part). Or jsut reinstall app.


3 Answers

This Will Work : You need to use backgroundImage:property in order to fit it in Circle.

CircleAvatar(
                radius: 30.0,
                backgroundImage:
                    NetworkImage("${snapshot.data.hitsList[index].previewUrl}"),
                backgroundColor: Colors.transparent,
              )

To Check with Dummy Placeholder:

CircleAvatar(
                radius: 30.0,
                backgroundImage:
                    NetworkImage('https://via.placeholder.com/150'),
                backgroundColor: Colors.transparent,
              )
like image 79
anmol.majhail Avatar answered Oct 12 '22 23:10

anmol.majhail


Had a similar problem in the AppBar actions widget list.

This worked for me:

CircleAvatar(
    radius: 18,
    child: ClipOval(
        child: Image.network(
          'image-url',
        ),
    ),
),
like image 37
michaelbn Avatar answered Oct 12 '22 23:10

michaelbn


If you don't want to use CircleAvatar, here is how you can do it.

ClipOval(
  child: Image.network(
    'https://via.placeholder.com/150',
    width: 100,
    height: 100,
    fit: BoxFit.cover,
  ),
),
like image 41
CopsOnRoad Avatar answered Oct 13 '22 00:10

CopsOnRoad