tane/apps/app_seeds/lib/ui/avatar.dart
vjrj 109c85298c feat(profile): default avatars via DiceBear "thumbs" (CC0), drop boring_avatars
Replace the flutter_boring_avatars fallback with a friendly DiceBear
"thumbs" face, generated offline (dicebear_core) and deterministically
from the pubkey, rendered as SVG (flutter_svg). The thumbs style is
CC0 1.0 (public domain) — no attribution, AGPL-clean — unlike Multiavatar
whose custom licence restricts use. Style parsed once and per-pubkey SVG
memoized; the CC0 <metadata> block is stripped to keep flutter_svg quiet.
2026-07-12 21:59:10 +02:00

40 lines
1.5 KiB
Dart

import 'seed_glyph.dart';
/// A profile avatar is carried in one string (stored locally and published as
/// the NIP-01 kind:0 `picture`), in one of three shapes:
/// - `data:image/jpeg;base64,…` — a tiny photo thumbnail (rides inline, no
/// media server, like offer photos);
/// - `tane:seed:<name>` — one of our own seed illustrations (for people who'd
/// rather not put a real photo — pseudonymity stays the default);
/// - empty — a DiceBear "thumbs" face generated deterministically from the pubkey.
const avatarGlyphPrefix = 'tane:seed:';
/// The seed illustrations offered as ready-made avatars. Names are the stable
/// storage key (appended to [avatarGlyphPrefix]); the glyphs already ship in
/// [SeedGlyphs]. Order is the picker order.
const avatarGlyphNames = <String>[
'jars',
'sack',
'jar',
'scattered',
'pouring',
'mug',
'bigSpoon',
'smallSpoon',
];
/// The glyph char for an avatar illustration [name], or null if unknown.
String? avatarGlyphChar(String name) => switch (name) {
'jars' => SeedGlyphs.jars,
'sack' => SeedGlyphs.sack,
'jar' => SeedGlyphs.jar,
'scattered' => SeedGlyphs.scattered,
'pouring' => SeedGlyphs.pouring,
'mug' => SeedGlyphs.mug,
'bigSpoon' => SeedGlyphs.bigSpoon,
'smallSpoon' => SeedGlyphs.smallSpoon,
_ => null,
};
/// The token that selects illustration [name] (e.g. `tane:seed:jars`).
String avatarGlyphToken(String name) => '$avatarGlyphPrefix$name';