feat(block1): photo thumbnails in the inventory list

The list showed only initials even when a variety had a photo (quick-add stores
one as an encrypted BLOB). Now the avatar shows the first photo, falling back to
the initial — matching the "foto/inicial" list spec.

- VarietyListItem carries the first photo bytes; watchInventory loads them in a
  single query per emission.
- List tile renders a MemoryImage avatar when present.

Tests: repository (photo bytes surfaced, null when none) and a widget test
(avatar replaces the initial). Full suite: 37 passing, 0 skipped.
This commit is contained in:
vjrj 2026-07-07 22:03:36 +02:00
parent 37427fa738
commit 8a19a6c85a
4 changed files with 87 additions and 10 deletions

View file

@ -52,6 +52,18 @@ void main() {
},
);
test('watchInventory carries the first photo bytes for the avatar', () async {
await repo.addQuickVariety(
label: 'With photo',
photoBytes: Uint8List.fromList([9, 8, 7]),
);
await repo.addQuickVariety(label: 'No photo');
final items = await repo.watchInventory().first;
expect(items.firstWhere((i) => i.label == 'With photo').photo, [9, 8, 7]);
expect(items.firstWhere((i) => i.label == 'No photo').photo, isNull);
});
test(
'stream is ordered by category then label and excludes soft-deleted rows',
() async {

View file

@ -1,3 +1,5 @@
import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:tane/db/database.dart';
@ -6,6 +8,14 @@ import 'package:tane/ui/inventory_list_screen.dart';
import '../support/test_support.dart';
/// A valid 1x1 transparent PNG so the avatar image decodes cleanly in tests.
final _tinyPng = Uint8List.fromList(const [
137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 1, //
0, 0, 0, 1, 8, 6, 0, 0, 0, 31, 21, 196, 137, 0, 0, 0, 13, 73, 68, 65, 84, //
120, 156, 99, 250, 207, 0, 0, 0, 2, 0, 1, 226, 33, 188, 51, 0, 0, 0, 0, //
73, 69, 78, 68, 174, 66, 96, 130,
]);
void main() {
late AppDatabase db;
@ -75,4 +85,21 @@ void main() {
expect(find.text('Inventario'), findsOneWidget);
await disposeTree(tester);
});
testWidgets(
'shows a photo avatar instead of the initial when a photo exists',
(tester) async {
final repo = newTestRepository(db);
await repo.addQuickVariety(label: 'Photographed', photoBytes: _tinyPng);
await tester.pumpWidget(
wrapScreen(repository: repo, child: const InventoryListScreen()),
);
await tester.pumpAndSettle();
expect(find.text('Photographed'), findsOneWidget);
expect(find.text('P'), findsNothing); // initial replaced by the photo
await disposeTree(tester);
},
);
}