feat(market): show offer photos in the market list and detail
Render offer.imageUrl (already carried by NIP-99) as a thumbnail on each market card and a hero image on the offer detail page. Remote images degrade gracefully: a spinner while loading, a neutral placeholder when the media server is unreachable. Publishing the photo comes next.
This commit is contained in:
parent
4b71859416
commit
b56ce68167
14 changed files with 633 additions and 111 deletions
|
|
@ -6,6 +6,7 @@ import 'package:tane/i18n/strings.g.dart';
|
|||
import 'package:tane/services/social_service.dart';
|
||||
import 'package:tane/services/social_settings.dart';
|
||||
import 'package:tane/ui/market_offer_detail_screen.dart';
|
||||
import 'package:tane/ui/market_widgets.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',
|
||||
authorPubkeyHex: 'ab' * 32,
|
||||
summary: 'Tomate rosa de Barbastro',
|
||||
|
|
@ -33,6 +34,7 @@ Offer _offer({bool organic = false}) => Offer(
|
|||
category: 'Solanaceae',
|
||||
approxGeohash: 'sp3e9',
|
||||
isOrganic: organic,
|
||||
imageUrl: imageUrl,
|
||||
);
|
||||
|
||||
void main() {
|
||||
|
|
@ -70,4 +72,34 @@ void main() {
|
|||
|
||||
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);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
45
apps/app_seeds/test/ui/market_widgets_test.dart
Normal file
45
apps/app_seeds/test/ui/market_widgets_test.dart
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
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)));
|
||||
|
||||
void main() {
|
||||
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);
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue