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:
vjrj 2026-07-10 21:43:35 +02:00
commit e2b88b4f26
20 changed files with 520 additions and 16 deletions

View file

@ -123,6 +123,10 @@ class _MarketOfferDetailScreenState extends State<MarketOfferDetailScreen> {
body: ListView(
padding: const EdgeInsets.all(16),
children: [
if (o.imageUrl != null) ...[
OfferHeroImage(url: o.imageUrl!, semanticLabel: t.market.photo),
const SizedBox(height: 16),
],
Row(
children: [
Expanded(

View file

@ -58,7 +58,11 @@ class _MarketScreenState extends State<MarketScreen> {
final repo =
widget.outbox != null ? context.read<VarietyRepository>() : null;
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();
if (!mounted) {
await cubit.close();
@ -380,6 +384,13 @@ class _OfferCard extends StatelessWidget {
children: [
Row(
children: [
if (offer.imageUrl != null) ...[
OfferThumbnail(
url: offer.imageUrl!,
semanticLabel: t.market.photo,
),
const SizedBox(width: 12),
],
Expanded(
child: Text(
offer.summary,

View file

@ -2,6 +2,7 @@ import 'package:commons_core/commons_core.dart';
import 'package:flutter/material.dart';
import '../i18n/strings.g.dart';
import '../services/offer_thumbnail.dart';
import 'theme.dart';
/// 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,
};
/// 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).
class OfferTypeChip extends StatelessWidget {
const OfferTypeChip({required this.label, super.key});