feat(profile): generated default avatars (boring-avatars beam) from pubkey

People without a photo or seed illustration now get a deterministic
pattern avatar drawn from their pubkey (flutter_boring_avatars, MIT),
in an earthy seed-tone palette, replacing the coloured-initial disc.
Same pubkey renders the same picture on every device with nothing shared.
This commit is contained in:
vjrj 2026-07-12 12:49:06 +02:00
parent e65d82017a
commit 1c2b3d5e8d
6 changed files with 59 additions and 45 deletions

View file

@ -1,15 +1,27 @@
import 'package:flutter/material.dart';
import 'package:flutter_boring_avatars/flutter_boring_avatars.dart';
import '../services/offer_thumbnail.dart' show decodeDataUri;
import '../services/profile_cache.dart';
import 'avatar.dart';
import 'seed_glyph.dart';
import 'theme.dart';
/// Palette for the generated default avatars earthy seed-and-leaf tones so
/// the fallback art sits inside the app's palette rather than fighting it.
const _generatedAvatarPalette = BoringAvatarPalette([
seedGreen,
seedRating, // warm amber
Color(0xFFB5541F), // terracotta pot
Color(0xFF6B4F2A), // seed-coat brown
Color(0xFFD3E8C8), // pale leaf
]);
/// A small round avatar for a person. When they've set an avatar ([picture] — a
/// `data:` photo thumbnail or a `tane:seed:<glyph>` illustration) it's shown;
/// otherwise it falls back to a deterministic disc coloured from their [pubkey],
/// with the first letter of their [name] (else a person glyph). Same pubkey
/// same colour on every device, so a person stays visually recognizable.
/// otherwise it falls back to a generated pattern drawn deterministically from
/// their [pubkey] (boring-avatars "beam"). Same pubkey same picture on every
/// device, so a person stays visually recognizable without sharing anything.
class PeerAvatar extends StatelessWidget {
const PeerAvatar({
required this.pubkey,
@ -46,35 +58,25 @@ class PeerAvatar extends StatelessWidget {
}
}
final letter = _initial(name);
return CircleAvatar(
radius: radius,
backgroundColor: peerAvatarColor(pubkey),
child: letter == null
? Icon(Icons.person_outline, size: radius, color: Colors.white)
: Text(
letter,
style: TextStyle(
color: Colors.white,
fontSize: radius,
fontWeight: FontWeight.w600,
),
),
return Semantics(
label: name,
image: true,
child: SizedBox.square(
dimension: radius * 2,
child: BoringAvatar(
name: pubkey,
type: BoringAvatarType.beam,
palette: _generatedAvatarPalette,
shape: const OvalBorder(),
),
),
);
}
static String? _initial(String? name) {
if (name == null) return null;
final trimmed = name.trim();
if (trimmed.isEmpty) return null;
// characters.first handles emoji/combining marks safely.
return trimmed.characters.first.toUpperCase();
}
}
/// A [PeerAvatar] that looks the person's published avatar up from the
/// [ProfileCache] (their kind:0 `picture`), falling back to the coloured-initial
/// disc while it loads or when none is cached / no cache is available. Use at
/// [ProfileCache] (their kind:0 `picture`), falling back to the generated
/// pattern while it loads or when none is cached / no cache is available. Use at
/// list/row sites (one avatar each); for many avatars of the same few people
/// (chat bubbles) resolve the picture once into state instead.
class CachedAvatar extends StatelessWidget {