Data display
Avatar
A round picture of a person, or their initials when there is no image.
JxAvatar
import 'package:jx_cli/ui.dart'
Available since 0.0.2
Preview
When to use it
- Authors of comments.
- Members of a team.
- The signed-in user in a menu.
Minimal example
JxAvatar(name: 'Grace Hopper') // initials: GH
JxAvatar(name: 'Grace Hopper', src: '/grace.jpg') // picture
Complete example
A full Jaspr component you can paste into a project.
import 'package:jaspr/dom.dart';
import 'package:jaspr/jaspr.dart';
import 'package:jx_cli/ui.dart';
/// Overlapping avatars of a team.
class TeamStack extends StatelessComponent {
const TeamStack(this.names, {super.key});
final List<String> names;
@override
Component build(BuildContext context) {
return div(classes: 'flex', [
for (final (i, name) in names.indexed)
JxAvatar(name: name, size: JxAvatarSize.sm, classes: i == 0 ? 'bw:2 bc:white' : '-ml:2 bw:2 bc:white'),
]);
}
}
Properties
| Property | Type | Default | Description |
|---|---|---|---|
name |
String |
required |
Used for the initials and as the accessible name. |
src |
String? |
null |
Picture URL. The image
alt
is the name.
|
size |
JxAvatarSize |
md |
sm
(32 px),
md
(40 px) or
lg
(56 px).
|
classes |
String? |
null |
Extra JX classes, appended after the component classes. |
Related types
| Name | Role |
|---|---|
JxAvatar.initials(name)
|
Static helper: up to two initials, "Ada Lovelace" → "AL". |
Customizing
-
Pass
classesto add or override utilities: they come last, soclasses: 'w:full'wins over the default width. -
Use another color for initials:
classes: 'bg:green-100 c:green-900'.
Accessibility
-
With a picture, the image
altis the name; with initials, the avatar isrole="img"with anaria-label. - Initials are hidden from screen readers, so the full name is read instead of letters.