prasule/lib/util/drawer.dart

98 lines
2.9 KiB
Dart
Raw Permalink Normal View History

2024-06-30 20:25:36 +02:00
// SPDX-FileCopyrightText: (C) 2024 Matyáš Caras
//
// SPDX-License-Identifier: AGPL-3.0-only
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:prasule/pw/platformroute.dart';
import 'package:prasule/views/debts/debt_view.dart';
2024-07-18 14:44:07 +02:00
import 'package:prasule/views/graphs/graph_view.dart';
import 'package:prasule/views/home.dart';
2024-07-18 14:44:07 +02:00
import 'package:prasule/views/recurring/recurring_view.dart';
/// Makes the drawer because I won't enter the same code in every view
Drawer makeDrawer(BuildContext context, Pages page) => Drawer(
child: ListView(
children: [
const DrawerHeader(child: Text("Prašule")),
ListTile(
leading: const Icon(Icons.home),
title: Text(
AppLocalizations.of(context).home,
),
selected: page == Pages.home,
onTap: () {
if (page == Pages.home) {
Navigator.of(context).pop();
return;
}
Navigator.of(context)
.pushReplacement(platformRoute((p0) => const HomeView()));
},
),
ListTile(
leading: const Icon(Icons.bar_chart),
title: Text(
AppLocalizations.of(context).graphs,
),
selected: page == Pages.graphs,
onTap: () {
if (page == Pages.graphs) {
Navigator.of(context).pop();
return;
}
Navigator.of(context)
.pushReplacement(platformRoute((p0) => const GraphView()));
},
),
ListTile(
leading: const Icon(Icons.repeat),
title: Text(
AppLocalizations.of(context).recurringPayments,
),
selected: page == Pages.recurringEntries,
onTap: () {
if (page == Pages.recurringEntries) {
Navigator.of(context).pop();
return;
}
Navigator.of(context).pushReplacement(
platformRoute((p0) => const RecurringEntriesView()),
);
},
),
ListTile(
leading: const Icon(Icons.people),
title: Text(
AppLocalizations.of(context).debts,
),
selected: page == Pages.debts,
onTap: () {
if (page == Pages.debts) {
Navigator.of(context).pop();
return;
}
Navigator.of(context).pushReplacement(
platformRoute((p0) => const DebtView()),
);
},
),
],
),
);
/// All the pages that drawer can navigate to
enum Pages {
/// [HomeView]
home,
/// [GraphView]
graphs,
/// [RecurringEntriesView]
recurringEntries,
/// [DebtView]
debts
}