display more landmark information
All checks were successful
Build and release APK / Build APK (pull_request) Successful in 5m49s

This commit is contained in:
2024-09-10 16:15:08 +02:00
parent 83d83b03a9
commit 7cbf5a037c
9 changed files with 196 additions and 28 deletions

View File

@@ -1,9 +1,9 @@
import 'package:flutter/material.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:anyway/structs/landmark.dart';
class LandmarkCard extends StatefulWidget {
final Landmark landmark;
@@ -18,6 +18,10 @@ class _LandmarkCardState extends State<LandmarkCard> {
@override
Widget build(BuildContext context) {
ThemeData theme = Theme.of(context);
ButtonStyle buttonStyle = TextButton.styleFrom(
backgroundColor: Colors.orange,
fixedSize: Size.fromHeight(20)
);
return Container(
height: 160,
child: Card(
@@ -62,15 +66,62 @@ class _LandmarkCardState extends State<LandmarkCard> {
)
],
),
Row(
children: [
Flexible(
child: Text(
"${widget.landmark.name} (${widget.landmark.type.name})",
style: const TextStyle(fontSize: 14),
if (widget.landmark.nameEN != null)
Row(
children: [
Flexible(
child: Text(
widget.landmark.nameEN!,
style: const TextStyle(
fontSize: 16,
),
maxLines: 1,
),
)
],
),
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(
style: buttonStyle,
onPressed: () {},
icon: widget.landmark.type.icon,
label: Text(widget.landmark.type.name),
),
)
]
if (widget.landmark.duration != null && widget.landmark.duration!.inMinutes > 0)
TextButton.icon(
style: buttonStyle,
onPressed: () {},
icon: Icon(Icons.hourglass_bottom),
label: Text('${widget.landmark.duration!.inMinutes} minutes'),
),
if (widget.landmark.websiteURL != null)
TextButton.icon(
style: buttonStyle,
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(
style: buttonStyle,
onPressed: () async {
// open a browser with the wikipedia link
await launchUrl(Uri.parse(widget.landmark.wikipediaURL!));
},
icon: Icon(Icons.book),
label: Text('Wikipedia'),
),
],
),
),
],
),

View File

@@ -1,15 +1,16 @@
import 'dart:collection';
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
const LandmarkType sightseeing = LandmarkType(name: 'sightseeing');
const LandmarkType nature = LandmarkType(name: 'nature');
const LandmarkType shopping = LandmarkType(name: 'shopping');
// const LandmarkType museum = LandmarkType(name: 'Museum');
// const LandmarkType restaurant = LandmarkType(name: 'Restaurant');
const LandmarkType start = LandmarkType(name: 'start');
const LandmarkType finish = LandmarkType(name: 'finish');
LandmarkType sightseeing = LandmarkType(name: 'sightseeing');
LandmarkType nature = LandmarkType(name: 'nature');
LandmarkType shopping = LandmarkType(name: 'shopping');
// LandmarkType museum = LandmarkType(name: 'Museum');
// LandmarkType restaurant = LandmarkType(name: 'Restaurant');
LandmarkType start = LandmarkType(name: 'start');
LandmarkType finish = LandmarkType(name: 'finish');
final class Landmark extends LinkedListEntry<Landmark>{
@@ -21,6 +22,9 @@ final class Landmark extends LinkedListEntry<Landmark>{
final bool? isSecondary;
// description to be shown in the overview
final String? nameEN;
final String? websiteURL;
final String? wikipediaURL;
final String? imageURL;
final String? description;
final Duration? duration;
@@ -38,6 +42,9 @@ final class Landmark extends LinkedListEntry<Landmark>{
required this.type,
this.isSecondary,
this.nameEN,
this.websiteURL,
this.wikipediaURL,
this.imageURL,
this.description,
this.duration,
@@ -61,15 +68,30 @@ final class Landmark extends LinkedListEntry<Landmark>{
// parse the rest separately, they could be missing
LandmarkType typeFixed = LandmarkType(name: type);
final isSecondary = json['is_secondary'] as bool?;
final nameEN = json['name_en'] as String?;
final websiteURL = json['website_url'] as String?;
final wikipediaURL = json['wikipedia_url'] as String?;
final imageURL = json['image_url'] as String?;
final description = json['description'] as String?;
var duration = Duration(minutes: json['duration'] ?? 0) as Duration?;
// if (duration == const Duration()) {duration = null;};
final visited = json['visited'] as bool?;
var tripTime = Duration(minutes: json['time_to_reach_next'] ?? 0) as Duration?;
return Landmark(
uuid: uuid, name: name, location: locationFixed, type: typeFixed, isSecondary: isSecondary, imageURL: imageURL, description: description, duration: duration, visited: visited, tripTime: tripTime);
uuid: uuid,
name: name,
location: locationFixed,
type: typeFixed,
isSecondary: isSecondary,
nameEN: nameEN,
websiteURL: websiteURL,
wikipediaURL: wikipediaURL,
imageURL: imageURL,
description: description,
duration: duration,
visited: visited,
tripTime: tripTime
);
} else {
throw FormatException('Invalid JSON: $json');
}
@@ -88,6 +110,9 @@ final class Landmark extends LinkedListEntry<Landmark>{
'location': location,
'type': type.name,
'is_secondary': isSecondary,
'name_en': nameEN,
'website_url': websiteURL,
'wikipedia_url': wikipediaURL,
'image_url': imageURL,
'description': description,
'duration': duration?.inMinutes,
@@ -100,13 +125,29 @@ final class Landmark extends LinkedListEntry<Landmark>{
class LandmarkType {
final String name;
// final String description;
// final Icon icon;
Icon icon;
const LandmarkType({
required this.name,
// required this.description,
// required this.icon,
});
LandmarkType({required this.name, this.icon = const Icon(Icons.location_on)}) {
switch (name) {
case 'sightseeing':
icon = Icon(Icons.church);
break;
case 'nature':
icon = Icon(Icons.eco);
break;
case 'shopping':
icon = Icon(Icons.shopping_cart);
break;
case 'start':
icon = Icon(Icons.play_arrow);
break;
case 'finish':
icon = Icon(Icons.flag);
break;
default:
icon = Icon(Icons.location_on);
}
}
@override
bool operator ==(Object other) {
if (other is LandmarkType) {