some preference improvements

This commit is contained in:
2024-05-25 18:55:58 +02:00
parent ea08250d87
commit 600f912a85
13 changed files with 365 additions and 56 deletions

View File

@@ -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) {

View File

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

View File

@@ -1,89 +0,0 @@
import 'package:flutter/material.dart';
import 'package:fast_network_navigation/modules/overview.dart';
import 'package:fast_network_navigation/modules/profile.dart';
class BasePage extends StatefulWidget {
const BasePage({super.key, required this.title});
final String title;
@override
State<BasePage> createState() => _BasePageState();
}
class _BasePageState extends State<BasePage> {
int _selectedIndex = 0;
void _onItemTapped(int index) {
setState(() {
_selectedIndex = index;
});
}
Widget currentView = MainPage();
@override
Widget build(BuildContext context) {
final ThemeData theme = Theme.of(context);
return Scaffold(
appBar: AppBar(title: Text(widget.title)),
body: Center(child: currentView),
drawer: Drawer(
// Add a ListView to the drawer. This ensures the user can scroll
// through the options in the drawer if there isn't enough vertical
// space to fit everything.
child: ListView(
// Important: Remove any padding from the ListView.
padding: EdgeInsets.zero,
children: [
DrawerHeader(
decoration: BoxDecoration(
gradient: LinearGradient(colors: [Colors.cyan, theme.primaryColor])
),
child: const Text('The fanciest navigation!'),
),
ListTile(
title: const Text('Home'),
selected: _selectedIndex == 0,
onTap: () {
// Update the state of the app
_onItemTapped(0);
// Then close the drawer
currentView = MainPage();
Navigator.pop(context);
},
),
ListTile(
title: const Text('Business'),
selected: _selectedIndex == 1,
onTap: () {
// Update the state of the app
_onItemTapped(1);
currentView = const Text("ghfhggfhgf");
// Then close the drawer
Navigator.pop(context);
},
),
// add a whitespace so that the settings are at the bottom
const Divider(),
ListTile(
title: const Text('Settings'),
leading: const Icon(Icons.settings),
selected: _selectedIndex == 2,
onTap: () {
_onItemTapped(2);
currentView = ProfilePage();
Navigator.pop(context);
},
),
// settings in the bottom of the drawer
],
),
),
);
}
}