I have an image in my assets folder and want to set as background for circle Avatar how should I do this?
CircleAvatar(
backgroundImage: AssetImage('assets/image.png'),
);
This will work for you.
Make sure you have added an image in the asset folder and path inside pubspec.yaml file
like
assets:
- assets/image.png
Since you already have the Image in your Assets
folder.
1) Add it to your pubspec.yaml
file:
assets:
- assets/yourimage.png
2) Specify the image as the backgroundImage
of your CircleAvatar
:
CircleAvatar(
// the circle avatar has the background image property for specifying images
backgroundImage: AssetImage('assets/yourimage.png'),
);
Something like this?
CircleAvatar(
child: Image.network(
"https://miro.medium.com/proxy/1*ilC2Aqp5sZd1wi0CopD1Hw.png",
fit: BoxFit.scaleDown,
))
Something like this will give you a avatar with a background that will show while loading a network image
CircleAvatar(
backgroundColor: Colors.pink,
backgroundImage: AssetImage('/path/to/asset.png'),
child: Image.network('https://www.example.com/with/online.png')
);
Don't forget to put the path to the asset folder in your pubspec.yml
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.