131 lines
3.1 KiB
Dart
131 lines
3.1 KiB
Dart
// Flutter
|
|
import 'package:flutter/material.dart';
|
|
|
|
// Local
|
|
import '/pages/expense.dart';
|
|
import '/pages/income.dart';
|
|
import '/pages/asset.dart';
|
|
import '/pages/report.dart';
|
|
import '/pages/settings.dart';
|
|
import '/db.dart';
|
|
|
|
void main() {
|
|
loadDB();
|
|
runApp(const MainApp());
|
|
}
|
|
|
|
class MainApp extends StatelessWidget {
|
|
const MainApp({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MaterialApp(
|
|
title: 'Recurring Expense Tracker',
|
|
theme: ThemeData(
|
|
useMaterial3: true,
|
|
colorScheme: ColorScheme.fromSeed(seedColor: Colors.green),
|
|
),
|
|
home: HomePage(),
|
|
);
|
|
}
|
|
}
|
|
|
|
class HomePage extends StatefulWidget {
|
|
const HomePage({
|
|
super.key,
|
|
});
|
|
|
|
@override
|
|
State<HomePage> createState() => _HomePageState();
|
|
}
|
|
|
|
class _HomePageState extends State<HomePage> {
|
|
var pageSelected = 0;
|
|
|
|
refresh() {
|
|
setState(() {});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
Widget page;
|
|
Widget? dialog;
|
|
switch (pageSelected) {
|
|
case 0:
|
|
page = ExpensePage();
|
|
dialog = ExpenseInputDialog(
|
|
notifyParent: refresh,
|
|
);
|
|
case 1:
|
|
page = IncomePage();
|
|
case 2:
|
|
page = AssetPage();
|
|
case 3:
|
|
page = ProjectionPage();
|
|
case 4:
|
|
page = SettingsPage();
|
|
default:
|
|
throw UnimplementedError('No widget for page $pageSelected yet!');
|
|
}
|
|
|
|
Future<void> addNewValue(BuildContext context) {
|
|
return showDialog(
|
|
context: context, builder: (_) => AlertDialog(content: dialog));
|
|
}
|
|
|
|
Widget? floatingButton;
|
|
if (dialog != null) {
|
|
floatingButton = IconButton(
|
|
onPressed: () {
|
|
addNewValue(context);
|
|
},
|
|
icon: Icon(Icons.add),
|
|
color: Theme.of(context).colorScheme.onSurface,
|
|
);
|
|
}
|
|
|
|
return LayoutBuilder(builder: (context, constraints) {
|
|
return Scaffold(
|
|
appBar: AppBar(title: Text("Expense Tracker")),
|
|
drawer: NavigationRail(
|
|
extended: constraints.maxWidth >= 800,
|
|
destinations: [
|
|
NavigationRailDestination(
|
|
icon: Icon(Icons.payment),
|
|
label: Text('Expenses'),
|
|
),
|
|
NavigationRailDestination(
|
|
icon: Icon(Icons.account_balance),
|
|
label: Text('Income'),
|
|
),
|
|
NavigationRailDestination(
|
|
icon: Icon(Icons.attach_money),
|
|
label: Text('Liquid Assets'),
|
|
),
|
|
NavigationRailDestination(
|
|
icon: Icon(Icons.bar_chart),
|
|
label: Text('Reports'),
|
|
),
|
|
NavigationRailDestination(
|
|
icon: Icon(Icons.settings),
|
|
label: Text('Settings'),
|
|
),
|
|
],
|
|
selectedIndex: pageSelected,
|
|
onDestinationSelected: (value) {
|
|
setState(() {
|
|
pageSelected = value;
|
|
Navigator.pop(context);
|
|
});
|
|
},
|
|
),
|
|
body: Container(
|
|
color: Theme.of(context).colorScheme.primaryContainer,
|
|
child: Center(child: page),
|
|
),
|
|
floatingActionButton: floatingButton,
|
|
);
|
|
});
|
|
}
|
|
}
|