prasule/lib/views/settings/graph_type.dart
Matyáš Caras a37e73f066 feat: add income/expense graphs
Reviewed-on: #16
2023-12-25 21:43:25 +01:00

157 lines
6.2 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:prasule/pw/platformdialog.dart';
import 'package:settings_ui/settings_ui.dart';
import 'package:shared_preferences/shared_preferences.dart';
class GraphTypeSettingsView extends StatefulWidget {
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(
settingsListBackground: Theme.of(context).colorScheme.background,
titleTextColor: Theme.of(context).colorScheme.primary),
sections: [
SettingsSection(
tiles: [
SettingsTile.navigation(
title: Text(AppLocalizations.of(context).yearly),
value: Text(_yearly == 1
? AppLocalizations.of(context).barChart
: AppLocalizations.of(context).lineChart),
onPressed: (c) => showDialog(
context: c,
builder: (ctx) => PlatformDialog(
title: AppLocalizations.of(context).selectType,
content: Column(
children: [
SizedBox(
width: MediaQuery.of(ctx).size.width,
child: InkWell(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(AppLocalizations.of(context).barChart,
textAlign: TextAlign.center),
),
onTap: () async {
var s = await SharedPreferences.getInstance();
s.setInt("yearlygraph", 1);
_yearly = 1;
if (!mounted) return;
Navigator.of(ctx).pop();
setState(() {});
},
),
),
SizedBox(
width: MediaQuery.of(context).size.width,
child: InkWell(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
AppLocalizations.of(context).lineChart,
textAlign: TextAlign.center,
),
),
onTap: () async {
var s = await SharedPreferences.getInstance();
s.setInt("yearlygraph", 2);
_yearly = 2;
if (!mounted) return;
Navigator.of(ctx).pop();
setState(() {});
},
),
),
],
),
),
),
),
SettingsTile.navigation(
title: Text(AppLocalizations.of(context).monthly),
value: Text(_monthly == 1
? AppLocalizations.of(context).barChart
: AppLocalizations.of(context).lineChart),
onPressed: (c) => showDialog(
context: c,
builder: (ctx) => PlatformDialog(
title: AppLocalizations.of(context).selectType,
content: Column(
children: [
SizedBox(
width: MediaQuery.of(ctx).size.width,
child: InkWell(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
AppLocalizations.of(context).barChart,
textAlign: TextAlign.center,
),
),
onTap: () async {
var s = await SharedPreferences.getInstance();
s.setInt("monthlygraph", 1);
_monthly = 1;
if (!mounted) return;
Navigator.of(ctx).pop();
setState(() {});
},
),
),
SizedBox(
width: MediaQuery.of(ctx).size.width,
child: InkWell(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
AppLocalizations.of(context).lineChart,
textAlign: TextAlign.center),
),
onTap: () async {
var s = await SharedPreferences.getInstance();
s.setInt("monthlygraph", 2);
_monthly = 2;
if (!mounted) return;
Navigator.of(ctx).pop();
setState(() {});
},
),
),
],
),
),
),
),
],
)
],
),
);
}
}