some preference improvements
This commit is contained in:
@@ -1,31 +1,62 @@
|
||||
import "package:flutter/material.dart";
|
||||
|
||||
class Destination {
|
||||
final double latitude;
|
||||
final double longitude;
|
||||
final String name;
|
||||
final String description;
|
||||
final DestinationType type;
|
||||
// final DestinationType type;
|
||||
final Duration duration;
|
||||
final bool visited;
|
||||
|
||||
Destination({
|
||||
const Destination({
|
||||
required this.latitude,
|
||||
required this.longitude,
|
||||
required this.name,
|
||||
required this.description,
|
||||
required this.type,
|
||||
// required this.type,
|
||||
required this.duration,
|
||||
required this.visited,
|
||||
});
|
||||
|
||||
factory Destination.fromJson(Map<String, dynamic> json) {
|
||||
return switch (json) {
|
||||
{
|
||||
'lat': double latitude,
|
||||
'lon': double longitude,
|
||||
'name': String name,
|
||||
'description': String description,
|
||||
// 'type': String type,
|
||||
'duration': int duration,
|
||||
'visited': bool visited
|
||||
|
||||
} =>
|
||||
Destination(
|
||||
latitude: latitude,
|
||||
longitude: longitude,
|
||||
name: name,
|
||||
description: description,
|
||||
// type: "DestinationType.values.firstWhere((element) => element.name == type)",
|
||||
duration: Duration(minutes: duration),
|
||||
visited: visited
|
||||
),
|
||||
_ => throw const FormatException('Failed to load destination.'),
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
class DestinationType {
|
||||
final String name;
|
||||
final String description;
|
||||
final Icon icon;
|
||||
|
||||
DestinationType({
|
||||
const DestinationType({
|
||||
required this.name,
|
||||
required this.description,
|
||||
required this.icon,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
82
frontend/lib/structs/preferences.dart
Normal file
82
frontend/lib/structs/preferences.dart
Normal file
@@ -0,0 +1,82 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
|
||||
class SinglePreference {
|
||||
String name;
|
||||
String description;
|
||||
int value;
|
||||
Icon icon;
|
||||
String key;
|
||||
|
||||
SinglePreference({
|
||||
required this.name,
|
||||
required this.description,
|
||||
required this.value,
|
||||
required this.icon,
|
||||
required this.key,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
class UserPreferences {
|
||||
List<SinglePreference> preferences = [
|
||||
SinglePreference(
|
||||
name: "Sightseeing",
|
||||
description: "How much do you like sightseeing?",
|
||||
value: 0,
|
||||
icon: Icon(Icons.church),
|
||||
key: "sightseeing",
|
||||
),
|
||||
SinglePreference(
|
||||
name: "Shopping",
|
||||
description: "How much do you like shopping?",
|
||||
value: 0,
|
||||
icon: Icon(Icons.shopping_bag),
|
||||
key: "shopping",
|
||||
),
|
||||
SinglePreference(
|
||||
name: "Foods & Drinks",
|
||||
description: "How much do you like eating?",
|
||||
value: 0,
|
||||
icon: Icon(Icons.restaurant),
|
||||
key: "eating",
|
||||
),
|
||||
SinglePreference(
|
||||
name: "Nightlife",
|
||||
description: "How much do you like nightlife?",
|
||||
value: 0,
|
||||
icon: Icon(Icons.wine_bar),
|
||||
key: "nightlife",
|
||||
),
|
||||
SinglePreference(
|
||||
name: "Nature",
|
||||
description: "How much do you like nature?",
|
||||
value: 0,
|
||||
icon: Icon(Icons.landscape),
|
||||
key: "nature",
|
||||
),
|
||||
SinglePreference(
|
||||
name: "Culture",
|
||||
description: "How much do you like culture?",
|
||||
value: 0,
|
||||
icon: Icon(Icons.palette),
|
||||
key: "culture",
|
||||
),
|
||||
];
|
||||
|
||||
|
||||
void save() async {
|
||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
for (SinglePreference pref in preferences) {
|
||||
prefs.setInt(pref.key, pref.value);
|
||||
}
|
||||
}
|
||||
|
||||
void load() async {
|
||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
for (SinglePreference pref in preferences) {
|
||||
pref.value = prefs.getInt(pref.key) ?? 0;
|
||||
}
|
||||
}
|
||||
}
|
14
frontend/lib/structs/route.dart
Normal file
14
frontend/lib/structs/route.dart
Normal file
@@ -0,0 +1,14 @@
|
||||
import "package:fast_network_navigation/structs/destination.dart";
|
||||
|
||||
|
||||
class Route {
|
||||
final String name;
|
||||
final Duration duration;
|
||||
final List<Destination> destinations;
|
||||
|
||||
Route({
|
||||
required this.name,
|
||||
required this.duration,
|
||||
required this.destinations
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user