Avatar
In ProgressDark modeRTLA user image display with fallback initials or icon.
Installation
Copy the component into your project using the CLI:
$ronakcn add avatar
Usage
Import and use the component in your Flutter widget tree:
lib/pages/example.dart
import 'package:flutter/material.dart';
import '../components/avatar/avatar.dart';
class ExamplePage extends StatelessWidget {
const ExamplePage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('RcnAvatar Example')),
body: Center(
child: RcnAvatar(
// Configure props here
),
),
);
}
}Variants
Avatar ships with the following variants:
with-image
Shows a user profile image.
with-initials
Falls back to initials when no image.
with-fallback-icon
Shows a generic user icon fallback.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
imageUrl | String? | null | URL of the user image. |
initials | String? | null | Initials shown as fallback. |
size | double | 40 | Diameter of the avatar. |
fallbackIcon | Widget? | null | Icon shown when image is absent. |
Source files
lib/components/ui/avatar.dart
import 'package:flutter/material.dart';
class RcnAvatar extends StatelessWidget {
const RcnAvatar({super.key, this.imageUrl, this.initials, this.size = 40, this.fallbackIcon});
final String? imageUrl;
final String? initials;
final double size;
final Widget? fallbackIcon;
@override
Widget build(BuildContext context) {
final colors = Theme.of(context).colorScheme;
return Container(
width: size,
height: size,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: colors.secondary,
image: imageUrl != null ? DecorationImage(image: NetworkImage(imageUrl!), fit: BoxFit.cover) : null,
),
child: imageUrl == null
? Center(
child: initials != null
? Text(initials!, style: TextStyle(color: colors.onSecondary, fontSize: size * 0.38, fontWeight: FontWeight.w600))
: fallbackIcon ?? Icon(Icons.person, size: size * 0.55, color: colors.onSecondary),
)
: null,
);
}
}Version
0.1.0 · display category