Codewraith
Codewraith

Reputation: 103

IconButton CircleAvatar not showing image

I am creating an AppBar for my application, but I am not able to insert an image in my CircleAvatar Button (this blue circle):

enter image description here

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:

enter image description here

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:

enter image description here

The following error is happening:

enter image description here

Does anyone know how to solve it?

Upvotes: 1

Views: 1690

Answers (3)

Ashraf Shaikh
Ashraf Shaikh

Reputation: 1

If you are using android studio, "Invalidate caches/restart" in "File" option will work.

Upvotes: 0

Murat Aslan
Murat Aslan

Reputation: 1580

You can use ClipRRect widget

ClipRRect(
  child: AssetImage("assets/images/example.jpeg"),
  borderRadius: BorderRadius.circular(16)
)

Upvotes: 0

CopsOnRoad
CopsOnRoad

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

Related Questions