2024-02-12 18:43:57 +01:00
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
import 'package:flutter/cupertino.dart';
|
2023-12-25 19:03:52 +01:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
|
|
|
import 'package:settings_ui/settings_ui.dart';
|
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
|
2023-12-29 21:39:54 +01:00
|
|
|
/// Allows setting the type of graph for certain data
|
2023-12-25 19:03:52 +01:00
|
|
|
class GraphTypeSettingsView extends StatefulWidget {
|
2023-12-29 21:39:54 +01:00
|
|
|
/// Allows setting the type of graph for certain data
|
2023-12-25 19:03:52 +01:00
|
|
|
const GraphTypeSettingsView({super.key});
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<GraphTypeSettingsView> createState() => _GraphTypeSettingsViewState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _GraphTypeSettingsViewState extends State<GraphTypeSettingsView> {
|
|
|
|
var _yearly = 1;
|
|
|
|
var _monthly = 2;
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
SharedPreferences.getInstance().then((prefs) {
|
|
|
|
_yearly = prefs.getInt("yearlygraph") ?? 1;
|
|
|
|
_monthly = prefs.getInt("monthlygraph") ?? 2;
|
|
|
|
setState(() {});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
|
|
|
title: Text(AppLocalizations.of(context).graphType),
|
|
|
|
),
|
|
|
|
body: SettingsList(
|
|
|
|
applicationType: ApplicationType.both,
|
|
|
|
darkTheme: SettingsThemeData(
|
2023-12-29 21:39:54 +01:00
|
|
|
settingsListBackground: Theme.of(context).colorScheme.background,
|
|
|
|
titleTextColor: Theme.of(context).colorScheme.primary,
|
|
|
|
),
|
2023-12-25 19:03:52 +01:00
|
|
|
sections: [
|
|
|
|
SettingsSection(
|
|
|
|
tiles: [
|
|
|
|
SettingsTile.navigation(
|
|
|
|
title: Text(AppLocalizations.of(context).yearly),
|
2023-12-29 21:39:54 +01:00
|
|
|
value: Text(
|
|
|
|
_yearly == 1
|
|
|
|
? AppLocalizations.of(context).barChart
|
|
|
|
: AppLocalizations.of(context).lineChart,
|
|
|
|
),
|
2024-02-12 18:43:57 +01:00
|
|
|
onPressed: (c) {
|
|
|
|
if (Platform.isIOS) {
|
|
|
|
// iOS does not use Material widgets => no inkwell support
|
|
|
|
showCupertinoModalPopup<void>(
|
|
|
|
context: context,
|
|
|
|
builder: (ctx) => CupertinoActionSheet(
|
|
|
|
title: Text(AppLocalizations.of(context).selectType),
|
|
|
|
actions: [
|
|
|
|
CupertinoActionSheetAction(
|
|
|
|
onPressed: () async {
|
|
|
|
final s = await SharedPreferences.getInstance();
|
|
|
|
await s.setInt("yearlygraph", 1);
|
|
|
|
_yearly = 1;
|
|
|
|
if (!ctx.mounted) return;
|
|
|
|
Navigator.of(ctx).pop();
|
|
|
|
setState(() {});
|
|
|
|
},
|
|
|
|
child: Text(
|
|
|
|
AppLocalizations.of(context).barChart,
|
|
|
|
textAlign: TextAlign.center,
|
2023-12-25 19:03:52 +01:00
|
|
|
),
|
|
|
|
),
|
2024-02-12 18:43:57 +01:00
|
|
|
CupertinoActionSheetAction(
|
|
|
|
onPressed: () async {
|
|
|
|
final s = await SharedPreferences.getInstance();
|
|
|
|
await s.setInt("yearlygraph", 2);
|
|
|
|
_yearly = 2;
|
|
|
|
if (!ctx.mounted) return;
|
|
|
|
Navigator.of(ctx).pop();
|
|
|
|
setState(() {});
|
|
|
|
},
|
|
|
|
child: Text(
|
|
|
|
AppLocalizations.of(context).lineChart,
|
|
|
|
textAlign: TextAlign.center,
|
2023-12-25 19:03:52 +01:00
|
|
|
),
|
|
|
|
),
|
2024-02-10 16:00:15 +01:00
|
|
|
],
|
|
|
|
),
|
2024-02-12 18:43:57 +01:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
showAdaptiveDialog<void>(
|
|
|
|
context: c,
|
|
|
|
builder: (ctx) => AlertDialog.adaptive(
|
|
|
|
title: Text(AppLocalizations.of(context).selectType),
|
|
|
|
content: SizedBox(
|
|
|
|
height: 80,
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
SizedBox(
|
|
|
|
width: MediaQuery.of(ctx).size.width,
|
|
|
|
child: InkWell(
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.all(8),
|
|
|
|
child: Text(
|
|
|
|
AppLocalizations.of(context).barChart,
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
onTap: () async {
|
|
|
|
final s =
|
|
|
|
await SharedPreferences.getInstance();
|
|
|
|
await s.setInt("yearlygraph", 1);
|
|
|
|
_yearly = 1;
|
|
|
|
if (!ctx.mounted) return;
|
|
|
|
Navigator.of(ctx).pop();
|
|
|
|
setState(() {});
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
SizedBox(
|
|
|
|
width: MediaQuery.of(context).size.width,
|
|
|
|
child: InkWell(
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.all(8),
|
|
|
|
child: Text(
|
|
|
|
AppLocalizations.of(context).lineChart,
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
onTap: () async {
|
|
|
|
final s =
|
|
|
|
await SharedPreferences.getInstance();
|
|
|
|
await s.setInt("yearlygraph", 2);
|
|
|
|
_yearly = 2;
|
|
|
|
if (!ctx.mounted) return;
|
|
|
|
Navigator.of(ctx).pop();
|
|
|
|
setState(() {});
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
2023-12-25 19:03:52 +01:00
|
|
|
),
|
|
|
|
SettingsTile.navigation(
|
|
|
|
title: Text(AppLocalizations.of(context).monthly),
|
2023-12-29 21:39:54 +01:00
|
|
|
value: Text(
|
|
|
|
_monthly == 1
|
|
|
|
? AppLocalizations.of(context).barChart
|
|
|
|
: AppLocalizations.of(context).lineChart,
|
|
|
|
),
|
2024-02-12 18:43:57 +01:00
|
|
|
onPressed: (c) {
|
|
|
|
if (Platform.isIOS) {
|
|
|
|
// iOS does not use Material widgets => no inkwell support
|
|
|
|
showCupertinoModalPopup<void>(
|
|
|
|
context: context,
|
|
|
|
builder: (ctx) => CupertinoActionSheet(
|
|
|
|
title: Text(AppLocalizations.of(context).selectType),
|
|
|
|
actions: [
|
|
|
|
CupertinoActionSheetAction(
|
|
|
|
onPressed: () async {
|
|
|
|
final s = await SharedPreferences.getInstance();
|
|
|
|
await s.setInt("monthlygraph", 1);
|
|
|
|
_monthly = 1;
|
|
|
|
if (!ctx.mounted) return;
|
|
|
|
Navigator.of(ctx).pop();
|
|
|
|
setState(() {});
|
|
|
|
},
|
|
|
|
child: Text(
|
|
|
|
AppLocalizations.of(context).barChart,
|
|
|
|
textAlign: TextAlign.center,
|
2023-12-25 19:03:52 +01:00
|
|
|
),
|
|
|
|
),
|
2024-02-12 18:43:57 +01:00
|
|
|
CupertinoActionSheetAction(
|
|
|
|
onPressed: () async {
|
|
|
|
final s = await SharedPreferences.getInstance();
|
|
|
|
await s.setInt("monthlygraph", 2);
|
|
|
|
_monthly = 2;
|
|
|
|
if (!ctx.mounted) return;
|
|
|
|
Navigator.of(ctx).pop();
|
|
|
|
setState(() {});
|
|
|
|
},
|
|
|
|
child: Text(
|
|
|
|
AppLocalizations.of(context).lineChart,
|
|
|
|
textAlign: TextAlign.center,
|
2023-12-25 19:03:52 +01:00
|
|
|
),
|
|
|
|
),
|
2024-02-10 16:00:15 +01:00
|
|
|
],
|
|
|
|
),
|
2024-02-12 18:43:57 +01:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
showAdaptiveDialog<void>(
|
|
|
|
context: c,
|
|
|
|
builder: (ctx) => AlertDialog.adaptive(
|
|
|
|
title: Text(AppLocalizations.of(context).selectType),
|
|
|
|
content: SizedBox(
|
|
|
|
height: 80,
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
SizedBox(
|
|
|
|
width: MediaQuery.of(ctx).size.width,
|
|
|
|
child: InkWell(
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.all(8),
|
|
|
|
child: Text(
|
|
|
|
AppLocalizations.of(context).barChart,
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
onTap: () async {
|
|
|
|
final s =
|
|
|
|
await SharedPreferences.getInstance();
|
|
|
|
await s.setInt("monthlygraph", 1);
|
|
|
|
_monthly = 1;
|
|
|
|
if (!ctx.mounted) return;
|
|
|
|
Navigator.of(ctx).pop();
|
|
|
|
setState(() {});
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
SizedBox(
|
|
|
|
width: MediaQuery.of(context).size.width,
|
|
|
|
child: InkWell(
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.all(8),
|
|
|
|
child: Text(
|
|
|
|
AppLocalizations.of(context).lineChart,
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
onTap: () async {
|
|
|
|
final s =
|
|
|
|
await SharedPreferences.getInstance();
|
|
|
|
await s.setInt("monthlygraph", 2);
|
|
|
|
_monthly = 2;
|
|
|
|
if (!ctx.mounted) return;
|
|
|
|
Navigator.of(ctx).pop();
|
|
|
|
setState(() {});
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
2023-12-25 19:03:52 +01:00
|
|
|
),
|
|
|
|
],
|
2023-12-29 21:39:54 +01:00
|
|
|
),
|
2023-12-25 19:03:52 +01:00
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|