tane/apps/app_seeds/lib/ui/avatar_edit.dart
vjrj ec56819fbf feat(profile): profile photo or seed-illustration avatar
Profiles had only a coloured-initial disc. Now each person can set an
avatar — a real photo OR one of our own seed illustrations (so
pseudonymity stays the default; no photo required).

- ui/avatar.dart: the one-string value scheme carried in the kind:0
  'picture' — a 'data:' photo thumbnail, a 'tane:seed:<glyph>' token, or
  empty. The Nostr ProfileTransport already published 'picture'.
- Photos ride inline as a tiny thumbnail (reuses offerThumbnailDataUri,
  24 KB cap) — no media server, like offer photos.
- avatar_edit.dart: pick/take a photo, choose a seed illustration, or
  remove; ProfileStore stores it; ProfileScreen shows a big editable
  avatar and publishes it.
- PeerAvatar renders photo / illustration / initial fallback.
- ProfileCache gains picture/setPicture; the inbox caches peers' avatars
  alongside their names.
- i18n avatar block (en/es/pt/ast). Tests: value scheme + PeerAvatar
  render modes, store + cache round-trips.

Follow-up: render peers' avatars in chat/market/your-people (thread the
cached picture into PeerAvatar at each call site).
2026-07-11 22:21:52 +02:00

90 lines
3.3 KiB
Dart

import 'package:flutter/material.dart';
import '../i18n/strings.g.dart';
import '../services/offer_thumbnail.dart' show offerThumbnailDataUri;
import 'avatar.dart';
import 'photo_pick.dart';
import 'seed_glyph.dart';
import 'theme.dart';
/// Lets the user choose a profile avatar: take/pick a photo (shrunk to a tiny
/// inline thumbnail), pick one of our seed illustrations, or remove it.
///
/// Returns the new avatar value (`data:` thumbnail or `tane:seed:<glyph>`),
/// an empty string to clear it, or null when cancelled.
Future<String?> showAvatarPicker(
BuildContext context, {
required String current,
}) {
return showModalBottomSheet<String>(
context: context,
isScrollControlled: true,
builder: (sheetContext) {
final t = sheetContext.t;
return SafeArea(
child: Padding(
padding: const EdgeInsets.fromLTRB(16, 12, 16, 16),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(t.avatar.title,
style: Theme.of(sheetContext).textTheme.titleMedium),
const SizedBox(height: 8),
ListTile(
key: const Key('avatar.fromPhoto'),
contentPadding: EdgeInsets.zero,
leading: const Icon(Icons.add_a_photo_outlined,
color: seedGreen),
title: Text(t.avatar.fromPhoto),
onTap: () async {
final bytes = await pickPhoto(sheetContext);
if (bytes == null) return;
final uri = offerThumbnailDataUri(bytes, maxBytes: 24000);
if (sheetContext.mounted) {
Navigator.of(sheetContext).pop(uri ?? '');
}
},
),
const SizedBox(height: 6),
Text(t.avatar.illustration,
style: const TextStyle(color: seedMuted, fontSize: 13)),
const SizedBox(height: 10),
Wrap(
spacing: 14,
runSpacing: 14,
children: [
for (final name in avatarGlyphNames)
InkWell(
key: Key('avatar.glyph.$name'),
borderRadius: BorderRadius.circular(40),
onTap: () => Navigator.of(sheetContext)
.pop(avatarGlyphToken(name)),
child: CircleAvatar(
radius: 24,
backgroundColor: seedGreen,
child: SeedGlyph(avatarGlyphChar(name)!,
size: 26, color: Colors.white),
),
),
],
),
if (current.isNotEmpty) ...[
const SizedBox(height: 8),
Align(
alignment: AlignmentDirectional.centerStart,
child: TextButton.icon(
key: const Key('avatar.remove'),
onPressed: () => Navigator.of(sheetContext).pop(''),
icon: const Icon(Icons.delete_outline, size: 18),
label: Text(t.avatar.remove),
),
),
],
],
),
),
);
},
);
}