some preference improvements
This commit is contained in:
@@ -4,9 +4,10 @@ import 'package:fast_network_navigation/modules/overview.dart';
|
||||
import 'package:fast_network_navigation/modules/profile.dart';
|
||||
|
||||
|
||||
// BasePage is the scaffold that holds all other pages
|
||||
// A side drawer is used to switch between pages
|
||||
class BasePage extends StatefulWidget {
|
||||
const BasePage({super.key, required this.title});
|
||||
|
||||
final String title;
|
||||
|
||||
@override
|
||||
@@ -22,7 +23,7 @@ class _BasePageState extends State<BasePage> {
|
||||
});
|
||||
}
|
||||
|
||||
Widget currentView = MainPage();
|
||||
Widget currentView = NavigationOverview();
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final ThemeData theme = Theme.of(context);
|
||||
@@ -51,7 +52,7 @@ class _BasePageState extends State<BasePage> {
|
||||
// Update the state of the app
|
||||
_onItemTapped(0);
|
||||
// Then close the drawer
|
||||
currentView = MainPage();
|
||||
currentView = NavigationOverview();
|
||||
Navigator.pop(context);
|
||||
},
|
||||
),
|
||||
@@ -87,3 +88,4 @@ class _BasePageState extends State<BasePage> {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:fast_network_navigation/modules/scaffold.dart';
|
||||
import 'package:fast_network_navigation/layout.dart';
|
||||
|
||||
void main() => runApp(const App());
|
||||
|
||||
|
@@ -9,9 +9,9 @@ import 'package:fast_network_navigation/modules/map.dart';
|
||||
|
||||
|
||||
|
||||
class MainPage extends StatefulWidget {
|
||||
class NavigationOverview extends StatefulWidget {
|
||||
@override
|
||||
State<MainPage> createState() => _MainPageState();
|
||||
State<NavigationOverview> createState() => _NavigationOverviewState();
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ class Debounce {
|
||||
}
|
||||
|
||||
|
||||
class _MainPageState extends State<MainPage> {
|
||||
class _NavigationOverviewState extends State<NavigationOverview> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@@ -1,3 +1,4 @@
|
||||
import 'package:fast_network_navigation/structs/preferences.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
|
||||
@@ -8,48 +9,83 @@ class ProfilePage extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _ProfilePageState extends State<ProfilePage> {
|
||||
|
||||
double value = 0.0;
|
||||
void onChanged(double newValue) {
|
||||
setState(() {
|
||||
value = newValue;
|
||||
});
|
||||
}
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('Profile'),
|
||||
),
|
||||
body: Padding(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
Card(
|
||||
child: ListTile(
|
||||
leading: Icon(Icons.notifications_sharp),
|
||||
title: Text('Notification 1'),
|
||||
subtitle: Text('This is a first notification'),
|
||||
),
|
||||
),
|
||||
Card(
|
||||
child: ListTile(
|
||||
leading: Icon(Icons.notifications_sharp),
|
||||
title: Text('Notification 2'),
|
||||
subtitle: Text('This is a notification'),
|
||||
),
|
||||
),
|
||||
Card(
|
||||
child: ListTile(
|
||||
leading: Icon(Icons.outdoor_grill),
|
||||
title: Text("Eating preference"),
|
||||
subtitle: Slider.adaptive(value: value, onChanged: onChanged, min: 0, max: 5, divisions: 5, label: value.toInt().toString(),)
|
||||
|
||||
)
|
||||
)
|
||||
],
|
||||
return ListView(
|
||||
children: [
|
||||
// First a round, centered image
|
||||
Center(
|
||||
child: CircleAvatar(
|
||||
radius: 100,
|
||||
child: Icon(Icons.person, size: 100),
|
||||
)
|
||||
),
|
||||
)
|
||||
Center(
|
||||
child: Text('Curious traveler', style: TextStyle(fontSize: 24))
|
||||
),
|
||||
|
||||
Padding(
|
||||
padding: EdgeInsets.all(10),
|
||||
),
|
||||
|
||||
Text('Please rate your preferences for the following activities:'),
|
||||
|
||||
// Now the sliders
|
||||
ImportanceSliders()
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
class ImportanceSliders extends StatefulWidget {
|
||||
|
||||
@override
|
||||
State<ImportanceSliders> createState() => _ImportanceSlidersState();
|
||||
}
|
||||
|
||||
|
||||
class _ImportanceSlidersState extends State<ImportanceSliders> {
|
||||
|
||||
UserPreferences _prefs = UserPreferences();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_prefs.load();
|
||||
}
|
||||
|
||||
List<Card> _createSliders() {
|
||||
List<Card> sliders = [];
|
||||
for (SinglePreference pref in _prefs.preferences) {
|
||||
sliders.add(Card(
|
||||
child: ListTile(
|
||||
leading: pref.icon,
|
||||
title: Text(pref.name),
|
||||
subtitle: Slider(
|
||||
value: pref.value.toDouble(),
|
||||
min: 0,
|
||||
max: 10,
|
||||
divisions: 10,
|
||||
label: pref.value.toString(),
|
||||
onChanged: (double newValue) {
|
||||
setState(() {
|
||||
pref.value = newValue.toInt();
|
||||
_prefs.save();
|
||||
});
|
||||
},
|
||||
)
|
||||
),
|
||||
margin: EdgeInsets.only(left: 10, right: 10, top: 10, bottom: 0),
|
||||
shadowColor: Colors.grey,
|
||||
));
|
||||
}
|
||||
return sliders;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(children: _createSliders());
|
||||
}
|
||||
}
|
||||
|
@@ -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
|
||||
});
|
||||
}
|
18
frontend/lib/utils/get_route.dart
Normal file
18
frontend/lib/utils/get_route.dart
Normal file
@@ -0,0 +1,18 @@
|
||||
import "package:fast_network_navigation/structs/destination.dart";
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'dart:convert';
|
||||
|
||||
Future<Destination> fetchDestination() async {
|
||||
final response = await http
|
||||
.get(Uri.parse('https://nav.kluster.moll.re/v1/destination/1'));
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
// If the server did return a 200 OK response,
|
||||
// then parse the JSON.
|
||||
return Destination.fromJson(jsonDecode(response.body) as Map<String, dynamic>);
|
||||
} else {
|
||||
// If the server did not return a 200 OK response,
|
||||
// then throw an exception.
|
||||
throw Exception('Failed to load destination');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user