Frontend UX improvements #37
| @@ -23,6 +23,15 @@ class LandmarkCard extends StatefulWidget { | |||||||
| class _LandmarkCardState extends State<LandmarkCard> { | class _LandmarkCardState extends State<LandmarkCard> { | ||||||
|   @override |   @override | ||||||
|   Widget build(BuildContext context) { |   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( |     return Container( | ||||||
|       child: Card( |       child: Card( | ||||||
|         shape: RoundedRectangleBorder( |         shape: RoundedRectangleBorder( | ||||||
| @@ -93,78 +102,67 @@ class _LandmarkCardState extends State<LandmarkCard> { | |||||||
|                 ) |                 ) | ||||||
|               ], |               ], | ||||||
|             ), |             ), | ||||||
|           SingleChildScrollView( |           Padding(padding: EdgeInsets.only(top: 10)), | ||||||
|             // allows the buttons to be scrolled |           Align( | ||||||
|             scrollDirection: Axis.horizontal, |             alignment: Alignment.centerLeft, | ||||||
|             child: Wrap( |             child: SingleChildScrollView( | ||||||
|               spacing: 10, |               // allows the buttons to be scrolled | ||||||
|               // show the type, the website, and the wikipedia link as buttons/labels in a row |               scrollDirection: Axis.horizontal, | ||||||
|               children: [ |               child: Wrap( | ||||||
|                 TextButton.icon( |                 spacing: 10, | ||||||
|                   onPressed: () {}, |                 // show the type, the website, and the wikipedia link as buttons/labels in a row | ||||||
|                   icon: widget.landmark.type.icon, |                 children: [ | ||||||
|                   label: Text(widget.landmark.type.name), |  | ||||||
|                 ), |  | ||||||
|                 if (widget.landmark.duration != null && widget.landmark.duration!.inMinutes > 0) |  | ||||||
|                   TextButton.icon( |                   TextButton.icon( | ||||||
|                     onPressed: () {}, |                     onPressed: () {}, | ||||||
|                     icon: Icon(Icons.hourglass_bottom), |                     icon: widget.landmark.type.icon, | ||||||
|                     label: Text('${widget.landmark.duration!.inMinutes} minutes'), |                     label: Text(widget.landmark.type.name), | ||||||
|                   ), |                   ), | ||||||
|                 if (widget.landmark.websiteURL != null) |                   if (widget.landmark.duration != null && widget.landmark.duration!.inMinutes > 0) | ||||||
|                   TextButton.icon( |                     TextButton.icon( | ||||||
|                     onPressed: () async { |                       onPressed: () {}, | ||||||
|                       // open a browser with the website link |                       icon: Icon(Icons.hourglass_bottom), | ||||||
|                       await launchUrl(Uri.parse(widget.landmark.websiteURL!)); |                       label: Text('${widget.landmark.duration!.inMinutes} minutes'), | ||||||
|                     }, |                     ), | ||||||
|                     icon: Icon(Icons.link), |                   if (widget.landmark.websiteURL != null) | ||||||
|                     label: Text('Website'), |                     TextButton.icon( | ||||||
|                   ), |                       onPressed: () async { | ||||||
|                 // if (widget.landmark.wikipediaURL != null) |                         // open a browser with the website link | ||||||
|                 //   TextButton.icon( |                         await launchUrl(Uri.parse(widget.landmark.websiteURL!)); | ||||||
|                 //     onPressed: () async { |                       }, | ||||||
|                 //       // open a browser with the wikipedia link |                       icon: Icon(Icons.link), | ||||||
|                 //       await launchUrl(Uri.parse(widget.landmark.wikipediaURL!)); |                       label: Text('Website'), | ||||||
|                 //     }, |                     ), | ||||||
|                 //     icon: Icon(Icons.book), |                   PopupMenuButton( | ||||||
|                 //   label: Text('Wikipedia'), |                     icon: Icon(Icons.settings), | ||||||
|                 // ), |                     style: TextButtonTheme.of(context).style, | ||||||
|                 PopupMenuButton( |                     itemBuilder: (context) => [ | ||||||
|                   icon: Icon(Icons.settings), |                       PopupMenuItem( | ||||||
|                   style: TextButtonTheme.of(context).style, |                         child: ListTile( | ||||||
|                   itemBuilder: (context) => [ |                           leading: Icon(Icons.delete), | ||||||
|                     PopupMenuItem( |                           title: Text('Delete'), | ||||||
|                       child: ListTile( |                           onTap: () async { | ||||||
|                         leading: Icon(Icons.delete), |  | ||||||
|                         title: Text('Delete'), |  | ||||||
|                         onTap: () async { |  | ||||||
|                           setState(() { |  | ||||||
|                             widget.parentTrip.removeLandmark(widget.landmark); |                             widget.parentTrip.removeLandmark(widget.landmark); | ||||||
|                           }); |                             rootScaffoldMessengerKey.currentState!.showSnackBar( | ||||||
|                           rootScaffoldMessengerKey.currentState!.showSnackBar( |                               SnackBar(content: Text("We won't show ${widget.landmark.name} again")) | ||||||
|                             SnackBar(content: Text("We won't show ${widget.landmark.name} again")) |                             ); | ||||||
|                           ); |                           }, | ||||||
|  |                         ), | ||||||
|  |  | ||||||
|                         }, |  | ||||||
|                       ), |                       ), | ||||||
|                     ), |                       PopupMenuItem( | ||||||
|                     PopupMenuItem( |                         child: ListTile( | ||||||
|                       child: ListTile( |                           leading: Icon(Icons.star), | ||||||
|                         leading: Icon(Icons.star), |                           title: Text('Favorite'), | ||||||
|                         title: Text('Favorite'), |                           onTap: () async { | ||||||
|                         onTap: () async { |                             // delete the landmark | ||||||
|                           // delete the landmark |                             // await deleteLandmark(widget.landmark); | ||||||
|                           // await deleteLandmark(widget.landmark); |                           }, | ||||||
|  |                         ), | ||||||
|                         }, |  | ||||||
|                       ), |                       ), | ||||||
|                     ), |                     ], | ||||||
|  |                   ) | ||||||
|                      |                      | ||||||
|                   ], |                 ], | ||||||
|                 ) |               ), | ||||||
|                    |  | ||||||
|               ], |  | ||||||
|             ), |             ), | ||||||
|           ), |           ), | ||||||
|         ], |         ], | ||||||
|   | |||||||
| @@ -93,6 +93,11 @@ patchLandmarkImage(Landmark landmark) async { | |||||||
|     if (newUrl != null) { |     if (newUrl != null) { | ||||||
|       landmark.imageURL = newUrl; |       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;  | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -58,3 +58,14 @@ Future<String?> getImageUrlFromName(String title) async { | |||||||
|     } |     } | ||||||
|     return await getImageUrl(pageId); |     return await getImageUrl(pageId); | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
|  | Future<String?> 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); | ||||||
|  | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user