diff --git a/frontend/lib/modules/landmark_card.dart b/frontend/lib/modules/landmark_card.dart index 1b49fc2..e920e79 100644 --- a/frontend/lib/modules/landmark_card.dart +++ b/frontend/lib/modules/landmark_card.dart @@ -23,6 +23,15 @@ class LandmarkCard extends StatefulWidget { class _LandmarkCardState extends State { @override Widget build(BuildContext context) { + if (widget.landmark.type == typeStart || widget.landmark.type == typeFinish) { + return TextButton.icon( + onPressed: () {}, + icon: widget.landmark.type.icon, + label: Text(widget.landmark.name), + ); + + } + // else: return Container( child: Card( shape: RoundedRectangleBorder( @@ -93,78 +102,67 @@ class _LandmarkCardState extends State { ) ], ), - SingleChildScrollView( - // allows the buttons to be scrolled - scrollDirection: Axis.horizontal, - child: Wrap( - spacing: 10, - // show the type, the website, and the wikipedia link as buttons/labels in a row - children: [ - TextButton.icon( - onPressed: () {}, - icon: widget.landmark.type.icon, - label: Text(widget.landmark.type.name), - ), - if (widget.landmark.duration != null && widget.landmark.duration!.inMinutes > 0) + Padding(padding: EdgeInsets.only(top: 10)), + Align( + alignment: Alignment.centerLeft, + child: SingleChildScrollView( + // allows the buttons to be scrolled + scrollDirection: Axis.horizontal, + child: Wrap( + spacing: 10, + // show the type, the website, and the wikipedia link as buttons/labels in a row + children: [ TextButton.icon( onPressed: () {}, - icon: Icon(Icons.hourglass_bottom), - label: Text('${widget.landmark.duration!.inMinutes} minutes'), + icon: widget.landmark.type.icon, + label: Text(widget.landmark.type.name), ), - if (widget.landmark.websiteURL != null) - TextButton.icon( - onPressed: () async { - // open a browser with the website link - await launchUrl(Uri.parse(widget.landmark.websiteURL!)); - }, - icon: Icon(Icons.link), - label: Text('Website'), - ), - // if (widget.landmark.wikipediaURL != null) - // TextButton.icon( - // onPressed: () async { - // // open a browser with the wikipedia link - // await launchUrl(Uri.parse(widget.landmark.wikipediaURL!)); - // }, - // icon: Icon(Icons.book), - // label: Text('Wikipedia'), - // ), - PopupMenuButton( - icon: Icon(Icons.settings), - style: TextButtonTheme.of(context).style, - itemBuilder: (context) => [ - PopupMenuItem( - child: ListTile( - leading: Icon(Icons.delete), - title: Text('Delete'), - onTap: () async { - setState(() { + if (widget.landmark.duration != null && widget.landmark.duration!.inMinutes > 0) + TextButton.icon( + onPressed: () {}, + icon: Icon(Icons.hourglass_bottom), + label: Text('${widget.landmark.duration!.inMinutes} minutes'), + ), + if (widget.landmark.websiteURL != null) + TextButton.icon( + onPressed: () async { + // open a browser with the website link + await launchUrl(Uri.parse(widget.landmark.websiteURL!)); + }, + icon: Icon(Icons.link), + label: Text('Website'), + ), + PopupMenuButton( + icon: Icon(Icons.settings), + style: TextButtonTheme.of(context).style, + itemBuilder: (context) => [ + PopupMenuItem( + child: ListTile( + leading: Icon(Icons.delete), + title: Text('Delete'), + onTap: () async { widget.parentTrip.removeLandmark(widget.landmark); - }); - rootScaffoldMessengerKey.currentState!.showSnackBar( - SnackBar(content: Text("We won't show ${widget.landmark.name} again")) - ); - - - }, + rootScaffoldMessengerKey.currentState!.showSnackBar( + SnackBar(content: Text("We won't show ${widget.landmark.name} again")) + ); + }, + ), ), - ), - PopupMenuItem( - child: ListTile( - leading: Icon(Icons.star), - title: Text('Favorite'), - onTap: () async { - // delete the landmark - // await deleteLandmark(widget.landmark); - - }, + PopupMenuItem( + child: ListTile( + leading: Icon(Icons.star), + title: Text('Favorite'), + onTap: () async { + // delete the landmark + // await deleteLandmark(widget.landmark); + }, + ), ), - ), - - ], - ) - - ], + ], + ) + + ], + ), ), ), ], diff --git a/frontend/lib/utils/fetch_trip.dart b/frontend/lib/utils/fetch_trip.dart index e24f81d..4fc35e2 100644 --- a/frontend/lib/utils/fetch_trip.dart +++ b/frontend/lib/utils/fetch_trip.dart @@ -93,6 +93,11 @@ patchLandmarkImage(Landmark landmark) async { if (newUrl != null) { landmark.imageURL = newUrl; } + } else if (landmark.imageURL!.contains("photos.app.goo.gl")) { + // the image is a google photos link, we should get the image behind the link + String? newUrl = await getImageUrlFromGooglePhotos(landmark.imageURL!); + // also set the new url if it is null + landmark.imageURL = newUrl; } } diff --git a/frontend/lib/utils/load_landmark_image.dart b/frontend/lib/utils/load_landmark_image.dart index c02a020..8b81bf4 100644 --- a/frontend/lib/utils/load_landmark_image.dart +++ b/frontend/lib/utils/load_landmark_image.dart @@ -58,3 +58,14 @@ Future getImageUrlFromName(String title) async { } return await getImageUrl(pageId); } + + +Future getImageUrlFromGooglePhotos(String url) async { + // this is a very simple implementation that just gets the image behind the link + // it is not guaranteed to work for all google photos links + final response = await dio.get(url); + final data = response.toString(); + final int start = data.indexOf("https://lh3.googleusercontent.com"); + final int end = data.indexOf('"', start); + return data.substring(start, end); +}