Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 8 additions & 8 deletions examples/travel_app/integration_test/app_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,16 @@ const Map<String, Object> _baliResponse = {
'TravelCarousel': {
'items': [
{
'imageChild': 'bali_memorial_image',
'imageChildId': 'bali_memorial_image',
'title': 'Cultural Immersion',
},
{
'imageChild': 'nyepi_festival_image',
'imageChildId': 'nyepi_festival_image',
'title': 'Festivals and Traditions',
},
{
'title': 'Beach Relaxation',
'imageChild': 'kata_noi_beach_image',
'imageChildId': 'kata_noi_beach_image',
},
],
},
Expand All @@ -94,7 +94,7 @@ const Map<String, Object> _baliResponse = {
'widget': {
'Image': {
'fit': 'cover',
'assetName': 'assets/travel_images/bali_memorial.jpg',
'location': 'assets/travel_images/bali_memorial.jpg',
},
},
},
Expand All @@ -103,19 +103,19 @@ const Map<String, Object> _baliResponse = {
'widget': {
'Image': {
'fit': 'cover',
'assetName': 'assets/travel_images/nyepi_festival_bali.jpg',
'location': 'assets/travel_images/nyepi_festival_bali.jpg',
},
},
},
{
'id': 'kata_noi_beach_image',
'widget': {
'Image': {
'assetName':
'assets/travel_images/kata_noi_beach_phuket_thailand.jpg',
'fit': 'cover',
'location':
'assets/travel_images/kata_noi_beach_phuket_thailand.jpg',
},
},
'id': 'kata_noi_beach_image',
},
{
'widget': {
Expand Down
12 changes: 6 additions & 6 deletions examples/travel_app/lib/src/catalog/travel_carousel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -290,13 +290,13 @@ JsonMap _hotelExample() {
{
'id': 'image_1',
'widget': {
'Image': {'fit': 'cover', 'assetName': hotel1.images[0]},
'Image': {'fit': 'cover', 'location': hotel1.images[0]},
},
},
{
'id': 'image_2',
'widget': {
'Image': {'fit': 'cover', 'assetName': hotel2.images[0]},
'Image': {'fit': 'cover', 'location': hotel2.images[0]},
},
},
],
Expand Down Expand Up @@ -355,7 +355,7 @@ JsonMap _inspirationExample() => {
'widget': {
'Image': {
'fit': 'cover',
'assetName': 'assets/travel_images/santorini_panorama.jpg',
'location': 'assets/travel_images/santorini_panorama.jpg',
},
},
},
Expand All @@ -364,7 +364,7 @@ JsonMap _inspirationExample() => {
'widget': {
'Image': {
'fit': 'cover',
'assetName':
'location':
'assets/travel_images/akrotiri_spring_fresco_santorini.jpg',
},
},
Expand All @@ -373,7 +373,7 @@ JsonMap _inspirationExample() => {
'id': 'santorini_caldera_image',
'widget': {
'Image': {
'assetName': 'assets/travel_images/santorini_from_space.jpg',
'location': 'assets/travel_images/santorini_from_space.jpg',
'fit': 'cover',
},
},
Expand All @@ -382,7 +382,7 @@ JsonMap _inspirationExample() => {
'widget': {
'Image': {
'fit': 'cover',
'assetName':
'location':
'assets/travel_images/saffron_gatherers_fresco_santorini.jpg',
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class BookingService {
location: 'Mountain View, CA',
pricePerNight: 250.0,
listingSelectionId: _generateListingSelectionId(),
images: ['assets/booking_service/flutter_hotel.jpeg'],
images: ['assets/booking_service/flutter_hotel.png'],
search: search,
),
),
Expand Down
7 changes: 3 additions & 4 deletions examples/travel_app/lib/src/travel_planner_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -435,8 +435,7 @@ ${_imagesJson ?? ''}
list that might be tangentially relevant. DO NOT USE ANY IMAGES NOT IN THE LIST.
It is fine if the image is irrelevant, as long as it is from the list.

- Use assetName for images from the list only - NEVER use `url` and reference
images from wikipedia or other sites.
- Image location always should be an asset path (e.g. assets/...).

# Example

Expand Down Expand Up @@ -483,7 +482,7 @@ contain the other widgets.
"id": "mexico_city_image",
"widget": {
"Image": {
"assetName": "assets/travel_images/mexico_city.jpg"
"location": "assets/travel_images/mexico_city.jpg"
}
}
},
Expand Down Expand Up @@ -516,7 +515,7 @@ contain the other widgets.
"id": "day1_image",
"widget": {
"Image": {
"assetName": "assets/travel_images/mexico_city.jpg"
"location": "assets/travel_images/mexico_city.jpg"
}
}
},
Expand Down
41 changes: 11 additions & 30 deletions packages/flutter_genui/lib/src/catalog/core_widgets/image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,9 @@ import '../../primitives/simple_items.dart';

final _schema = S.object(
properties: {
'url': S.string(
'location': S.string(
description:
'The URL of the image to display. Only one '
'of url or assetName may be specified.',
),
'assetName': S.string(
description:
'The name of the asset to display. Only '
'one of assetName or url may be specified.',
'Asset path (e.g. assets/...) or network URL (e.g. https://...)',
),
'fit': S.string(
description: 'How the image should be inscribed into the box.',
Expand All @@ -28,11 +22,10 @@ final _schema = S.object(
);

extension type _ImageData.fromMap(JsonMap _json) {
factory _ImageData({String? url, String? assetName, String? fit}) =>
_ImageData.fromMap({'url': url, 'assetName': assetName, 'fit': fit});
factory _ImageData({required String location, String? fit}) =>
_ImageData.fromMap({'location': location, 'fit': fit});

String? get url => _json['url'] as String?;
String? get assetName => _json['assetName'] as String?;
String get location => _json['location'] as String;
BoxFit? get fit => _json['fit'] != null
? BoxFit.values.firstWhere((e) => e.name == _json['fit'] as String)
: null;
Expand All @@ -52,25 +45,13 @@ final image = CatalogItem(
}) {
final imageData = _ImageData.fromMap(data as JsonMap);

final url = imageData.url;
final assetName = imageData.assetName;

if ((url == null) == (assetName == null)) {
throw Exception(
'Image widget must have either a url or an assetName, '
'but not both. '
'Details: $imageData',
);
}
final location = imageData.location;
final fit = imageData.fit;

if (url != null) {
return Image.network(url, fit: imageData.fit);
if (location.startsWith('assets/')) {
return Image.asset(location, fit: fit);
} else {
return Image.network(location, fit: fit);
}

if (assetName != null) {
return Image.asset(assetName, fit: imageData.fit);
}

return const SizedBox();
},
);
2 changes: 1 addition & 1 deletion packages/flutter_genui/test/image_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void main() {
builder: (context) => Scaffold(
body: image.widgetBuilder(
data: {
'url':
'location':
'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png',
},
id: 'test_image',
Expand Down
Loading