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
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.
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.
“flutter network image not showing” Code Answer'sTry to add internet permission in android folder(do nothing with IOS part). Or jsut reinstall app.
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,
)
Had a similar problem in the AppBar
actions widget list.
This worked for me:
CircleAvatar(
radius: 18,
child: ClipOval(
child: Image.network(
'image-url',
),
),
),
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,
),
),
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