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:
parent
f31f58cc7e
commit
d85b557f1e
6 changed files with 59 additions and 45 deletions
|
|
@ -3,6 +3,7 @@ import 'dart:async';
|
|||
import 'package:commons_core/commons_core.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_boring_avatars/flutter_boring_avatars.dart';
|
||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:tane/domain/chat_timeline.dart';
|
||||
|
|
@ -124,14 +125,14 @@ void main() {
|
|||
await tester.pumpWidget(host(cubit));
|
||||
await tester.pump();
|
||||
|
||||
// Both sides carry an avatar, and the two people are different colours —
|
||||
// Both sides carry an avatar, each generated from its own pubkey —
|
||||
// so you can tell who said what at a glance.
|
||||
expect(find.byType(PeerAvatar), findsNWidgets(2));
|
||||
final discs = tester
|
||||
.widgetList<CircleAvatar>(find.byType(CircleAvatar))
|
||||
final generated = tester
|
||||
.widgetList<BoringAvatar>(find.byType(BoringAvatar))
|
||||
.toList();
|
||||
expect(discs, hasLength(2));
|
||||
expect(discs.first.backgroundColor, isNot(discs.last.backgroundColor));
|
||||
expect(generated, hasLength(2));
|
||||
expect(generated.first.name, isNot(generated.last.name));
|
||||
});
|
||||
|
||||
testWidgets('a new message lands in view at the bottom, not below the fold', (
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_boring_avatars/flutter_boring_avatars.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:tane/services/profile_cache.dart';
|
||||
import 'package:tane/ui/avatar.dart';
|
||||
|
|
@ -37,19 +38,20 @@ void main() {
|
|||
home: Scaffold(body: Center(child: child)),
|
||||
);
|
||||
|
||||
testWidgets('shows the name initial when known', (tester) async {
|
||||
await tester.pumpWidget(host(PeerAvatar(pubkey: 'aa', name: 'rosa')));
|
||||
expect(find.text('R'), findsOneWidget); // uppercased first letter
|
||||
});
|
||||
|
||||
testWidgets('falls back to a glyph when the name is unknown', (
|
||||
testWidgets('falls back to a generated pattern keyed by pubkey', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(host(const PeerAvatar(pubkey: 'aa')));
|
||||
expect(find.byIcon(Icons.person_outline), findsOneWidget);
|
||||
await tester.pumpWidget(host(PeerAvatar(pubkey: 'aa', name: 'rosa')));
|
||||
final generated = tester.widget<BoringAvatar>(find.byType(BoringAvatar));
|
||||
expect(generated.name, 'aa'); // pubkey, not name → stable across renames
|
||||
expect(find.byType(Text), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('generates it even when the name is unknown', (tester) async {
|
||||
await tester.pumpWidget(host(const PeerAvatar(pubkey: 'aa')));
|
||||
expect(find.byType(BoringAvatar), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('renders a seed illustration when the avatar is a token', (
|
||||
tester,
|
||||
) async {
|
||||
|
|
@ -74,19 +76,19 @@ void main() {
|
|||
expect(find.byType(SeedGlyph), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('falls back to the initial when nothing is cached', (
|
||||
testWidgets('falls back to the generated pattern when nothing is cached', (
|
||||
tester,
|
||||
) async {
|
||||
final cache = ProfileCache(InMemorySecretStore());
|
||||
await tester.pumpWidget(host(
|
||||
CachedAvatar(pubkey: 'peer2', name: 'Bea', cache: cache)));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('B'), findsOneWidget);
|
||||
expect(find.byType(BoringAvatar), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('no cache → the coloured-initial disc', (tester) async {
|
||||
testWidgets('no cache → the generated pattern', (tester) async {
|
||||
await tester.pumpWidget(host(const CachedAvatar(pubkey: 'x', name: 'Bea')));
|
||||
expect(find.text('B'), findsOneWidget);
|
||||
expect(find.byType(BoringAvatar), findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue