Circular avatar with border

Flutter tips Published on

The Challenge with CircleAvatar

Flutter's CircleAvatar widget is great for showing circular images or user initials, but it doesn't come with a built-in way to add a border directly. If you need that extra visual touch, you might think you need a complex custom solution.

The Quick Trick for Borders

Luckily, there's a super simple trick to add a border without having to rewrite the CircleAvatar widget from scratch. The secret? You just wrap it!

Wrapping with Another CircleAvatar

One easy method is to wrap your main CircleAvatar inside another CircleAvatar. The outer one will act as the border.

Here's how it looks in code:

CircleAvatar(
  radius: radius + 2, // Make the outer circle a little bigger
  backgroundColor: borderColor, // This is the border color
  child: CircleAvatar( // This is your original avatar
    radius: radius, // Keep the inner circle the original size
    backgroundImage: NetworkImage(url), // Your image or child goes here
  ),
);

How This Code Works

The outer CircleAvatar is given a radius that's slightly larger than your main avatar's radius (like radius + 2). Its backgroundColor becomes the color you want for your border. The inner CircleAvatar is your actual avatar content (image or child) with the original radius. Because the outer one is bigger and has a background color, it shows up as a ring around your inner avatar – effectively creating a border!

Using a Container for More Styles

If you need more fancy border styles, like gradients or different shapes, you can also wrap your CircleAvatar inside a Container and use its decoration property. This gives you even more flexibility over the appearance.

This simple wrapping technique is a fast and clean way to give your circular avatars a border in Flutter.

Save 3 months of work

Create your app using our 6 years of making Flutter apps and more than 50+ apps

kickstarter for flutter apps

Frequently Asked Questions

Does Flutter's CircleAvatar widget have a built-in border property?

No, the default CircleAvatar does not have a property to add a border directly.

What is a simple way to add a border effect to a CircularAvatar?

You can wrap the CircleAvatar inside another widget, like another CircleAvatar or a Container, to simulate a border.

How does wrapping with another CircleAvatar create a border?

The outer CircleAvatar is given a slightly larger radius and set to the border color. The inner CircleAvatar (the original one) sits on top, showing the image, while the outer one's background forms the border around it.

Can I use a Container instead of another CircleAvatar for the border?

Yes, wrapping with a Container gives you more flexibility for borders, gradients, and other decorations.

Read more
You may also be interested in
Go Beyond Material: Add Custom Colors in your Flutter Theme  blog card image
Go Beyond Material: Add Custom Colors in your Flutter Theme
Published on 2025-05-12T08:49:42.146Z
Center a form Without hiding fields when keyboard is open  blog card image
Center a form Without hiding fields when keyboard is open
Published on 2025-05-13T07:05:30.629Z
ApparenceKit is a flutter template generator tool by Apparence.io © 2025.
All rights reserved