Reputation: 103
I am creating an AppBar for my application, but I am not able to insert an image in my CircleAvatar Button (this blue circle):
The code that I am using right now to create the CircleAvatar Button is the following one:
main.dart:
appBar: AppBar(
actions: <Widget>[
IconButton(
icon: CircleAvatar(
child: new Image.asset("assets/images/example.jpeg")),
onPressed: () {}),
]),
pubspec.yaml:
assets:
- assets/images/example.jpeg
I am trying to use this image:
So I would need to make this image appear and fit that blue CircleAvatar Button, but I cannot understand why it isn't working properly.
Can anyone help me with this problem?
P.S.: If anyone knows a package or code sample that asks the user to fit the image, in the way that he or she wants, it would be of great help to me, because I want the user to be able to fit the image in the perfect size. Like this for example:
The following error is happening:
Does anyone know how to solve it?
Upvotes: 1
Views: 1690
Reputation: 1
If you are using android studio, "Invalidate caches/restart" in "File" option will work.
Upvotes: 0
Reputation: 1580
You can use ClipRRect
widget
ClipRRect(
child: AssetImage("assets/images/example.jpeg"),
borderRadius: BorderRadius.circular(16)
)
Upvotes: 0
Reputation: 267404
Replace child
with backgroundImage
.
So, instead of using
CircleAvatar(
child: AssetImage("assets/images/example.jpeg"),
)
use
CircleAvatar(
backgroundImage: AssetImage("assets/images/example.jpeg"),
)
Upvotes: 3