feat(profile): Material default avatar + square photo crop

Drop the DiceBear generated avatar (and dicebear_core/dicebear_styles/
flutter_svg): the default is again a Material coloured-initial disc from
the pubkey. Picking a photo now goes through a square crop step
(crop_your_image — pure Flutter, all platforms incl. desktop, Apache-2.0,
only pulls the image package we already had) before the 24 KB thumbnail.
This commit is contained in:
vjrj 2026-07-12 23:39:56 +02:00
parent 17612b8147
commit f6967e8cbb
8 changed files with 200 additions and 175 deletions

View file

@ -124,14 +124,14 @@ void main() {
await tester.pumpWidget(host(cubit));
await tester.pump();
// Both sides carry an avatar, each generated from its own pubkey
// Both sides carry an avatar, and the two people are different colours
// so you can tell who said what at a glance.
expect(find.byType(PeerAvatar), findsNWidgets(2));
final generated = tester
.widgetList<GeneratedAvatar>(find.byType(GeneratedAvatar))
final discs = tester
.widgetList<CircleAvatar>(find.byType(CircleAvatar))
.toList();
expect(generated, hasLength(2));
expect(generated.first.pubkey, isNot(generated.last.pubkey));
expect(discs, hasLength(2));
expect(discs.first.backgroundColor, isNot(discs.last.backgroundColor));
});
testWidgets('a new message lands in view at the bottom, not below the fold', (

View file

@ -36,19 +36,17 @@ void main() {
home: Scaffold(body: Center(child: child)),
);
testWidgets('falls back to a generated avatar keyed by pubkey', (
tester,
) async {
testWidgets('shows the name initial when known', (tester) async {
await tester.pumpWidget(host(PeerAvatar(pubkey: 'aa', name: 'rosa')));
final generated =
tester.widget<GeneratedAvatar>(find.byType(GeneratedAvatar));
expect(generated.pubkey, 'aa'); // pubkey, not name stable across renames
expect(find.byType(Text), findsNothing);
expect(find.text('R'), findsOneWidget); // uppercased first letter
});
testWidgets('generates it even when the name is unknown', (tester) async {
testWidgets('falls back to a person icon when the name is unknown', (
tester,
) async {
await tester.pumpWidget(host(const PeerAvatar(pubkey: 'aa')));
expect(find.byType(GeneratedAvatar), findsOneWidget);
expect(find.byIcon(Icons.person_outline), findsOneWidget);
expect(find.byType(Text), findsNothing);
});
testWidgets('renders a seed illustration when the avatar is a token', (
@ -75,19 +73,19 @@ void main() {
expect(find.byType(SeedGlyph), findsOneWidget);
});
testWidgets('falls back to the generated avatar when nothing is cached', (
testWidgets('falls back to the initial 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.byType(GeneratedAvatar), findsOneWidget);
expect(find.text('B'), findsOneWidget);
});
testWidgets('no cache → the generated avatar', (tester) async {
testWidgets('no cache → the coloured-initial disc', (tester) async {
await tester.pumpWidget(host(const CachedAvatar(pubkey: 'x', name: 'Bea')));
expect(find.byType(GeneratedAvatar), findsOneWidget);
expect(find.text('B'), findsOneWidget);
});
});
}

View file

@ -0,0 +1,48 @@
import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:image/image.dart' as img;
import 'package:tane/ui/photo_crop.dart';
void main() {
// A small but real PNG the cropper can decode.
final bytes = Uint8List.fromList(
img.encodePng(img.Image(width: 32, height: 32)),
);
testWidgets('cropToSquare shows a cancel/confirm UI and cancel returns null', (
tester,
) async {
Uint8List? result;
var returned = false;
await tester.pumpWidget(MaterialApp(
home: Builder(
builder: (context) => Scaffold(
body: Center(
child: ElevatedButton(
onPressed: () async {
result = await cropToSquare(context, bytes);
returned = true;
},
child: const Text('open'),
),
),
),
),
));
await tester.tap(find.text('open'));
await tester.pump(); // push the crop route
await tester.pump(const Duration(milliseconds: 100));
expect(find.byKey(const Key('crop.confirm')), findsOneWidget);
expect(find.byKey(const Key('crop.cancel')), findsOneWidget);
await tester.tap(find.byKey(const Key('crop.cancel')));
await tester.pump(); // pop the crop route
expect(returned, isTrue);
expect(result, isNull); // cancelling yields no image
});
}