Compare commits
12 Commits
54cd86c34b
...
last_versi
Author | SHA1 | Date | |
---|---|---|---|
5425b22ba2 | |||
305012ffd4 | |||
8c31d868b9 | |||
9d478b9cbf | |||
452eb73773 | |||
631555af59 | |||
0f65166123 | |||
595aaefedc | |||
9d8a5e6685 | |||
2acabf4d3b | |||
15fa4aadbd | |||
78a407d0ec |
@ -7,6 +7,7 @@ import '/pages/income.dart';
|
||||
import '/pages/asset.dart';
|
||||
import '/pages/report.dart';
|
||||
import '/pages/settings.dart';
|
||||
import '/pages/help.dart';
|
||||
import '/db.dart';
|
||||
|
||||
void main() {
|
||||
@ -25,6 +26,12 @@ class MainApp extends StatelessWidget {
|
||||
useMaterial3: true,
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.green),
|
||||
),
|
||||
darkTheme: ThemeData(
|
||||
useMaterial3: true,
|
||||
brightness: Brightness.dark,
|
||||
colorSchemeSeed: Colors.green,
|
||||
),
|
||||
themeMode: ThemeMode.system,
|
||||
home: HomePage(),
|
||||
);
|
||||
}
|
||||
@ -64,13 +71,17 @@ class _HomePageState extends State<HomePage> {
|
||||
page = ProjectionPage();
|
||||
case 4:
|
||||
page = SettingsPage();
|
||||
case 5:
|
||||
page = HelpPage();
|
||||
default:
|
||||
throw UnimplementedError('No widget for page $pageSelected yet!');
|
||||
}
|
||||
|
||||
Future<void> addNewValue(BuildContext context) {
|
||||
return showDialog(
|
||||
context: context, builder: (_) => AlertDialog(content: dialog));
|
||||
context: context,
|
||||
builder: (_) => AlertDialog(content: dialog),
|
||||
);
|
||||
}
|
||||
|
||||
Widget? floatingButton;
|
||||
@ -88,7 +99,7 @@ class _HomePageState extends State<HomePage> {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: Text("Expense Tracker")),
|
||||
drawer: NavigationRail(
|
||||
extended: constraints.maxWidth >= 800,
|
||||
extended: true,
|
||||
destinations: [
|
||||
NavigationRailDestination(
|
||||
icon: Icon(Icons.payment),
|
||||
@ -110,6 +121,10 @@ class _HomePageState extends State<HomePage> {
|
||||
icon: Icon(Icons.settings),
|
||||
label: Text('Settings'),
|
||||
),
|
||||
NavigationRailDestination(
|
||||
icon: Icon(Icons.help),
|
||||
label: Text('Help'),
|
||||
),
|
||||
],
|
||||
selectedIndex: pageSelected,
|
||||
onDestinationSelected: (value) {
|
||||
|
@ -12,7 +12,16 @@ class Expense {
|
||||
required this.frequency,
|
||||
required this.description});
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return "$name, $cost, ${frequency.title}, $description";
|
||||
}
|
||||
|
||||
double calcComparableCost() {
|
||||
return cost * frequency.timesPerYear;
|
||||
}
|
||||
|
||||
double calcComparableCostDaily() {
|
||||
return cost / frequency.numDays;
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,63 @@
|
||||
// https://www.tutorialspoint.com/dart_programming/dart_programming_enumeration.htm
|
||||
enum Frequency {
|
||||
daily(title: "Daily"),
|
||||
weekly(title: "Weekly"),
|
||||
biweekly(title: "Biweekly"),
|
||||
montly(title: "Monthly"),
|
||||
yearly(title: "Yearly");
|
||||
daily(
|
||||
title: "Daily",
|
||||
hint: "Once Per Day",
|
||||
timesPerYear: 364.25,
|
||||
numDays: 1,
|
||||
),
|
||||
weekly(
|
||||
title: "Weekly",
|
||||
hint: "Once Per Week",
|
||||
timesPerYear: (364.25 / 7),
|
||||
numDays: 7,
|
||||
),
|
||||
biweekly(
|
||||
title: "Biweekly",
|
||||
hint: "Every Other Week",
|
||||
timesPerYear: (364.25 / 14),
|
||||
numDays: 14,
|
||||
),
|
||||
bimonthly(
|
||||
title: "Bimonthly",
|
||||
hint: "Twice Per Month",
|
||||
timesPerYear: 24,
|
||||
numDays: (364.25 / 24),
|
||||
),
|
||||
monthly(
|
||||
title: "Monthly",
|
||||
hint: "Once Per Month",
|
||||
timesPerYear: 12,
|
||||
numDays: (364.25 / 12),
|
||||
),
|
||||
quarterly(
|
||||
title: "Quarterly",
|
||||
hint: "Every Three Months",
|
||||
timesPerYear: 4,
|
||||
numDays: (364.25 / 4),
|
||||
),
|
||||
biannual(
|
||||
title: "Biannual",
|
||||
hint: "Twice Per Year",
|
||||
timesPerYear: 2,
|
||||
numDays: (364.25 / 2),
|
||||
),
|
||||
yearly(
|
||||
title: "Yearly",
|
||||
hint: "Once Per Year",
|
||||
timesPerYear: 1,
|
||||
numDays: 364.25,
|
||||
);
|
||||
|
||||
const Frequency({required this.title});
|
||||
const Frequency({
|
||||
required this.title,
|
||||
required this.hint,
|
||||
required this.timesPerYear,
|
||||
required this.numDays,
|
||||
});
|
||||
|
||||
final String title;
|
||||
final String hint;
|
||||
final double timesPerYear;
|
||||
final double numDays;
|
||||
}
|
||||
|
@ -7,33 +7,152 @@ import '/models/frequency.dart';
|
||||
|
||||
List<Expense> expenses = [];
|
||||
|
||||
class ExpensePage extends StatelessWidget {
|
||||
class ExpensePage extends StatefulWidget {
|
||||
const ExpensePage({
|
||||
super.key,
|
||||
});
|
||||
|
||||
@override
|
||||
State<ExpensePage> createState() => _ExpensePageState();
|
||||
}
|
||||
|
||||
class _ExpensePageState extends State<ExpensePage> {
|
||||
refresh() {
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
|
||||
expenses.sort(
|
||||
(a, b) => (b.calcComparableCost() - a.calcComparableCost()).toInt(),
|
||||
);
|
||||
|
||||
return expenses.isEmpty
|
||||
? Text("Add expenses to get started!")
|
||||
: ListView.builder(
|
||||
itemCount: expenses.length,
|
||||
itemBuilder: (_, index) {
|
||||
final Expense curr = expenses[index];
|
||||
return Center(
|
||||
child: Padding(
|
||||
final String estimateSymbolYearly = curr.frequency.timesPerYear
|
||||
.toStringAsFixed(2)
|
||||
.endsWith(".00") &&
|
||||
curr.calcComparableCost().toStringAsFixed(3).endsWith("0")
|
||||
? ""
|
||||
: "~";
|
||||
final String estimateSymbolDaily =
|
||||
curr.frequency.numDays.toStringAsFixed(2).endsWith(".00") &&
|
||||
curr
|
||||
.calcComparableCostDaily()
|
||||
.toStringAsFixed(3)
|
||||
.endsWith("0")
|
||||
? ""
|
||||
: "~";
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(4.0),
|
||||
child: Dismissible(
|
||||
key: Key(curr.toString()),
|
||||
background: Container(
|
||||
color: Colors.red,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
Icon(Icons.delete),
|
||||
Text("Delete"),
|
||||
],
|
||||
),
|
||||
),
|
||||
secondaryBackground: Container(
|
||||
color: Colors.orange,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
Text("Edit"),
|
||||
Icon(Icons.edit),
|
||||
],
|
||||
),
|
||||
),
|
||||
onDismissed: (direction) {
|
||||
setState(() {
|
||||
expenses.remove(curr);
|
||||
});
|
||||
switch (direction) {
|
||||
case DismissDirection.startToEnd:
|
||||
// Only remove the item from the list.
|
||||
break;
|
||||
case DismissDirection.endToStart:
|
||||
// Open an edit dialog, then remove the item from the list.
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (_) => AlertDialog(
|
||||
content: ExpenseInputDialog(
|
||||
notifyParent: refresh,
|
||||
expense: curr,
|
||||
),
|
||||
),
|
||||
);
|
||||
break;
|
||||
default:
|
||||
UnimplementedError(
|
||||
"Direction ${direction.toString()} not recognized.",
|
||||
);
|
||||
}
|
||||
},
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
color: Colors.greenAccent,
|
||||
color: theme.colorScheme.onPrimary,
|
||||
),
|
||||
child: Column(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(4.0),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
children: [
|
||||
Text(curr.name),
|
||||
Text("${curr.cost.toString()} ${curr.frequency.title}"),
|
||||
Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
curr.name,
|
||||
style: TextStyle(fontSize: 20.0),
|
||||
),
|
||||
Text(
|
||||
"${curr.cost.toStringAsFixed(2)} ${curr.frequency.title}",
|
||||
style: TextStyle(fontSize: 12.0),
|
||||
),
|
||||
],
|
||||
),
|
||||
Expanded(
|
||||
child: Center(
|
||||
child: Text(
|
||||
curr.description,
|
||||
style: TextStyle(
|
||||
fontSize: 12.0,
|
||||
),
|
||||
softWrap: true,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
//if (curr.frequency != Frequency.daily)
|
||||
Text(
|
||||
"$estimateSymbolDaily${curr.calcComparableCostDaily().toStringAsFixed(2)} ${Frequency.daily.title}",
|
||||
style: TextStyle(fontSize: 12.0),
|
||||
),
|
||||
//if (curr.frequency != Frequency.yearly)
|
||||
Text(
|
||||
"$estimateSymbolYearly${curr.calcComparableCost().toStringAsFixed(2)} ${Frequency.yearly.title}",
|
||||
style: TextStyle(fontSize: 12.0),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
@ -44,9 +163,12 @@ class ExpensePage extends StatelessWidget {
|
||||
|
||||
class ExpenseInputDialog extends StatefulWidget {
|
||||
final Function() notifyParent;
|
||||
final Expense? expense;
|
||||
|
||||
const ExpenseInputDialog({
|
||||
super.key,
|
||||
required this.notifyParent,
|
||||
this.expense,
|
||||
});
|
||||
|
||||
@override
|
||||
@ -57,62 +179,128 @@ class _ExpenseInputDialogState extends State<ExpenseInputDialog> {
|
||||
final _expenseFormKey = GlobalKey<FormState>();
|
||||
|
||||
String _name = "";
|
||||
double _cost = 0.0;
|
||||
Frequency _freq = Frequency.montly;
|
||||
double _cost = 0;
|
||||
Frequency _freq = Frequency.monthly;
|
||||
String _desc = "";
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AlertDialog(
|
||||
if (widget.expense != null) {
|
||||
_name = widget.expense!.name;
|
||||
_cost = widget.expense!.cost;
|
||||
_freq = widget.expense!.frequency;
|
||||
_desc = widget.expense!.description;
|
||||
}
|
||||
|
||||
return Column(
|
||||
// prevent AlertDialog from taking full vertical height.
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Container(
|
||||
alignment: FractionalOffset.topRight,
|
||||
child: IconButton(
|
||||
onPressed: () {
|
||||
if (widget.expense != null) {
|
||||
setState(() {
|
||||
expenses.add(widget.expense!);
|
||||
widget.notifyParent();
|
||||
});
|
||||
}
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
icon: Icon(Icons.clear),
|
||||
),
|
||||
),
|
||||
AlertDialog(
|
||||
insetPadding: EdgeInsets.all(0),
|
||||
title: Center(
|
||||
child: Text("New Expense"),
|
||||
child: widget.expense == null
|
||||
? Text("New Expense")
|
||||
: Text("Edit Expense"),
|
||||
),
|
||||
content: Form(
|
||||
key: _expenseFormKey,
|
||||
//autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
//spacing: 10,
|
||||
children: [
|
||||
TextFormField(
|
||||
keyboardType: TextInputType.text,
|
||||
textCapitalization: TextCapitalization.words,
|
||||
decoration: InputDecoration(
|
||||
labelText: "Name",
|
||||
hintText: "Example: Red Pocket Phone Bill",
|
||||
hintText: "Example: Red Pocket",
|
||||
hintStyle: TextStyle(fontSize: 10.0),
|
||||
errorStyle: TextStyle(fontSize: 10.0),
|
||||
),
|
||||
initialValue: _name,
|
||||
validator: (value) {
|
||||
if (value!.isEmpty) {
|
||||
return "Name must be provided.";
|
||||
}
|
||||
if (!expenses.every((expense) => expense.name != value)) {
|
||||
return "Name must be unique, already in use.";
|
||||
}
|
||||
return null;
|
||||
},
|
||||
onSaved: (newValue) {
|
||||
_name = newValue!;
|
||||
onSaved: (value) {
|
||||
_name = value!;
|
||||
},
|
||||
),
|
||||
TextFormField(
|
||||
keyboardType: TextInputType.numberWithOptions(decimal: true),
|
||||
decoration: InputDecoration(
|
||||
labelText: "Cost", hintText: "Example: 10.00"),
|
||||
labelText: "Cost",
|
||||
hintText: "Example: 10.00",
|
||||
hintStyle: TextStyle(fontSize: 10.0),
|
||||
errorStyle: TextStyle(fontSize: 10.0),
|
||||
),
|
||||
initialValue: _cost != 0 ? _cost.toString() : "",
|
||||
validator: (value) {
|
||||
if (value!.isEmpty) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return "Cost must be provided.";
|
||||
}
|
||||
if (double.parse(value) < 0) {
|
||||
return "Please use the Income page rather than having negative expenses.";
|
||||
}
|
||||
if (double.parse(value) < 0.01) {
|
||||
return "Cost must be one hundreth (0.01) or higher.";
|
||||
}
|
||||
if (double.tryParse(value) == null) {
|
||||
return "Cost must be a valid number.";
|
||||
}
|
||||
return null;
|
||||
},
|
||||
onSaved: (newValue) {
|
||||
_cost = double.parse(newValue!);
|
||||
onSaved: (value) {
|
||||
_cost = double.parse(value!);
|
||||
},
|
||||
),
|
||||
DropdownButtonFormField(
|
||||
items: (Frequency.values.map((freq) =>
|
||||
DropdownMenuItem(value: freq, child: Text(freq.title))))
|
||||
items: Frequency.values
|
||||
.map(
|
||||
(freq) => DropdownMenuItem(
|
||||
value: freq,
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
freq.title,
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsets.all(1.0),
|
||||
child: Text(
|
||||
" (${freq.hint})",
|
||||
style: TextStyle(fontSize: 10.0),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
value: _freq,
|
||||
decoration: InputDecoration(
|
||||
labelText: "Recurrence", hintText: "Example: Monthly"),
|
||||
labelText: "Frequency",
|
||||
errorStyle: TextStyle(fontSize: 10.0),
|
||||
),
|
||||
validator: (value) {
|
||||
if (value == null) {
|
||||
return "Frequency must be provided.";
|
||||
@ -122,38 +310,33 @@ class _ExpenseInputDialogState extends State<ExpenseInputDialog> {
|
||||
}
|
||||
return null;
|
||||
},
|
||||
onChanged: (newValue) {
|
||||
_freq = newValue!;
|
||||
onChanged: (value) {
|
||||
_freq = value!;
|
||||
},
|
||||
),
|
||||
TextFormField(
|
||||
keyboardType: TextInputType.text,
|
||||
textCapitalization: TextCapitalization.sentences,
|
||||
decoration: InputDecoration(
|
||||
labelText: "Description",
|
||||
hintText: "Example: 1GB data with unlimited talk & text."),
|
||||
hintText: "Example: 1GB data with unlimited talk & text.",
|
||||
hintStyle: TextStyle(fontSize: 8.0),
|
||||
errorStyle: TextStyle(fontSize: 10.0),
|
||||
),
|
||||
initialValue: _desc,
|
||||
validator: (value) {
|
||||
return null;
|
||||
},
|
||||
onSaved: (newValue) {
|
||||
_desc = newValue!;
|
||||
onSaved: (value) {
|
||||
_desc = value!;
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
ElevatedButton.icon(
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
icon: Icon(Icons.cancel),
|
||||
label: Text('Cancel'),
|
||||
),
|
||||
ElevatedButton.icon(
|
||||
Center(
|
||||
child: ElevatedButton.icon(
|
||||
onPressed: () {
|
||||
if (_expenseFormKey.currentState!.validate()) {
|
||||
_expenseFormKey.currentState!.save();
|
||||
@ -173,9 +356,10 @@ class _ExpenseInputDialogState extends State<ExpenseInputDialog> {
|
||||
icon: Icon(Icons.save),
|
||||
label: Text('Submit'),
|
||||
),
|
||||
],
|
||||
)
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
72
lib/pages/help.dart
Normal file
72
lib/pages/help.dart
Normal file
@ -0,0 +1,72 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class HelpPage extends StatelessWidget {
|
||||
const HelpPage({
|
||||
super.key,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
color: theme.colorScheme.onPrimary,
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
Text("This app is meant to be a simple budgeting tool,"
|
||||
" allowing you to view your income and expenses at a high level"
|
||||
" without micro managing specific budget items or adding receipts."),
|
||||
//Text("Another paragraph.")
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
color: theme.colorScheme.onPrimary,
|
||||
),
|
||||
child: TextButton.icon(
|
||||
onPressed: () {},
|
||||
icon: Icon(Icons.code),
|
||||
label: Text("Code Repository"),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
color: theme.colorScheme.onPrimary,
|
||||
),
|
||||
child: TextButton.icon(
|
||||
onPressed: () {},
|
||||
icon: Icon(Icons.web_asset),
|
||||
label: Text("Personal Website"),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
@ -7,12 +7,6 @@ class IncomePage extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Center(
|
||||
child: Column(
|
||||
children: [
|
||||
Text("TBD"),
|
||||
Placeholder(),
|
||||
],
|
||||
));
|
||||
return Placeholder();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user