some preference improvements
Some checks failed
Build and release APK / Build APK (pull_request) Successful in 7m27s
Test code / Test code (push) Has been cancelled
Build web / Build Web (pull_request) Has been cancelled
Test code / Test code (pull_request) Has been cancelled

This commit is contained in:
2024-05-25 18:55:58 +02:00
parent 07830de1b2
commit 3029fb8537
13 changed files with 365 additions and 56 deletions

View File

@@ -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,
});
}

View 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;
}
}
}

View 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
});
}