Merge branch 'claude/nostalgic-wright-acfc25': inline offer photos
Market offers carry a small base64 data-URI thumbnail embedded in the Nostr event (no media server); full photo stays in the encrypted inventory. Blossom alternative parked on branch parked/offer-photos-blossom. # Conflicts: # apps/app_seeds/lib/i18n/strings.g.dart
This commit is contained in:
commit
e2b88b4f26
20 changed files with 520 additions and 16 deletions
|
|
@ -174,6 +174,7 @@ class SeedLabelEntry extends Equatable {
|
||||||
class ShareableLot extends Equatable {
|
class ShareableLot extends Equatable {
|
||||||
const ShareableLot({
|
const ShareableLot({
|
||||||
required this.lotId,
|
required this.lotId,
|
||||||
|
required this.varietyId,
|
||||||
required this.summary,
|
required this.summary,
|
||||||
required this.offerStatus,
|
required this.offerStatus,
|
||||||
this.category,
|
this.category,
|
||||||
|
|
@ -183,6 +184,10 @@ class ShareableLot extends Equatable {
|
||||||
|
|
||||||
final String lotId;
|
final String lotId;
|
||||||
|
|
||||||
|
/// The lot's variety, so the publish step can fetch its cover photo to host
|
||||||
|
/// as the offer image. Not published itself — never leaves the device.
|
||||||
|
final String varietyId;
|
||||||
|
|
||||||
/// What to publish: the variety label (never the full inventory).
|
/// What to publish: the variety label (never the full inventory).
|
||||||
final String summary;
|
final String summary;
|
||||||
|
|
||||||
|
|
@ -197,7 +202,7 @@ class ShareableLot extends Equatable {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object?> get props =>
|
List<Object?> get props =>
|
||||||
[lotId, summary, offerStatus, category, harvestYear, isOrganic];
|
[lotId, varietyId, summary, offerStatus, category, harvestYear, isOrganic];
|
||||||
}
|
}
|
||||||
|
|
||||||
/// One germination test on a lot; [rate] is derived (0..1), null when it can't
|
/// One germination test on a lot; [rate] is derived (0..1), null when it can't
|
||||||
|
|
@ -727,6 +732,12 @@ class VarietyRepository {
|
||||||
return byVariety;
|
return byVariety;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The cover photo (lowest `sortOrder`) for a single variety, or null when it
|
||||||
|
/// has none. Used by the publish step to host an offer's image; reuses the
|
||||||
|
/// same "first photo" rule as the inventory avatar.
|
||||||
|
Future<Uint8List?> coverPhotoFor(String varietyId) async =>
|
||||||
|
(await _firstPhotosFor([varietyId]))[varietyId];
|
||||||
|
|
||||||
/// Maps each of [speciesIds] to its scientific name (one query).
|
/// Maps each of [speciesIds] to its scientific name (one query).
|
||||||
Future<Map<String, String>> _scientificNamesFor(
|
Future<Map<String, String>> _scientificNamesFor(
|
||||||
Set<String> speciesIds,
|
Set<String> speciesIds,
|
||||||
|
|
@ -1461,6 +1472,7 @@ class VarietyRepository {
|
||||||
if (byId[l.varietyId] case final v?)
|
if (byId[l.varietyId] case final v?)
|
||||||
ShareableLot(
|
ShareableLot(
|
||||||
lotId: l.id,
|
lotId: l.id,
|
||||||
|
varietyId: v.id,
|
||||||
summary: v.label,
|
summary: v.label,
|
||||||
offerStatus: l.offerStatus,
|
offerStatus: l.offerStatus,
|
||||||
category: v.category,
|
category: v.category,
|
||||||
|
|
|
||||||
|
|
@ -482,7 +482,8 @@
|
||||||
"sharedBy": "Compartíu por",
|
"sharedBy": "Compartíu por",
|
||||||
"noProfile": "Esta persona entá nun compartió'l so perfil",
|
"noProfile": "Esta persona entá nun compartió'l so perfil",
|
||||||
"copyId": "Copiar códigu",
|
"copyId": "Copiar códigu",
|
||||||
"idCopied": "Códigu copiáu"
|
"idCopied": "Códigu copiáu",
|
||||||
|
"photo": "Semeya"
|
||||||
},
|
},
|
||||||
"profile": {
|
"profile": {
|
||||||
"title": "El to perfil",
|
"title": "El to perfil",
|
||||||
|
|
|
||||||
|
|
@ -485,7 +485,8 @@
|
||||||
"sharedBy": "Shared by",
|
"sharedBy": "Shared by",
|
||||||
"noProfile": "This person hasn't shared a profile yet",
|
"noProfile": "This person hasn't shared a profile yet",
|
||||||
"copyId": "Copy code",
|
"copyId": "Copy code",
|
||||||
"idCopied": "Code copied"
|
"idCopied": "Code copied",
|
||||||
|
"photo": "Photo"
|
||||||
},
|
},
|
||||||
"profile": {
|
"profile": {
|
||||||
"title": "Your profile",
|
"title": "Your profile",
|
||||||
|
|
|
||||||
|
|
@ -484,7 +484,8 @@
|
||||||
"sharedBy": "Compartido por",
|
"sharedBy": "Compartido por",
|
||||||
"noProfile": "Esta persona aún no ha compartido su perfil",
|
"noProfile": "Esta persona aún no ha compartido su perfil",
|
||||||
"copyId": "Copiar código",
|
"copyId": "Copiar código",
|
||||||
"idCopied": "Código copiado"
|
"idCopied": "Código copiado",
|
||||||
|
"photo": "Foto"
|
||||||
},
|
},
|
||||||
"profile": {
|
"profile": {
|
||||||
"title": "Tu perfil",
|
"title": "Tu perfil",
|
||||||
|
|
|
||||||
|
|
@ -481,7 +481,8 @@
|
||||||
"sharedBy": "Partilhado por",
|
"sharedBy": "Partilhado por",
|
||||||
"noProfile": "Esta pessoa ainda não partilhou o seu perfil",
|
"noProfile": "Esta pessoa ainda não partilhou o seu perfil",
|
||||||
"copyId": "Copiar código",
|
"copyId": "Copiar código",
|
||||||
"idCopied": "Código copiado"
|
"idCopied": "Código copiado",
|
||||||
|
"photo": "Foto"
|
||||||
},
|
},
|
||||||
"profile": {
|
"profile": {
|
||||||
"title": "O teu perfil",
|
"title": "O teu perfil",
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,9 @@
|
||||||
/// To regenerate, run: `dart run slang`
|
/// To regenerate, run: `dart run slang`
|
||||||
///
|
///
|
||||||
/// Locales: 4
|
/// Locales: 4
|
||||||
/// Strings: 1664 (416 per locale)
|
/// Strings: 1668 (417 per locale)
|
||||||
///
|
///
|
||||||
/// Built on 2026-07-10 at 19:36 UTC
|
/// Built on 2026-07-10 at 19:42 UTC
|
||||||
|
|
||||||
// coverage:ignore-file
|
// coverage:ignore-file
|
||||||
// ignore_for_file: type=lint, unused_import
|
// ignore_for_file: type=lint, unused_import
|
||||||
|
|
|
||||||
|
|
@ -693,6 +693,7 @@ class _Translations$market$ast extends Translations$market$en {
|
||||||
@override String get noProfile => 'Esta persona entá nun compartió\'l so perfil';
|
@override String get noProfile => 'Esta persona entá nun compartió\'l so perfil';
|
||||||
@override String get copyId => 'Copiar códigu';
|
@override String get copyId => 'Copiar códigu';
|
||||||
@override String get idCopied => 'Códigu copiáu';
|
@override String get idCopied => 'Códigu copiáu';
|
||||||
|
@override String get photo => 'Semeya';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Path: profile
|
// Path: profile
|
||||||
|
|
@ -1505,6 +1506,7 @@ extension on TranslationsAst {
|
||||||
'market.noProfile' => 'Esta persona entá nun compartió\'l so perfil',
|
'market.noProfile' => 'Esta persona entá nun compartió\'l so perfil',
|
||||||
'market.copyId' => 'Copiar códigu',
|
'market.copyId' => 'Copiar códigu',
|
||||||
'market.idCopied' => 'Códigu copiáu',
|
'market.idCopied' => 'Códigu copiáu',
|
||||||
|
'market.photo' => 'Semeya',
|
||||||
'profile.title' => 'El to perfil',
|
'profile.title' => 'El to perfil',
|
||||||
'profile.name' => 'Nome',
|
'profile.name' => 'Nome',
|
||||||
'profile.nameHint' => 'Cómo te ven los demás',
|
'profile.nameHint' => 'Cómo te ven los demás',
|
||||||
|
|
|
||||||
|
|
@ -1284,6 +1284,9 @@ class Translations$market$en {
|
||||||
|
|
||||||
/// en: 'Code copied'
|
/// en: 'Code copied'
|
||||||
String get idCopied => 'Code copied';
|
String get idCopied => 'Code copied';
|
||||||
|
|
||||||
|
/// en: 'Photo'
|
||||||
|
String get photo => 'Photo';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Path: profile
|
// Path: profile
|
||||||
|
|
@ -2327,6 +2330,7 @@ extension on Translations {
|
||||||
'market.noProfile' => 'This person hasn\'t shared a profile yet',
|
'market.noProfile' => 'This person hasn\'t shared a profile yet',
|
||||||
'market.copyId' => 'Copy code',
|
'market.copyId' => 'Copy code',
|
||||||
'market.idCopied' => 'Code copied',
|
'market.idCopied' => 'Code copied',
|
||||||
|
'market.photo' => 'Photo',
|
||||||
'profile.title' => 'Your profile',
|
'profile.title' => 'Your profile',
|
||||||
'profile.name' => 'Display name',
|
'profile.name' => 'Display name',
|
||||||
'profile.nameHint' => 'How others see you',
|
'profile.nameHint' => 'How others see you',
|
||||||
|
|
|
||||||
|
|
@ -695,6 +695,7 @@ class _Translations$market$es extends Translations$market$en {
|
||||||
@override String get noProfile => 'Esta persona aún no ha compartido su perfil';
|
@override String get noProfile => 'Esta persona aún no ha compartido su perfil';
|
||||||
@override String get copyId => 'Copiar código';
|
@override String get copyId => 'Copiar código';
|
||||||
@override String get idCopied => 'Código copiado';
|
@override String get idCopied => 'Código copiado';
|
||||||
|
@override String get photo => 'Foto';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Path: profile
|
// Path: profile
|
||||||
|
|
@ -1509,6 +1510,7 @@ extension on TranslationsEs {
|
||||||
'market.noProfile' => 'Esta persona aún no ha compartido su perfil',
|
'market.noProfile' => 'Esta persona aún no ha compartido su perfil',
|
||||||
'market.copyId' => 'Copiar código',
|
'market.copyId' => 'Copiar código',
|
||||||
'market.idCopied' => 'Código copiado',
|
'market.idCopied' => 'Código copiado',
|
||||||
|
'market.photo' => 'Foto',
|
||||||
'profile.title' => 'Tu perfil',
|
'profile.title' => 'Tu perfil',
|
||||||
'profile.name' => 'Nombre',
|
'profile.name' => 'Nombre',
|
||||||
'profile.nameHint' => 'Cómo te ven los demás',
|
'profile.nameHint' => 'Cómo te ven los demás',
|
||||||
|
|
|
||||||
|
|
@ -692,6 +692,7 @@ class _Translations$market$pt extends Translations$market$en {
|
||||||
@override String get noProfile => 'Esta pessoa ainda não partilhou o seu perfil';
|
@override String get noProfile => 'Esta pessoa ainda não partilhou o seu perfil';
|
||||||
@override String get copyId => 'Copiar código';
|
@override String get copyId => 'Copiar código';
|
||||||
@override String get idCopied => 'Código copiado';
|
@override String get idCopied => 'Código copiado';
|
||||||
|
@override String get photo => 'Foto';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Path: profile
|
// Path: profile
|
||||||
|
|
@ -1503,6 +1504,7 @@ extension on TranslationsPt {
|
||||||
'market.noProfile' => 'Esta pessoa ainda não partilhou o seu perfil',
|
'market.noProfile' => 'Esta pessoa ainda não partilhou o seu perfil',
|
||||||
'market.copyId' => 'Copiar código',
|
'market.copyId' => 'Copiar código',
|
||||||
'market.idCopied' => 'Código copiado',
|
'market.idCopied' => 'Código copiado',
|
||||||
|
'market.photo' => 'Foto',
|
||||||
'profile.title' => 'O teu perfil',
|
'profile.title' => 'O teu perfil',
|
||||||
'profile.name' => 'Nome',
|
'profile.name' => 'Nome',
|
||||||
'profile.nameHint' => 'Como os outros te veem',
|
'profile.nameHint' => 'Como os outros te veem',
|
||||||
|
|
|
||||||
56
apps/app_seeds/lib/services/offer_thumbnail.dart
Normal file
56
apps/app_seeds/lib/services/offer_thumbnail.dart
Normal file
|
|
@ -0,0 +1,56 @@
|
||||||
|
import 'dart:convert';
|
||||||
|
import 'dart:typed_data';
|
||||||
|
|
||||||
|
import 'package:image/image.dart' as img;
|
||||||
|
|
||||||
|
/// Builds a tiny `data:image/jpeg;base64,…` thumbnail from a full photo, small
|
||||||
|
/// enough to ride *inside* a Nostr offer event — no media server, fully
|
||||||
|
/// decentralized. The full-resolution photo stays in the encrypted local
|
||||||
|
/// inventory; only this shrunken preview is published so peers can see the seed.
|
||||||
|
///
|
||||||
|
/// Relays cap event size, so we downscale (longest edge) and re-encode until the
|
||||||
|
/// base64 fits under [maxBytes]. Returns null when the bytes aren't a decodable
|
||||||
|
/// image or no size small enough is reachable — the offer then publishes without
|
||||||
|
/// a photo (graceful, never a hard failure).
|
||||||
|
String? offerThumbnailDataUri(
|
||||||
|
Uint8List bytes, {
|
||||||
|
int maxBytes = 40000,
|
||||||
|
List<int> edges = const [320, 256, 192, 128],
|
||||||
|
int quality = 68,
|
||||||
|
}) {
|
||||||
|
try {
|
||||||
|
final decoded = img.decodeImage(bytes);
|
||||||
|
if (decoded == null) return null;
|
||||||
|
|
||||||
|
for (final edge in edges) {
|
||||||
|
final resized = _fitWithin(decoded, edge);
|
||||||
|
final jpeg = img.encodeJpg(resized, quality: quality);
|
||||||
|
final b64 = base64.encode(jpeg);
|
||||||
|
if (b64.length <= maxBytes) return 'data:image/jpeg;base64,$b64';
|
||||||
|
}
|
||||||
|
return null; // even the smallest edge didn't fit — skip the image
|
||||||
|
} catch (_) {
|
||||||
|
return null; // undecodable/corrupt bytes — publish without a photo
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Extracts the raw bytes from a `data:...;base64,…` URI, or null when [uri] is
|
||||||
|
/// not a base64 data URI. Used by the UI to render an inline thumbnail with
|
||||||
|
/// `Image.memory` instead of a network fetch.
|
||||||
|
Uint8List? decodeDataUri(String uri) {
|
||||||
|
if (!uri.startsWith('data:')) return null;
|
||||||
|
try {
|
||||||
|
return Uri.parse(uri).data?.contentAsBytes();
|
||||||
|
} on FormatException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Resizes [image] so its longest edge is at most [edge], preserving aspect
|
||||||
|
/// ratio. Never upscales a photo that's already smaller.
|
||||||
|
img.Image _fitWithin(img.Image image, int edge) {
|
||||||
|
if (image.width <= edge && image.height <= edge) return image;
|
||||||
|
return image.width >= image.height
|
||||||
|
? img.copyResize(image, width: edge)
|
||||||
|
: img.copyResize(image, height: edge);
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
import 'dart:typed_data';
|
||||||
|
|
||||||
import 'package:commons_core/commons_core.dart';
|
import 'package:commons_core/commons_core.dart';
|
||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
|
|
@ -7,6 +8,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import '../data/variety_repository.dart';
|
import '../data/variety_repository.dart';
|
||||||
import '../services/offer_mapper.dart';
|
import '../services/offer_mapper.dart';
|
||||||
import '../services/offer_outbox.dart';
|
import '../services/offer_outbox.dart';
|
||||||
|
import '../services/offer_thumbnail.dart';
|
||||||
import '../services/social_service.dart';
|
import '../services/social_service.dart';
|
||||||
import '../services/social_settings.dart';
|
import '../services/social_settings.dart';
|
||||||
|
|
||||||
|
|
@ -134,12 +136,26 @@ class OffersState extends Equatable {
|
||||||
/// UI stays offline-tolerant (a null transport = the social layer is unavailable
|
/// UI stays offline-tolerant (a null transport = the social layer is unavailable
|
||||||
/// and the screen degrades gracefully).
|
/// and the screen degrades gracefully).
|
||||||
class OffersCubit extends Cubit<OffersState> {
|
class OffersCubit extends Cubit<OffersState> {
|
||||||
OffersCubit(this._transport, {Future<void> Function()? onDispose})
|
OffersCubit(
|
||||||
: _onDispose = onDispose,
|
this._transport, {
|
||||||
|
Future<Uint8List?> Function(String varietyId)? coverPhoto,
|
||||||
|
String? Function(Uint8List bytes)? thumbnail,
|
||||||
|
Future<void> Function()? onDispose,
|
||||||
|
}) : _coverPhoto = coverPhoto,
|
||||||
|
_thumbnail = thumbnail,
|
||||||
|
_onDispose = onDispose,
|
||||||
super(const OffersState());
|
super(const OffersState());
|
||||||
|
|
||||||
final OfferTransport? _transport;
|
final OfferTransport? _transport;
|
||||||
|
|
||||||
|
/// Fetches a variety's cover photo bytes; null in tests or when no inventory
|
||||||
|
/// repo is wired.
|
||||||
|
final Future<Uint8List?> Function(String varietyId)? _coverPhoto;
|
||||||
|
|
||||||
|
/// Turns full photo bytes into a small `data:` thumbnail embedded in the offer
|
||||||
|
/// (no media server). Null → offers publish without a photo.
|
||||||
|
final String? Function(Uint8List bytes)? _thumbnail;
|
||||||
|
|
||||||
/// Closes the owning [SocialSession]/connection when the cubit is disposed
|
/// Closes the owning [SocialSession]/connection when the cubit is disposed
|
||||||
/// (null in tests, where the transport is a fake with nothing to close).
|
/// (null in tests, where the transport is a fake with nothing to close).
|
||||||
final Future<void> Function()? _onDispose;
|
final Future<void> Function()? _onDispose;
|
||||||
|
|
@ -269,6 +285,7 @@ class OffersCubit extends Cubit<OffersState> {
|
||||||
areaGeohash: areaGeohash,
|
areaGeohash: areaGeohash,
|
||||||
category: lot.category,
|
category: lot.category,
|
||||||
isOrganic: lot.isOrganic,
|
isOrganic: lot.isOrganic,
|
||||||
|
imageUrl: await _coverThumbnail(lot.varietyId),
|
||||||
);
|
);
|
||||||
final result = await transport.publish(offer);
|
final result = await transport.publish(offer);
|
||||||
if (result.accepted) accepted++;
|
if (result.accepted) accepted++;
|
||||||
|
|
@ -281,6 +298,22 @@ class OffersCubit extends Cubit<OffersState> {
|
||||||
return accepted;
|
return accepted;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Builds a small inline `data:` thumbnail from the lot's cover photo to embed
|
||||||
|
/// in the offer, or null when there's no photo, no thumbnailer, or it can't be
|
||||||
|
/// shrunk to fit. Best-effort: a missing image never blocks publishing.
|
||||||
|
Future<String?> _coverThumbnail(String varietyId) async {
|
||||||
|
final coverPhoto = _coverPhoto;
|
||||||
|
final thumbnail = _thumbnail;
|
||||||
|
if (coverPhoto == null || thumbnail == null) return null;
|
||||||
|
try {
|
||||||
|
final Uint8List? bytes = await coverPhoto(varietyId);
|
||||||
|
if (bytes == null || bytes.isEmpty) return null;
|
||||||
|
return thumbnail(bytes);
|
||||||
|
} catch (_) {
|
||||||
|
return null; // degrade: publish the offer without a photo
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> close() async {
|
Future<void> close() async {
|
||||||
_searchTimeout?.cancel();
|
_searchTimeout?.cancel();
|
||||||
|
|
@ -295,13 +328,19 @@ class OffersCubit extends Cubit<OffersState> {
|
||||||
/// fails), the cubit is created with a null transport and the screen still opens.
|
/// fails), the cubit is created with a null transport and the screen still opens.
|
||||||
Future<OffersCubit> createOffersCubit(
|
Future<OffersCubit> createOffersCubit(
|
||||||
SocialService social,
|
SocialService social,
|
||||||
SocialSettings settings,
|
SocialSettings settings, {
|
||||||
) async {
|
VarietyRepository? repository,
|
||||||
|
}) async {
|
||||||
final relays = await settings.relayUrls();
|
final relays = await settings.relayUrls();
|
||||||
if (relays.isEmpty) return OffersCubit(null);
|
if (relays.isEmpty) return OffersCubit(null);
|
||||||
try {
|
try {
|
||||||
final session = await social.openSession(relays);
|
final session = await social.openSession(relays);
|
||||||
return OffersCubit(session.offers, onDispose: session.close);
|
return OffersCubit(
|
||||||
|
session.offers,
|
||||||
|
coverPhoto: repository?.coverPhotoFor,
|
||||||
|
thumbnail: offerThumbnailDataUri,
|
||||||
|
onDispose: session.close,
|
||||||
|
);
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
return OffersCubit(null); // offline / no relay reachable
|
return OffersCubit(null); // offline / no relay reachable
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -123,6 +123,10 @@ class _MarketOfferDetailScreenState extends State<MarketOfferDetailScreen> {
|
||||||
body: ListView(
|
body: ListView(
|
||||||
padding: const EdgeInsets.all(16),
|
padding: const EdgeInsets.all(16),
|
||||||
children: [
|
children: [
|
||||||
|
if (o.imageUrl != null) ...[
|
||||||
|
OfferHeroImage(url: o.imageUrl!, semanticLabel: t.market.photo),
|
||||||
|
const SizedBox(height: 16),
|
||||||
|
],
|
||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
Expanded(
|
Expanded(
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,11 @@ class _MarketScreenState extends State<MarketScreen> {
|
||||||
final repo =
|
final repo =
|
||||||
widget.outbox != null ? context.read<VarietyRepository>() : null;
|
widget.outbox != null ? context.read<VarietyRepository>() : null;
|
||||||
setState(() => _loading = true);
|
setState(() => _loading = true);
|
||||||
final cubit = await createOffersCubit(widget.social, widget.settings);
|
final cubit = await createOffersCubit(
|
||||||
|
widget.social,
|
||||||
|
widget.settings,
|
||||||
|
repository: repo,
|
||||||
|
);
|
||||||
final area = await widget.settings.areaGeohash();
|
final area = await widget.settings.areaGeohash();
|
||||||
if (!mounted) {
|
if (!mounted) {
|
||||||
await cubit.close();
|
await cubit.close();
|
||||||
|
|
@ -380,6 +384,13 @@ class _OfferCard extends StatelessWidget {
|
||||||
children: [
|
children: [
|
||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
|
if (offer.imageUrl != null) ...[
|
||||||
|
OfferThumbnail(
|
||||||
|
url: offer.imageUrl!,
|
||||||
|
semanticLabel: t.market.photo,
|
||||||
|
),
|
||||||
|
const SizedBox(width: 12),
|
||||||
|
],
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Text(
|
child: Text(
|
||||||
offer.summary,
|
offer.summary,
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import 'package:commons_core/commons_core.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import '../i18n/strings.g.dart';
|
import '../i18n/strings.g.dart';
|
||||||
|
import '../services/offer_thumbnail.dart';
|
||||||
import 'theme.dart';
|
import 'theme.dart';
|
||||||
|
|
||||||
/// Human words for an offer's reciprocity mode. Shared by the market list and
|
/// Human words for an offer's reciprocity mode. Shared by the market list and
|
||||||
|
|
@ -14,6 +15,122 @@ String offerTypeLabel(Translations t, OfferType type) => switch (type) {
|
||||||
OfferType.lend => t.share.exchange,
|
OfferType.lend => t.share.exchange,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// A small square thumbnail of an offer's photo for the market list card.
|
||||||
|
/// The image usually rides inline in the offer as a `data:` URI (decentralized,
|
||||||
|
/// no server), so it renders straight from memory; an `http(s)` URL is still
|
||||||
|
/// supported for interop and degrades gracefully (spinner, then placeholder).
|
||||||
|
class OfferThumbnail extends StatelessWidget {
|
||||||
|
const OfferThumbnail({
|
||||||
|
required this.url,
|
||||||
|
required this.semanticLabel,
|
||||||
|
this.size = 56,
|
||||||
|
super.key,
|
||||||
|
});
|
||||||
|
|
||||||
|
final String url;
|
||||||
|
final String semanticLabel;
|
||||||
|
final double size;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return ClipRRect(
|
||||||
|
borderRadius: BorderRadius.circular(10),
|
||||||
|
child: _offerImage(
|
||||||
|
url,
|
||||||
|
semanticLabel: semanticLabel,
|
||||||
|
width: size,
|
||||||
|
height: size,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Full-width "hero" image atop the offer detail page. Same source handling as
|
||||||
|
/// [OfferThumbnail]; hidden entirely when the offer has no photo.
|
||||||
|
class OfferHeroImage extends StatelessWidget {
|
||||||
|
const OfferHeroImage({
|
||||||
|
required this.url,
|
||||||
|
required this.semanticLabel,
|
||||||
|
super.key,
|
||||||
|
});
|
||||||
|
|
||||||
|
final String url;
|
||||||
|
final String semanticLabel;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return ClipRRect(
|
||||||
|
borderRadius: BorderRadius.circular(14),
|
||||||
|
child: AspectRatio(
|
||||||
|
aspectRatio: 4 / 3,
|
||||||
|
child: _offerImage(url, semanticLabel: semanticLabel),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Renders an offer image from either an inline `data:` URI (via memory) or a
|
||||||
|
/// remote URL (via network), always cropping to fill and falling back to a
|
||||||
|
/// neutral placeholder — a broken image must never block the card.
|
||||||
|
Widget _offerImage(
|
||||||
|
String url, {
|
||||||
|
required String semanticLabel,
|
||||||
|
double? width,
|
||||||
|
double? height,
|
||||||
|
}) {
|
||||||
|
final inline = decodeDataUri(url);
|
||||||
|
if (inline != null) {
|
||||||
|
return Image.memory(
|
||||||
|
inline,
|
||||||
|
width: width,
|
||||||
|
height: height,
|
||||||
|
fit: BoxFit.cover,
|
||||||
|
semanticLabel: semanticLabel,
|
||||||
|
errorBuilder: (context, _, _) =>
|
||||||
|
_OfferImagePlaceholder(width: width, height: height),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return Image.network(
|
||||||
|
url,
|
||||||
|
width: width,
|
||||||
|
height: height,
|
||||||
|
fit: BoxFit.cover,
|
||||||
|
semanticLabel: semanticLabel,
|
||||||
|
loadingBuilder: (context, child, progress) => progress == null
|
||||||
|
? child
|
||||||
|
: _OfferImagePlaceholder(width: width, height: height, loading: true),
|
||||||
|
errorBuilder: (context, _, _) =>
|
||||||
|
_OfferImagePlaceholder(width: width, height: height),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Neutral fill shown while a remote offer image loads or when it can't be
|
||||||
|
/// decoded/fetched — a marketplace is useless if a broken image blocks the card.
|
||||||
|
class _OfferImagePlaceholder extends StatelessWidget {
|
||||||
|
const _OfferImagePlaceholder({this.width, this.height, this.loading = false});
|
||||||
|
|
||||||
|
final double? width;
|
||||||
|
final double? height;
|
||||||
|
final bool loading;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Container(
|
||||||
|
width: width,
|
||||||
|
height: height,
|
||||||
|
color: seedPrimaryContainer.withValues(alpha: 0.4),
|
||||||
|
alignment: Alignment.center,
|
||||||
|
child: loading
|
||||||
|
? const SizedBox(
|
||||||
|
width: 20,
|
||||||
|
height: 20,
|
||||||
|
child: CircularProgressIndicator(strokeWidth: 2),
|
||||||
|
)
|
||||||
|
: const Icon(Icons.image_not_supported_outlined, color: seedMuted),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// The small pill showing an offer's reciprocity mode (give/swap/sell/wanted).
|
/// The small pill showing an offer's reciprocity mode (give/swap/sell/wanted).
|
||||||
class OfferTypeChip extends StatelessWidget {
|
class OfferTypeChip extends StatelessWidget {
|
||||||
const OfferTypeChip({required this.label, super.key});
|
const OfferTypeChip({required this.label, super.key});
|
||||||
|
|
|
||||||
61
apps/app_seeds/test/services/offer_thumbnail_test.dart
Normal file
61
apps/app_seeds/test/services/offer_thumbnail_test.dart
Normal file
|
|
@ -0,0 +1,61 @@
|
||||||
|
import 'dart:convert';
|
||||||
|
import 'dart:typed_data';
|
||||||
|
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:image/image.dart' as img;
|
||||||
|
import 'package:tane/services/offer_thumbnail.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
/// A real, decodable photo far bigger than a thumbnail, with varied pixels so
|
||||||
|
/// JPEG can't compress it to nothing.
|
||||||
|
Uint8List bigPhoto() {
|
||||||
|
final image = img.Image(width: 1280, height: 960);
|
||||||
|
for (var y = 0; y < image.height; y++) {
|
||||||
|
for (var x = 0; x < image.width; x++) {
|
||||||
|
image.setPixelRgb(x, y, (x * 7) % 256, (y * 5) % 256, (x + y) % 256);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return img.encodeJpg(image, quality: 90);
|
||||||
|
}
|
||||||
|
|
||||||
|
test('produces a small jpeg data-URI that fits the byte budget', () {
|
||||||
|
final uri = offerThumbnailDataUri(bigPhoto(), maxBytes: 40000);
|
||||||
|
|
||||||
|
expect(uri, isNotNull);
|
||||||
|
expect(uri!, startsWith('data:image/jpeg;base64,'));
|
||||||
|
final b64 = uri.substring('data:image/jpeg;base64,'.length);
|
||||||
|
expect(b64.length, lessThanOrEqualTo(40000));
|
||||||
|
|
||||||
|
// The payload really is a smaller image than the source.
|
||||||
|
final decoded = img.decodeJpg(base64.decode(b64))!;
|
||||||
|
expect(decoded.width, lessThanOrEqualTo(320));
|
||||||
|
expect(decoded.height, lessThanOrEqualTo(320));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('never upscales an already-tiny image', () {
|
||||||
|
final small = img.encodeJpg(img.Image(width: 64, height: 48), quality: 80);
|
||||||
|
final uri = offerThumbnailDataUri(small);
|
||||||
|
|
||||||
|
expect(uri, isNotNull);
|
||||||
|
final b64 = uri!.substring('data:image/jpeg;base64,'.length);
|
||||||
|
final decoded = img.decodeJpg(base64.decode(b64))!;
|
||||||
|
expect(decoded.width, 64);
|
||||||
|
expect(decoded.height, 48);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('returns null for bytes that are not an image', () {
|
||||||
|
expect(offerThumbnailDataUri(Uint8List.fromList([1, 2, 3, 4])), isNull);
|
||||||
|
});
|
||||||
|
|
||||||
|
group('decodeDataUri', () {
|
||||||
|
test('round-trips a base64 data URI to its bytes', () {
|
||||||
|
final bytes = Uint8List.fromList([9, 8, 7, 6]);
|
||||||
|
final uri = 'data:image/jpeg;base64,${base64.encode(bytes)}';
|
||||||
|
expect(decodeDataUri(uri), bytes);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('returns null for a plain http url', () {
|
||||||
|
expect(decodeDataUri('https://example.org/a.jpg'), isNull);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
import 'dart:typed_data';
|
||||||
|
|
||||||
import 'package:commons_core/commons_core.dart';
|
import 'package:commons_core/commons_core.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
|
@ -269,12 +270,14 @@ void main() {
|
||||||
const [
|
const [
|
||||||
ShareableLot(
|
ShareableLot(
|
||||||
lotId: 'lot-1',
|
lotId: 'lot-1',
|
||||||
|
varietyId: 'var-1',
|
||||||
summary: 'Tomate',
|
summary: 'Tomate',
|
||||||
offerStatus: OfferStatus.shared,
|
offerStatus: OfferStatus.shared,
|
||||||
category: 'Solanaceae',
|
category: 'Solanaceae',
|
||||||
),
|
),
|
||||||
ShareableLot(
|
ShareableLot(
|
||||||
lotId: 'lot-2',
|
lotId: 'lot-2',
|
||||||
|
varietyId: 'var-2',
|
||||||
summary: 'Judía',
|
summary: 'Judía',
|
||||||
offerStatus: OfferStatus.exchange,
|
offerStatus: OfferStatus.exchange,
|
||||||
),
|
),
|
||||||
|
|
@ -291,6 +294,88 @@ void main() {
|
||||||
await cubit.close();
|
await cubit.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('publishLots embeds an inline thumbnail data-URI on the offer',
|
||||||
|
() async {
|
||||||
|
final transport = FakeOfferTransport();
|
||||||
|
var thumbnailed = 0;
|
||||||
|
final cubit = OffersCubit(
|
||||||
|
transport,
|
||||||
|
coverPhoto: (id) async => Uint8List.fromList([1, 2, 3]),
|
||||||
|
thumbnail: (bytes) {
|
||||||
|
thumbnailed++;
|
||||||
|
return 'data:image/jpeg;base64,AAAA';
|
||||||
|
},
|
||||||
|
);
|
||||||
|
await cubit.publishLots(
|
||||||
|
const [
|
||||||
|
ShareableLot(
|
||||||
|
lotId: 'lot-1',
|
||||||
|
varietyId: 'var-1',
|
||||||
|
summary: 'Tomate',
|
||||||
|
offerStatus: OfferStatus.shared,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
authorPubkeyHex: 'ab' * 32,
|
||||||
|
areaGeohash: 'sp3e9',
|
||||||
|
);
|
||||||
|
|
||||||
|
await cubit.discover('sp3');
|
||||||
|
await pumpEventQueue();
|
||||||
|
expect(thumbnailed, 1);
|
||||||
|
expect(cubit.state.offers.single.imageUrl, 'data:image/jpeg;base64,AAAA');
|
||||||
|
await cubit.close();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('publishLots still publishes (without image) when thumbnailing fails',
|
||||||
|
() async {
|
||||||
|
final transport = FakeOfferTransport();
|
||||||
|
final cubit = OffersCubit(
|
||||||
|
transport,
|
||||||
|
coverPhoto: (id) async => Uint8List.fromList([1, 2, 3]),
|
||||||
|
thumbnail: (bytes) => throw Exception('boom'),
|
||||||
|
);
|
||||||
|
final count = await cubit.publishLots(
|
||||||
|
const [
|
||||||
|
ShareableLot(
|
||||||
|
lotId: 'lot-1',
|
||||||
|
varietyId: 'var-1',
|
||||||
|
summary: 'Tomate',
|
||||||
|
offerStatus: OfferStatus.shared,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
authorPubkeyHex: 'ab' * 32,
|
||||||
|
areaGeohash: 'sp3e9',
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(count, 1); // the offer still went out
|
||||||
|
await cubit.discover('sp3');
|
||||||
|
await pumpEventQueue();
|
||||||
|
expect(cubit.state.offers.single.imageUrl, isNull);
|
||||||
|
await cubit.close();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('publishLots without a thumbnailer publishes no image', () async {
|
||||||
|
final transport = FakeOfferTransport();
|
||||||
|
final cubit = OffersCubit(transport); // no thumbnail, no coverPhoto
|
||||||
|
await cubit.publishLots(
|
||||||
|
const [
|
||||||
|
ShareableLot(
|
||||||
|
lotId: 'lot-1',
|
||||||
|
varietyId: 'var-1',
|
||||||
|
summary: 'Tomate',
|
||||||
|
offerStatus: OfferStatus.shared,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
authorPubkeyHex: 'ab' * 32,
|
||||||
|
areaGeohash: 'sp3e9',
|
||||||
|
);
|
||||||
|
|
||||||
|
await cubit.discover('sp3');
|
||||||
|
await pumpEventQueue();
|
||||||
|
expect(cubit.state.offers.single.imageUrl, isNull);
|
||||||
|
await cubit.close();
|
||||||
|
});
|
||||||
|
|
||||||
test('publishLots is a no-op offline or with no area', () async {
|
test('publishLots is a no-op offline or with no area', () async {
|
||||||
final offline = OffersCubit(null);
|
final offline = OffersCubit(null);
|
||||||
expect(
|
expect(
|
||||||
|
|
@ -298,6 +383,7 @@ void main() {
|
||||||
const [
|
const [
|
||||||
ShareableLot(
|
ShareableLot(
|
||||||
lotId: 'x',
|
lotId: 'x',
|
||||||
|
varietyId: 'vx',
|
||||||
summary: 'x',
|
summary: 'x',
|
||||||
offerStatus: OfferStatus.shared,
|
offerStatus: OfferStatus.shared,
|
||||||
),
|
),
|
||||||
|
|
@ -315,6 +401,7 @@ void main() {
|
||||||
const [
|
const [
|
||||||
ShareableLot(
|
ShareableLot(
|
||||||
lotId: 'x',
|
lotId: 'x',
|
||||||
|
varietyId: 'vx',
|
||||||
summary: 'x',
|
summary: 'x',
|
||||||
offerStatus: OfferStatus.shared,
|
offerStatus: OfferStatus.shared,
|
||||||
),
|
),
|
||||||
|
|
@ -336,13 +423,20 @@ void main() {
|
||||||
cubit: cubit,
|
cubit: cubit,
|
||||||
shareableLots: const [
|
shareableLots: const [
|
||||||
ShareableLot(
|
ShareableLot(
|
||||||
lotId: 'lot-1', summary: 'Tomate', offerStatus: OfferStatus.shared),
|
lotId: 'lot-1',
|
||||||
|
varietyId: 'var-1',
|
||||||
|
summary: 'Tomate',
|
||||||
|
offerStatus: OfferStatus.shared),
|
||||||
ShareableLot(
|
ShareableLot(
|
||||||
lotId: 'lot-2',
|
lotId: 'lot-2',
|
||||||
|
varietyId: 'var-2',
|
||||||
summary: 'Judía',
|
summary: 'Judía',
|
||||||
offerStatus: OfferStatus.exchange),
|
offerStatus: OfferStatus.exchange),
|
||||||
ShareableLot(
|
ShareableLot(
|
||||||
lotId: 'lot-3', summary: 'Otro', offerStatus: OfferStatus.shared),
|
lotId: 'lot-3',
|
||||||
|
varietyId: 'var-3',
|
||||||
|
summary: 'Otro',
|
||||||
|
offerStatus: OfferStatus.shared),
|
||||||
],
|
],
|
||||||
authorPubkeyHex: 'ab' * 32,
|
authorPubkeyHex: 'ab' * 32,
|
||||||
areaGeohash: 'sp3e9',
|
areaGeohash: 'sp3e9',
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import 'package:tane/i18n/strings.g.dart';
|
||||||
import 'package:tane/services/social_service.dart';
|
import 'package:tane/services/social_service.dart';
|
||||||
import 'package:tane/services/social_settings.dart';
|
import 'package:tane/services/social_settings.dart';
|
||||||
import 'package:tane/ui/market_offer_detail_screen.dart';
|
import 'package:tane/ui/market_offer_detail_screen.dart';
|
||||||
|
import 'package:tane/ui/market_widgets.dart';
|
||||||
|
|
||||||
import '../support/test_support.dart';
|
import '../support/test_support.dart';
|
||||||
|
|
||||||
|
|
@ -25,7 +26,7 @@ Widget _wrap(MarketOfferDetailScreen screen) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Offer _offer({bool organic = false}) => Offer(
|
Offer _offer({bool organic = false, String? imageUrl}) => Offer(
|
||||||
id: 'lot-1',
|
id: 'lot-1',
|
||||||
authorPubkeyHex: 'ab' * 32,
|
authorPubkeyHex: 'ab' * 32,
|
||||||
summary: 'Tomate rosa de Barbastro',
|
summary: 'Tomate rosa de Barbastro',
|
||||||
|
|
@ -33,6 +34,7 @@ Offer _offer({bool organic = false}) => Offer(
|
||||||
category: 'Solanaceae',
|
category: 'Solanaceae',
|
||||||
approxGeohash: 'sp3e9',
|
approxGeohash: 'sp3e9',
|
||||||
isOrganic: organic,
|
isOrganic: organic,
|
||||||
|
imageUrl: imageUrl,
|
||||||
);
|
);
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
|
@ -70,4 +72,34 @@ void main() {
|
||||||
|
|
||||||
expect(find.byKey(const Key('offerDetail.contact')), findsNothing);
|
expect(find.byKey(const Key('offerDetail.contact')), findsNothing);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
testWidgets('shows a hero image when the offer has a photo', (tester) async {
|
||||||
|
final social = await SocialService.fromRootSeedHex('00' * 32);
|
||||||
|
final settings = SocialSettings(InMemorySecretStore());
|
||||||
|
await settings.setRelayUrls(const []);
|
||||||
|
|
||||||
|
await tester.pumpWidget(_wrap(MarketOfferDetailScreen(
|
||||||
|
offer: _offer(imageUrl: 'https://media.example/abc.jpg'),
|
||||||
|
social: social,
|
||||||
|
settings: settings,
|
||||||
|
)));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
expect(find.byType(OfferHeroImage), findsOneWidget);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('shows no hero image when the offer has none', (tester) async {
|
||||||
|
final social = await SocialService.fromRootSeedHex('00' * 32);
|
||||||
|
final settings = SocialSettings(InMemorySecretStore());
|
||||||
|
await settings.setRelayUrls(const []);
|
||||||
|
|
||||||
|
await tester.pumpWidget(_wrap(MarketOfferDetailScreen(
|
||||||
|
offer: _offer(),
|
||||||
|
social: social,
|
||||||
|
settings: settings,
|
||||||
|
)));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
expect(find.byType(OfferHeroImage), findsNothing);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
62
apps/app_seeds/test/ui/market_widgets_test.dart
Normal file
62
apps/app_seeds/test/ui/market_widgets_test.dart
Normal file
|
|
@ -0,0 +1,62 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:tane/ui/market_widgets.dart';
|
||||||
|
|
||||||
|
Widget _wrap(Widget child) => MaterialApp(home: Scaffold(body: Center(child: child)));
|
||||||
|
|
||||||
|
/// A 1×1 PNG as an inline data URI — the shape offers actually publish.
|
||||||
|
const _dataUri =
|
||||||
|
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lE'
|
||||||
|
'QVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
testWidgets('OfferThumbnail renders an inline data-URI from memory',
|
||||||
|
(tester) async {
|
||||||
|
await tester.pumpWidget(
|
||||||
|
_wrap(const OfferThumbnail(url: _dataUri, semanticLabel: 'Photo')),
|
||||||
|
);
|
||||||
|
await tester.pump();
|
||||||
|
|
||||||
|
expect(find.byType(Image), findsOneWidget);
|
||||||
|
// Decoded fine — no broken-image placeholder.
|
||||||
|
expect(find.byIcon(Icons.image_not_supported_outlined), findsNothing);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('OfferThumbnail builds a network image', (tester) async {
|
||||||
|
await tester.pumpWidget(
|
||||||
|
_wrap(const OfferThumbnail(
|
||||||
|
url: 'https://media.example/abc.jpg',
|
||||||
|
semanticLabel: 'Photo',
|
||||||
|
)),
|
||||||
|
);
|
||||||
|
// The image widget is present; its loadingBuilder/errorBuilder handle the
|
||||||
|
// remote fetch, so we only assert the widget is wired (no network in tests).
|
||||||
|
expect(find.byType(Image), findsOneWidget);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('OfferThumbnail falls back to a placeholder when the load fails',
|
||||||
|
(tester) async {
|
||||||
|
await tester.pumpWidget(
|
||||||
|
_wrap(const OfferThumbnail(
|
||||||
|
url: 'https://media.example/missing.jpg',
|
||||||
|
semanticLabel: 'Photo',
|
||||||
|
)),
|
||||||
|
);
|
||||||
|
// Let the (failed) network fetch resolve; the errorBuilder then shows a
|
||||||
|
// neutral icon instead of a broken image.
|
||||||
|
await tester.pump();
|
||||||
|
await tester.pump(const Duration(seconds: 1));
|
||||||
|
|
||||||
|
expect(find.byIcon(Icons.image_not_supported_outlined), findsOneWidget);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('OfferHeroImage builds a network image', (tester) async {
|
||||||
|
await tester.pumpWidget(
|
||||||
|
_wrap(const OfferHeroImage(
|
||||||
|
url: 'https://media.example/abc.jpg',
|
||||||
|
semanticLabel: 'Photo',
|
||||||
|
)),
|
||||||
|
);
|
||||||
|
expect(find.byType(Image), findsOneWidget);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
@ -35,6 +35,7 @@ void main() {
|
||||||
type: OfferType.gift,
|
type: OfferType.gift,
|
||||||
category: 'Solanaceae',
|
category: 'Solanaceae',
|
||||||
approxGeohash: 'sp3e9xyz',
|
approxGeohash: 'sp3e9xyz',
|
||||||
|
imageUrl: 'https://media.test/tomate.jpg',
|
||||||
));
|
));
|
||||||
expect(published.accepted, isTrue, reason: published.message);
|
expect(published.accepted, isTrue, reason: published.message);
|
||||||
|
|
||||||
|
|
@ -43,6 +44,7 @@ void main() {
|
||||||
expect(found, hasLength(1));
|
expect(found, hasLength(1));
|
||||||
expect(found.single.summary, 'Tomate rosa de Barbastro');
|
expect(found.single.summary, 'Tomate rosa de Barbastro');
|
||||||
expect(found.single.authorPubkeyHex, alice.publicKeyHex);
|
expect(found.single.authorPubkeyHex, alice.publicKeyHex);
|
||||||
|
expect(found.single.imageUrl, 'https://media.test/tomate.jpg');
|
||||||
|
|
||||||
await aliceT.close();
|
await aliceT.close();
|
||||||
await bobT.close();
|
await bobT.close();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue