@@ -17,8 +17,13 @@ import 'theme_data.dart';
1717/// such an image, the user's initials. A given user's initials should
1818/// always be paired with the same background color, for consistency.
1919///
20+ /// If [foregroundImage] fails then [backgroundImage] is used. If
21+ /// [backgroundImage] fails too, [backgroundColor] is used.
22+ ///
2023/// The [onBackgroundImageError] parameter must be null if the [backgroundImage]
2124/// is null.
25+ /// The [onForegroundImageError] parameter must be null if the [foregroundImage]
26+ /// is null.
2227///
2328/// {@tool snippet}
2429///
@@ -60,13 +65,16 @@ class CircleAvatar extends StatelessWidget {
6065 this .child,
6166 this .backgroundColor,
6267 this .backgroundImage,
68+ this .foregroundImage,
6369 this .onBackgroundImageError,
70+ this .onForegroundImageError,
6471 this .foregroundColor,
6572 this .radius,
6673 this .minRadius,
6774 this .maxRadius,
6875 }) : assert (radius == null || (minRadius == null && maxRadius == null )),
6976 assert (backgroundImage != null || onBackgroundImageError == null ),
77+ assert (foregroundImage != null || onForegroundImageError== null ),
7078 super (key: key);
7179
7280 /// The widget below this widget in the tree.
@@ -95,13 +103,24 @@ class CircleAvatar extends StatelessWidget {
95103 /// The background image of the circle. Changing the background
96104 /// image will cause the avatar to animate to the new image.
97105 ///
106+ /// Typically used as a fallback image for [foregroundImage] .
107+ ///
98108 /// If the [CircleAvatar] is to have the user's initials, use [child] instead.
99109 final ImageProvider ? backgroundImage;
100110
111+ /// The foreground image of the circle.
112+ ///
113+ /// Typically used as profile image. For fallback use [backgroundImage] .
114+ final ImageProvider ? foregroundImage;
115+
101116 /// An optional error callback for errors emitted when loading
102117 /// [backgroundImage] .
103118 final ImageErrorListener ? onBackgroundImageError;
104119
120+ /// An optional error callback for errors emitted when loading
121+ /// [foregroundImage] .
122+ final ImageErrorListener ? onForegroundImageError;
123+
105124 /// The size of the avatar, expressed as the radius (half the diameter).
106125 ///
107126 /// If [radius] is specified, then neither [minRadius] nor [maxRadius] may be
@@ -217,6 +236,16 @@ class CircleAvatar extends StatelessWidget {
217236 : null ,
218237 shape: BoxShape .circle,
219238 ),
239+ foregroundDecoration: foregroundImage != null
240+ ? BoxDecoration (
241+ image: DecorationImage (
242+ image: foregroundImage! ,
243+ onError: onForegroundImageError,
244+ fit: BoxFit .cover,
245+ ),
246+ shape: BoxShape .circle,
247+ )
248+ : null ,
220249 child: child == null
221250 ? null
222251 : Center (
0 commit comments