PrismAvatar class

A circular or rounded avatar with initials fallback, presence and status.

Handles the three cases every app hits: an image that loads, an image that fails, and a user with no image at all. Initials are derived from the name automatically and the background color is picked deterministically from the name, so the same person always looks the same.

PrismAvatar(name: 'Ayesha Khan')
PrismAvatar(name: 'Ayesha Khan', imageUrl: user.photoUrl, size: 56)
PrismAvatar(name: 'Ayesha Khan', presence: PrismPresence.online)
Inheritance

Constructors

PrismAvatar({Key? key, required String name, String? imageUrl, ImageProvider<Object>? image, double size = 40, PrismAvatarShape shape = PrismAvatarShape.circle, Color? backgroundColor, Color? foregroundColor, PrismPresence? presence, Widget? badge, String? initialsOverride, String? semanticLabel, double borderWidth = 0, Color? borderColor})
Creates an avatar.
const

Properties

backgroundColor → Color?
Fallback background; defaults to a deterministic palette color.
final
badge → Widget?
Optional widget layered at the bottom-end corner (e.g. a count badge).
final
borderColor → Color?
Ring color; defaults to the theme surface.
final
borderWidth → double
Ring width drawn around the avatar.
final
foregroundColor → Color?
Fallback text color; defaults to a color that contrasts the background.
final
hashCode → int
The hash code for this object.
no setterinherited
image → ImageProvider<Object>?
In-memory image provider, useful for locally picked photos.
final
imageUrl → String?
Network image URL. Falls back to initials if it fails to load.
final
initialsOverride → String?
Overrides the computed initials.
final
key → Key?
Controls how one widget replaces another widget in the tree.
finalinherited
name → String
Display name. Used for initials, color selection and the a11y label.
final
presence → PrismPresence?
Optional presence dot.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
semanticLabel → String?
Accessibility label; defaults to the name plus presence.
final
shape → PrismAvatarShape
Circle by default; choose PrismAvatarShape.rounded for app icons.
final
size → double
Avatar diameter (or width for non-circular shapes).
final

Methods

build(BuildContext context) → Widget
Describes the part of the user interface represented by this widget.
override
createElement() → StatelessElement
Creates a StatelessElement to manage this widget's location in the tree.
inherited
debugDescribeChildren() → List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) → String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) → String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String
Returns a one-line detailed description of the object.
inherited
toStringShort() → String
A short, textual description of this widget.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Methods

colorFor(BuildContext context, String name) → Color
Deterministically picks a stable background color for name from the theme's tonal palette.
initialsFor(String name, {int max = 2}) → String
Derives up to two uppercase initials from name.
onColorFor(Color background) → Color
A foreground color that reads well on background.