some preference improvements
This commit is contained in:
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;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user