Made Settings persistent with autosave
This commit is contained in:
@ -6,9 +6,11 @@ import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
import '../../model/accountModel.dart';
|
||||
import '../../model/appTheme.dart';
|
||||
import '../../theming/appTheme.dart';
|
||||
import '../../storage/settings/settingsProvider.dart';
|
||||
import '../../widget/confirmDialog.dart';
|
||||
import 'debug/debugOverview.dart';
|
||||
import 'debug/jsonViewer.dart';
|
||||
|
||||
class Settings extends StatefulWidget {
|
||||
const Settings({Key? key}) : super(key: key);
|
||||
@ -29,152 +31,158 @@ class _SettingsState extends State<Settings> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text("Einstellungen"),
|
||||
),
|
||||
body: ListView(
|
||||
children: [
|
||||
return Consumer<SettingsProvider>(builder: (context, settings, child) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text("Einstellungen"),
|
||||
),
|
||||
body: ListView(
|
||||
children: [
|
||||
|
||||
ListTile(
|
||||
leading: const Icon(Icons.logout_outlined),
|
||||
title: const Text("Konto abmelden"),
|
||||
onTap: () {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => ConfirmDialog(
|
||||
title: "Abmelden?",
|
||||
content: "Möchtest du dich wirklich abmelden?",
|
||||
confirmButton: "Abmelden",
|
||||
onConfirm: () {
|
||||
SharedPreferences.getInstance().then((value) => {
|
||||
value.clear(),
|
||||
}).then((value) => {
|
||||
Provider.of<AccountModel>(context, listen: false).logout(),
|
||||
Navigator.popUntil(context, (route) => !Navigator.canPop(context)),
|
||||
});
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
|
||||
const Divider(),
|
||||
|
||||
Consumer<AppTheme>(
|
||||
builder: (context, value, child) {
|
||||
return ListTile(
|
||||
leading: const Icon(Icons.dark_mode_outlined),
|
||||
title: const Text("Farbgebung"),
|
||||
trailing: DropdownButton<ThemeMode>(
|
||||
value: value.getMode,
|
||||
icon: const Icon(Icons.arrow_drop_down),
|
||||
items: ThemeMode.values.map((e) => DropdownMenuItem<ThemeMode>(
|
||||
value: e,
|
||||
enabled: e != value.getMode,
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(AppTheme.getDisplayOptions(e).icon),
|
||||
const SizedBox(width: 10),
|
||||
Text(AppTheme.getDisplayOptions(e).displayName),
|
||||
],
|
||||
),
|
||||
)).toList(),
|
||||
onChanged: (e) {
|
||||
Provider.of<AppTheme>(context, listen: false).setTheme(e ?? ThemeMode.system);
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
|
||||
const Divider(),
|
||||
|
||||
ListTile(
|
||||
leading: const Icon(Icons.live_help_outlined),
|
||||
title: const Text("Informationen und Lizenzen"),
|
||||
onTap: () async {
|
||||
final appInfo = await PackageInfo.fromPlatform();
|
||||
|
||||
if(!context.mounted) return; // TODO Fix context used in async
|
||||
showAboutDialog(
|
||||
context: context,
|
||||
applicationIcon: const Icon(Icons.apps),
|
||||
applicationName: "MarianumMobile",
|
||||
applicationVersion: "${appInfo.appName}\n\nPackage: ${appInfo.packageName}\n\nVersion: ${appInfo.version}\nBuild: ${appInfo.buildNumber}",
|
||||
applicationLegalese: "Dies ist ein Inoffizieller Nextcloud & Webuntis Client und wird nicht vom Marianum selbst betrieben.\n"
|
||||
"Keinerlei Gewähr für Vollständigkeit, Richtigkeit und Aktualität!\n\n"
|
||||
"Development build\n"
|
||||
"Marianum Fulda 2023 Elias Müller",
|
||||
);
|
||||
},
|
||||
trailing: const Icon(Icons.arrow_right),
|
||||
),
|
||||
|
||||
ListTile(
|
||||
leading: const Icon(Icons.policy_outlined),
|
||||
title: const Text("Datenschutz"),
|
||||
onTap: () {
|
||||
launchUrl(Uri.parse("https://mhsl.eu/datenschutz.html"));
|
||||
},
|
||||
trailing: const Icon(Icons.open_in_new),
|
||||
),
|
||||
|
||||
ListTile(
|
||||
leading: const Icon(Icons.badge_outlined),
|
||||
title: const Text("Impressum"),
|
||||
onTap: () {
|
||||
launchUrl(Uri.parse("https://mhsl.eu/id.html"));
|
||||
},
|
||||
trailing: const Icon(Icons.open_in_new),
|
||||
),
|
||||
|
||||
const Divider(),
|
||||
|
||||
ListTile(
|
||||
leading: const Icon(Icons.developer_mode_outlined),
|
||||
title: const Text("Entwicklermodus"),
|
||||
trailing: Checkbox(
|
||||
visualDensity: const VisualDensity(horizontal: VisualDensity.minimumDensity),
|
||||
value: developerMode,
|
||||
onChanged: (state) {
|
||||
setState(() {
|
||||
developerMode = !developerMode;
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
Visibility(
|
||||
visible: developerMode,
|
||||
child: ListTile(
|
||||
leading: const Icon(Icons.data_object),
|
||||
title: const Text("Storage view"),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.logout_outlined),
|
||||
title: const Text("Konto abmelden"),
|
||||
onTap: () {
|
||||
Navigator.push(context, MaterialPageRoute(builder: (context) {
|
||||
return const DebugOverview();
|
||||
}));
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => ConfirmDialog(
|
||||
title: "Abmelden?",
|
||||
content: "Möchtest du dich wirklich abmelden?",
|
||||
confirmButton: "Abmelden",
|
||||
onConfirm: () {
|
||||
SharedPreferences.getInstance().then((value) => {
|
||||
value.clear(),
|
||||
}).then((value) => {
|
||||
Provider.of<AccountModel>(context, listen: false).logout(),
|
||||
Navigator.popUntil(context, (route) => !Navigator.canPop(context)),
|
||||
});
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
trailing: const Icon(Icons.arrow_right),
|
||||
),
|
||||
),
|
||||
|
||||
Visibility(
|
||||
visible: developerMode && false, // TODO Implement verbose logging
|
||||
child: ListTile(
|
||||
leading: const Icon(Icons.logo_dev),
|
||||
title: const Text("Logging verbosity"),
|
||||
trailing: DropdownButton<String>(
|
||||
value: "1",
|
||||
items: ["1", "2", "3"].map((e) => DropdownMenuItem<String>(value: e, child: Text(e))).toList(),
|
||||
const Divider(),
|
||||
|
||||
ListTile(
|
||||
leading: const Icon(Icons.dark_mode_outlined),
|
||||
title: const Text("Farbgebung"),
|
||||
trailing: DropdownButton<ThemeMode>(
|
||||
value: settings.val().appTheme,
|
||||
icon: const Icon(Icons.arrow_drop_down),
|
||||
items: ThemeMode.values.map((e) => DropdownMenuItem<ThemeMode>(
|
||||
value: e,
|
||||
enabled: e != settings.val().appTheme,
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(AppTheme.getDisplayOptions(e).icon),
|
||||
const SizedBox(width: 10),
|
||||
Text(AppTheme.getDisplayOptions(e).displayName),
|
||||
],
|
||||
),
|
||||
)).toList(),
|
||||
onChanged: (e) {
|
||||
|
||||
setState(() {
|
||||
settings.val(write: true).appTheme = e!;
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
const Divider(),
|
||||
|
||||
ListTile(
|
||||
leading: const Icon(Icons.live_help_outlined),
|
||||
title: const Text("Informationen und Lizenzen"),
|
||||
onTap: () {
|
||||
PackageInfo.fromPlatform().then((appInfo) {
|
||||
showAboutDialog(
|
||||
context: context,
|
||||
applicationIcon: const Icon(Icons.apps),
|
||||
applicationName: "MarianumMobile",
|
||||
applicationVersion: "${appInfo.appName}\n\nPackage: ${appInfo.packageName}\n\nVersion: ${appInfo.version}\nBuild: ${appInfo.buildNumber}",
|
||||
applicationLegalese: "Dies ist ein Inoffizieller Nextcloud & Webuntis Client und wird nicht vom Marianum selbst betrieben.\n"
|
||||
"Keinerlei Gewähr für Vollständigkeit, Richtigkeit und Aktualität!\n\n"
|
||||
"Development build\n"
|
||||
"Marianum Fulda 2023 Elias Müller",
|
||||
);
|
||||
});
|
||||
},
|
||||
trailing: const Icon(Icons.arrow_right),
|
||||
),
|
||||
|
||||
ListTile(
|
||||
leading: const Icon(Icons.policy_outlined),
|
||||
title: const Text("Datenschutz"),
|
||||
onTap: () {
|
||||
launchUrl(Uri.parse("https://mhsl.eu/datenschutz.html"));
|
||||
},
|
||||
trailing: const Icon(Icons.open_in_new),
|
||||
),
|
||||
|
||||
ListTile(
|
||||
leading: const Icon(Icons.badge_outlined),
|
||||
title: const Text("Impressum"),
|
||||
onTap: () {
|
||||
launchUrl(Uri.parse("https://mhsl.eu/id.html"));
|
||||
},
|
||||
trailing: const Icon(Icons.open_in_new),
|
||||
),
|
||||
|
||||
const Divider(),
|
||||
|
||||
ListTile(
|
||||
leading: const Icon(Icons.developer_mode_outlined),
|
||||
title: const Text("Entwicklermodus"),
|
||||
trailing: Checkbox(
|
||||
visualDensity: const VisualDensity(horizontal: VisualDensity.minimumDensity),
|
||||
value: settings.val().devToolsEnabled,
|
||||
onChanged: (state) {
|
||||
setState(() {
|
||||
settings.val(write: true).devToolsEnabled = state ?? false;
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
Visibility(
|
||||
visible: settings.val().devToolsEnabled,
|
||||
child: Column(
|
||||
children: [
|
||||
ListTile(
|
||||
leading: const Icon(Icons.data_object),
|
||||
title: const Text("Storage view"),
|
||||
onTap: () {
|
||||
Navigator.push(context, MaterialPageRoute(builder: (context) {
|
||||
return const DebugOverview();
|
||||
}));
|
||||
},
|
||||
trailing: const Icon(Icons.arrow_right),
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.logo_dev_outlined),
|
||||
title: const Text("Logging verbosity"),
|
||||
trailing: DropdownButton<String>(
|
||||
value: "1",
|
||||
items: ["1", "2", "3"].map((e) => DropdownMenuItem<String>(value: e, child: Text(e))).toList(),
|
||||
onChanged: (e) {
|
||||
|
||||
},
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.settings_applications_outlined),
|
||||
title: const Text("Settings JSON dump"),
|
||||
onTap: () {
|
||||
JsonViewer.asDialog(context, settings.val().toJson());
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user