fluttercnfluttercn
Components

Avatar

Display user profile pictures with automatic fallbacks and status indicators

Installation

npx fluttercn@latest add avatar

Usage

Basic Avatar

Display an avatar with automatic fallback to initials:

Basic avatar component preview
// Network image with fallback
Avatar(
  imageUrl: 'https://example.com/avatar.jpg',
  fallbackName: 'John Doe',
)
 
// Asset image
Avatar(
assetPath: 'assets/avatar.png',
fallbackName: 'Jane Smith',
)
 
// Initials only
Avatar(
fallbackName: 'Alice Bob',
)
 

Sizes

Six predefined sizes from extra small to extra large:

Avatar sizes preview
Avatar(
  fallbackName: 'John Doe',
  size: AvatarSize.xs,  // 24px
)
 
Avatar(
  fallbackName: 'John Doe',
  size: AvatarSize.sm,  // 32px
)
 
Avatar(
  fallbackName: 'John Doe',
  size: AvatarSize.md,  // 40px (default)
)
 
Avatar(
  fallbackName: 'John Doe',
  size: AvatarSize.lg,  // 48px
)
 
Avatar(
  fallbackName: 'John Doe',
  size: AvatarSize.xl,  // 64px
)
 
Avatar(
  fallbackName: 'John Doe',
  size: AvatarSize.xl2, // 80px
)

Shapes

Avatars support both circular and rectangular shapes:

Avatar shapes preview
// Circle (default)
Avatar(
  fallbackName: 'John Doe',
  shape: BoxShape.circle,
)
 
// Rectangle with default radius
Avatar(
fallbackName: 'Jane Smith',
shape: BoxShape.rectangle,
)
 
// Rectangle with custom radius
Avatar(
fallbackName: 'Alice Bob',
shape: BoxShape.rectangle,
borderRadius: 8,
)
 

Status Indicator

Show online/offline status with a colored dot:

Avatar status indicator preview
// Online status (green)
Avatar(
  fallbackName: 'John Doe',
  showStatus: true,
  statusColor: AppTheme.success,
  statusPosition: StatusPosition.bottomRight,
)
 
// Busy status (red)
Avatar(
  fallbackName: 'Jane Smith',
  showStatus: true,
  statusColor: AppTheme.error,
  statusPosition: StatusPosition.bottomRight,
)
 
// Away status (yellow)
Avatar(
  fallbackName: 'Alice Bob',
  showStatus: true,
  statusColor: AppTheme.warning,
  statusPosition: StatusPosition.topRight,
)

Avatar Group

Display multiple avatars with overlap:

Avatar group preview
Avatar(fallbackName: 'Jane Smith'), Avatar(fallbackName: 'Alice Bob'),
Avatar(fallbackName: 'Bob Wilson'), Avatar(fallbackName: 'Carol Johnson'),
], max: 3, // Show 3 avatars + count size: AvatarSize.md, spacing: -8, //
Overlap amount ) ```
</Tab>
</Tabs>
 
## Examples
 
### User Profile Header
 
<Tabs items={['Preview', 'Code']}>
<Tab value="Preview">
<MobileScreenshot
  src="/previews/avatar/avatar_example.png"
  alt="User profile header example"
  width={360}
/>
</Tab>
<Tab value="Code">
```dart
Row(
children: [
Avatar(
  imageUrl: user.avatarUrl,
  fallbackName: user.name,
  size: AvatarSize.xl,
  showStatus: true,
  statusColor: user.isOnline ? AppTheme.success : AppTheme.textDisabled,
  onTap: () {
    Navigator.push(
      context,
      MaterialPageRoute(builder: (_) => ProfilePage(user)),
    );
  },
),
AppTheme.gapHorizontalLg,
Column(
  crossAxisAlignment: CrossAxisAlignment.start,
  children: [
    Text(user.name, style: AppTheme.titleLarge),
    Text(user.email, style: AppTheme.bodySmall),
  ],
),
],
)

API Reference

Avatar

PropertyTypeDefaultDescription
imageUrlString?nullNetwork image URL
assetPathString?nullAsset image path
fallbackNameString?nullName for generating initials
fallbackWidgetWidget?nullCustom fallback widget
sizeAvatarSizemdAvatar size
shapeBoxShapecircleAvatar shape (circle or rectangle)
borderRadiusdouble?nullCustom border radius (rectangle only)
showBorderboolfalseShow border around avatar
borderColorColor?nullBorder color
borderWidthdouble2.0Border width
showStatusboolfalseShow status indicator
statusColorColor?nullStatus indicator color (defaults to success green)
statusPositionStatusPositionbottomRightStatus indicator position
onTapVoidCallback?nullCallback when avatar is tapped

AvatarGroup

PropertyTypeDefaultDescription
avatarsList<Avatar>requiredList of avatars to display
maxint?nullMaximum avatars to show (rest shown as +N)
sizeAvatarSizemdSize for all avatars
spacingdouble-8.0Spacing between avatars (negative for overlap)
showBorderbooltrueShow border around avatars

AvatarSize

  • xs - 24px
  • sm - 32px
  • md - 40px (default)
  • lg - 48px
  • xl - 64px
  • xl2 - 80px

StatusPosition

  • topRight - Top right corner
  • topLeft - Top left corner
  • bottomRight - Bottom right corner (default)
  • bottomLeft - Bottom left corner

Features

  • Smart Fallbacks - Automatic fallback chain: network image → asset image → initials → default icon
  • Loading States - Built-in loading indicator for network images
  • Error Handling - Graceful fallback when images fail to load
  • Initials Generation - Automatic initials from names (e.g., "John Doe" → "JD")
  • Status Indicators - Optional colored dot for online/offline status
  • Avatar Groups - Display multiple avatars with overlap and count
  • Interactive - Optional tap handling with cursor feedback
  • Flexible Shapes - Circle or rounded rectangle with custom radius
  • Themed - Automatically adapts to light/dark mode

Network images show a loading spinner while loading. If loading fails, the avatar automatically falls back to initials or the default icon.

Do not use both imageUrl and assetPath together. Use one or the other for the image source.

Fallback Priority

When displaying an avatar, the component follows this fallback chain:

  1. Network Image (imageUrl) - If provided and loads successfully
  2. Asset Image (assetPath) - If network image fails or no URL provided
  3. Custom Fallback (fallbackWidget) - If custom widget provided
  4. Initials (fallbackName) - Generated from name (e.g., "John Doe" → "JD")
  5. Default Icon - Person icon if nothing else is available

This ensures your avatars always display something meaningful, even when images fail to load.