Working auth and added shared notes
This commit is contained in:
@@ -26,256 +26,285 @@ class _BudgetOverviewScreenState extends ConsumerState<BudgetOverviewScreen> {
|
||||
final budgetListScrollController = ScrollController();
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final budgetCategories = ref.watch(Store().budgetCategoriesProvider);
|
||||
final transactions = ref.watch(Store().transactionsProvider);
|
||||
final budgetCategories = ref.watch(budgetCategoriesProvider);
|
||||
final transactions = ref.watch(transactionsProvider);
|
||||
final screen = BuildMedia(context).size;
|
||||
double netExpense = 0.0;
|
||||
double netIncome = 0.0;
|
||||
Map<int, double> budgetCategoryNetMap = {};
|
||||
netExpense = transactions
|
||||
.where((t) => t.type == TransactionType.expense)
|
||||
.fold(netExpense, (net, t) => net + t.amount);
|
||||
netIncome = transactions
|
||||
.where((t) => t.type == TransactionType.income)
|
||||
.fold(netIncome, (net, t) => net + t.amount);
|
||||
for (final bud in budgetCategories) {
|
||||
double net = 0.0;
|
||||
net = transactions
|
||||
.where((t) => t.budgetCategoryId == bud.id)
|
||||
.fold(net, (net, t) => net + t.amount);
|
||||
budgetCategoryNetMap[bud.id!] = net;
|
||||
}
|
||||
return RefreshIndicator(
|
||||
displacement: 20.0,
|
||||
onRefresh: () async {
|
||||
final family = ref.read(Store().familyProvider).valueOrNull;
|
||||
final _ =
|
||||
ref.read(Store().dashboardProvider.notifier).fetchDashboard(family);
|
||||
},
|
||||
child: Column(
|
||||
children: [
|
||||
/// TOP HALF, TITLE & OVERVIEW
|
||||
Container(
|
||||
height: screen.height * 0.3,
|
||||
width: screen.width,
|
||||
color: Styles.purpleNurple,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
const Spacer(flex: 2),
|
||||
Text(
|
||||
formatDate(DateTime.now()),
|
||||
style:
|
||||
const TextStyle(fontSize: 16, color: Styles.electricBlue),
|
||||
),
|
||||
const Spacer(),
|
||||
const Text('MONTHLY',
|
||||
style: TextStyle(fontSize: 42, color: Styles.electricBlue)),
|
||||
const Spacer(flex: 2),
|
||||
BudgetNetBar(isPositive: true, net: netIncome),
|
||||
const Spacer(),
|
||||
BudgetNetBar(isPositive: false, net: netExpense),
|
||||
const Spacer(),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
/// BOTTOM HALF, BUDGET BREAKDOWN
|
||||
Expanded(
|
||||
child: Container(
|
||||
color: Styles.sunflower,
|
||||
netExpense = transactions
|
||||
.where((t) => t.type == TransactionType.expense)
|
||||
.fold(netExpense, (net, t) => net + t.amount);
|
||||
netIncome = transactions
|
||||
.where((t) => t.type == TransactionType.income)
|
||||
.fold(netIncome, (net, t) => net + t.amount);
|
||||
for (final bud in budgetCategories) {
|
||||
double net = 0.0;
|
||||
net = transactions
|
||||
.where((t) => t.budgetCategoryId == bud.id)
|
||||
.fold(net, (net, t) => net + t.amount);
|
||||
budgetCategoryNetMap[bud.id!] = net;
|
||||
}
|
||||
return Stack(
|
||||
children: [
|
||||
Column(
|
||||
children: [
|
||||
/// TOP HALF, TITLE & OVERVIEW
|
||||
Container(
|
||||
height: screen.height * 0.3,
|
||||
width: screen.width,
|
||||
color: Styles.purpleNurple,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(14.0),
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Styles.blushingPink,
|
||||
borderRadius: BorderRadius.circular(16.0),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
const Padding(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
child: Text(
|
||||
'BUDGET',
|
||||
style: TextStyle(
|
||||
fontSize: 28, color: Styles.electricBlue),
|
||||
),
|
||||
),
|
||||
budgetCategories.isEmpty
|
||||
? Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: SizedBox(
|
||||
width: screen.width * 0.8,
|
||||
child: Column(
|
||||
children: [
|
||||
const Padding(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
child: Text(
|
||||
'No budget categories created yet, add some!'),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: ref.watch(
|
||||
Store().budgetProvider) ==
|
||||
null
|
||||
? null
|
||||
: () => showDialog(
|
||||
context: context,
|
||||
builder: (context) => Dialog(
|
||||
shape:
|
||||
Styles.dialogShape,
|
||||
backgroundColor:
|
||||
Styles.dialogColor,
|
||||
child:
|
||||
const AddBudgetCategoryDialog()),
|
||||
),
|
||||
child: const Text('Add Category'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
)
|
||||
: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 2.0, vertical: 4.0),
|
||||
child: SizedBox(
|
||||
height: screen.height * 0.36,
|
||||
child: Scrollbar(
|
||||
controller: budgetListScrollController,
|
||||
thumbVisibility: true,
|
||||
child: ListView(
|
||||
physics: const BouncingScrollPhysics(),
|
||||
controller: budgetListScrollController,
|
||||
shrinkWrap: true,
|
||||
children: [
|
||||
...budgetCategories
|
||||
.mapIndexed((i, category) {
|
||||
return BudgetCategoryBar(
|
||||
budgetCategory: category,
|
||||
currentAmount:
|
||||
budgetCategoryNetMap[
|
||||
category.id]!,
|
||||
index: i,
|
||||
);
|
||||
}).toList(),
|
||||
const SizedBox(height: 20),
|
||||
Row(
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment.center,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 140,
|
||||
child: ElevatedButton(
|
||||
onPressed: ref.watch(Store()
|
||||
.budgetProvider) ==
|
||||
null
|
||||
? null
|
||||
: () => showDialog(
|
||||
context: context,
|
||||
builder: (context) => Dialog(
|
||||
shape: Styles
|
||||
.dialogShape,
|
||||
backgroundColor:
|
||||
Styles
|
||||
.dialogColor,
|
||||
child:
|
||||
const AddBudgetCategoryDialog()),
|
||||
),
|
||||
child: const Text(
|
||||
'Add Category'),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const Spacer(flex: 2),
|
||||
Text(
|
||||
formatDate(DateTime.now()),
|
||||
style: const TextStyle(
|
||||
fontSize: 16, color: Styles.electricBlue),
|
||||
),
|
||||
const Spacer(),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Padding(
|
||||
padding:
|
||||
const EdgeInsets.only(left: 20.0, right: 15.0),
|
||||
child: Container(
|
||||
height: 70,
|
||||
decoration: BoxDecoration(
|
||||
color: Styles.seaweedGreen,
|
||||
borderRadius: BorderRadius.circular(15.0),
|
||||
),
|
||||
child: InkWell(
|
||||
child: const Center(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: 20.0, vertical: 14.0),
|
||||
child: FittedBox(
|
||||
child: Text(
|
||||
'Transaction History',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(fontSize: 25),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
const TransactionsListview()));
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(right: 20.0),
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Styles.purpleNurple,
|
||||
borderRadius: BorderRadius.circular(40.0),
|
||||
),
|
||||
height: 80,
|
||||
width: 80,
|
||||
child: IconButton(
|
||||
icon: const Icon(
|
||||
Icons.add,
|
||||
size: 48,
|
||||
color: Styles.lavender,
|
||||
),
|
||||
onPressed: () {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return Dialog(
|
||||
backgroundColor: Styles.dialogColor,
|
||||
shape: Styles.dialogShape,
|
||||
child: const AddTransactionDialog());
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const Text('MONTHLY',
|
||||
style:
|
||||
TextStyle(fontSize: 42, color: Styles.electricBlue)),
|
||||
const Spacer(flex: 2),
|
||||
BudgetNetBar(isPositive: true, net: netIncome),
|
||||
const Spacer(),
|
||||
BudgetNetBar(isPositive: false, net: netExpense),
|
||||
const Spacer(),
|
||||
],
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
|
||||
/// BOTTOM HALF, BUDGET BREAKDOWN
|
||||
Expanded(
|
||||
child: Container(
|
||||
color: Styles.sunflower,
|
||||
width: screen.width,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(14.0),
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Styles.blushingPink,
|
||||
borderRadius: BorderRadius.circular(16.0),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
const Padding(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
child: Text(
|
||||
'BUDGET',
|
||||
style: TextStyle(
|
||||
fontSize: 28, color: Styles.electricBlue),
|
||||
),
|
||||
),
|
||||
budgetCategories.isEmpty
|
||||
? Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: SizedBox(
|
||||
width: screen.width * 0.8,
|
||||
child: Column(
|
||||
children: [
|
||||
const Padding(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
child: Text(
|
||||
'No budget categories created yet, add some!'),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed:
|
||||
ref.watch(budgetProvider) ==
|
||||
null
|
||||
? null
|
||||
: () => showDialog(
|
||||
context: context,
|
||||
builder: (context) => Dialog(
|
||||
shape: Styles
|
||||
.dialogShape,
|
||||
backgroundColor:
|
||||
Styles
|
||||
.dialogColor,
|
||||
child:
|
||||
const AddBudgetCategoryDialog()),
|
||||
),
|
||||
child: const Text('Add Category'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
)
|
||||
: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 2.0, vertical: 4.0),
|
||||
child: SizedBox(
|
||||
height: screen.height * 0.36,
|
||||
child: Scrollbar(
|
||||
controller: budgetListScrollController,
|
||||
thumbVisibility: true,
|
||||
child: ListView(
|
||||
physics:
|
||||
const BouncingScrollPhysics(),
|
||||
controller:
|
||||
budgetListScrollController,
|
||||
shrinkWrap: true,
|
||||
children: [
|
||||
...budgetCategories
|
||||
.mapIndexed((i, category) {
|
||||
return BudgetCategoryBar(
|
||||
budgetCategory: category,
|
||||
currentAmount:
|
||||
budgetCategoryNetMap[
|
||||
category.id]!,
|
||||
index: i,
|
||||
);
|
||||
}).toList(),
|
||||
const SizedBox(height: 20),
|
||||
Row(
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment.center,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 140,
|
||||
child: ElevatedButton(
|
||||
onPressed: ref.watch(
|
||||
budgetProvider) ==
|
||||
null
|
||||
? null
|
||||
: () => showDialog(
|
||||
context: context,
|
||||
builder: (context) => Dialog(
|
||||
shape: Styles
|
||||
.dialogShape,
|
||||
backgroundColor:
|
||||
Styles
|
||||
.dialogColor,
|
||||
child:
|
||||
const AddBudgetCategoryDialog()),
|
||||
),
|
||||
child: const Text(
|
||||
'Add Category'),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Padding(
|
||||
padding:
|
||||
const EdgeInsets.only(left: 20.0, right: 15.0),
|
||||
child: Container(
|
||||
height: 70,
|
||||
decoration: BoxDecoration(
|
||||
color: Styles.seaweedGreen,
|
||||
borderRadius: BorderRadius.circular(15.0),
|
||||
),
|
||||
child: InkWell(
|
||||
child: const Center(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: 20.0, vertical: 14.0),
|
||||
child: FittedBox(
|
||||
child: Text(
|
||||
'Transaction History',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(fontSize: 25),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
const TransactionsListview()));
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(right: 20.0),
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Styles.purpleNurple,
|
||||
borderRadius: BorderRadius.circular(40.0),
|
||||
),
|
||||
height: 80,
|
||||
width: 80,
|
||||
child: IconButton(
|
||||
icon: const Icon(
|
||||
Icons.add,
|
||||
size: 48,
|
||||
color: Styles.lavender,
|
||||
),
|
||||
onPressed: () {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return Dialog(
|
||||
backgroundColor: Styles.dialogColor,
|
||||
shape: Styles.dialogShape,
|
||||
child: const AddTransactionDialog());
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const Spacer(),
|
||||
],
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
Align(
|
||||
alignment: Alignment.topRight,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(top: 5.0, right: 5.0),
|
||||
child: IconButton(
|
||||
icon: const Icon(Icons.loop),
|
||||
color: Styles.seaweedGreen,
|
||||
onPressed: () =>
|
||||
ref.read(dashboardProvider.notifier).fetchDashboard(),
|
||||
),
|
||||
),
|
||||
),
|
||||
IgnorePointer(
|
||||
child: AnimatedOpacity(
|
||||
duration: const Duration(milliseconds: 150),
|
||||
opacity: ref.watch(loadingStateProvider) ? 0.75 : 0.0,
|
||||
child: Container(
|
||||
color: Colors.black12,
|
||||
height: screen.height,
|
||||
width: screen.width,
|
||||
child: const Center(
|
||||
child: CircularProgressIndicator(
|
||||
color: Styles.lavender,
|
||||
strokeWidth: 2.5,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ class TransactionsListview extends ConsumerStatefulWidget {
|
||||
class _TransactionsListviewState extends ConsumerState<TransactionsListview> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final transactions = ref.watch(Store().transactionsProvider);
|
||||
final transactions = ref.watch(transactionsProvider);
|
||||
transactions.sort(
|
||||
(a, b) => b.date.compareTo(a.date),
|
||||
);
|
||||
|
||||
@@ -8,6 +8,8 @@ import 'package:rluv/models/budget_category_model.dart';
|
||||
|
||||
import '../../../global/api.dart';
|
||||
import '../../../global/store.dart';
|
||||
import '../../../global/utils.dart';
|
||||
import '../../../global/widgets/ui_button.dart';
|
||||
|
||||
class AddBudgetCategoryDialog extends ConsumerStatefulWidget {
|
||||
const AddBudgetCategoryDialog({super.key});
|
||||
@@ -19,8 +21,6 @@ class AddBudgetCategoryDialog extends ConsumerStatefulWidget {
|
||||
|
||||
class _AddBudgetCategoryDialogState
|
||||
extends ConsumerState<AddBudgetCategoryDialog> {
|
||||
bool loading = false;
|
||||
bool complete = false;
|
||||
late final Budget? budget;
|
||||
final categoryNameController = TextEditingController();
|
||||
final amountController = TextEditingController();
|
||||
@@ -34,7 +34,7 @@ class _AddBudgetCategoryDialogState
|
||||
final formKey = GlobalKey<FormState>();
|
||||
@override
|
||||
void initState() {
|
||||
budget = ref.read(Store().budgetProvider);
|
||||
budget = ref.read(budgetProvider);
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
categoryFocusNode.requestFocus();
|
||||
});
|
||||
@@ -46,20 +46,10 @@ class _AddBudgetCategoryDialogState
|
||||
if (budget == null) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
Navigator.pop(context);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('Could not get your budget'),
|
||||
),
|
||||
);
|
||||
});
|
||||
return Container();
|
||||
} else if (complete) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
Navigator.pop(context);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('Budget Category Added!'),
|
||||
),
|
||||
showSnack(
|
||||
ref: ref,
|
||||
text: 'Could not get your budget',
|
||||
type: SnackType.error,
|
||||
);
|
||||
});
|
||||
return Container();
|
||||
@@ -215,10 +205,20 @@ class _AddBudgetCategoryDialogState
|
||||
),
|
||||
),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () => submitCategory(colors[selectedColorIndex]),
|
||||
child: const Text('SAVE'),
|
||||
)
|
||||
UiButton(
|
||||
showLoading: true,
|
||||
color: Styles.lavender,
|
||||
text: 'SAVE',
|
||||
onPressed: () =>
|
||||
submitCategory(colors[selectedColorIndex]).then((_) {
|
||||
Navigator.pop(context);
|
||||
showSnack(
|
||||
ref: ref,
|
||||
text: 'Budget Category Added!',
|
||||
type: SnackType.success,
|
||||
);
|
||||
}),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -227,7 +227,6 @@ class _AddBudgetCategoryDialogState
|
||||
icon: const Icon(Icons.close),
|
||||
onPressed: () => Navigator.pop(context),
|
||||
),
|
||||
if (loading) const Center(child: CircularProgressIndicator()),
|
||||
],
|
||||
),
|
||||
);
|
||||
@@ -238,9 +237,6 @@ class _AddBudgetCategoryDialogState
|
||||
printPink('Failed validation');
|
||||
return;
|
||||
}
|
||||
setState(
|
||||
() => loading = true,
|
||||
);
|
||||
final newBudget = BudgetCategory(
|
||||
id: null,
|
||||
amount: double.parse(amountController.text),
|
||||
@@ -249,17 +245,16 @@ class _AddBudgetCategoryDialogState
|
||||
name: categoryNameController.text,
|
||||
);
|
||||
|
||||
final budgetData =
|
||||
await Api().post(path: 'budget_category', data: newBudget.toJson());
|
||||
final budgetData = await ref
|
||||
.read(apiProvider.notifier)
|
||||
.post(path: 'budget_category', data: newBudget.toJson());
|
||||
final success = budgetData != null ? budgetData['success'] as bool : false;
|
||||
if (success) {
|
||||
ref
|
||||
.read(Store().dashboardProvider.notifier)
|
||||
.read(dashboardProvider.notifier)
|
||||
.add({'budget_categories': budgetData});
|
||||
} else {
|
||||
showSnack(ref: ref, text: 'Could not add budget', type: SnackType.error);
|
||||
}
|
||||
complete = true;
|
||||
setState(() {
|
||||
loading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,10 +2,12 @@ import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:helpers/helpers/misc_build/build_media.dart';
|
||||
import 'package:rluv/global/utils.dart';
|
||||
|
||||
import '../../../global/api.dart';
|
||||
import '../../../global/store.dart';
|
||||
import '../../../global/styles.dart';
|
||||
import '../../../global/widgets/ui_button.dart';
|
||||
import '../../../models/budget_category_model.dart';
|
||||
import '../../../models/transaction_model.dart';
|
||||
|
||||
@@ -20,8 +22,7 @@ class AddTransactionDialog extends ConsumerStatefulWidget {
|
||||
}
|
||||
|
||||
class _AddTransactionDialogState extends ConsumerState<AddTransactionDialog> {
|
||||
bool loading = false;
|
||||
bool complete = false;
|
||||
late DateTime selectedDate;
|
||||
late final TextEditingController amountController;
|
||||
late final TextEditingController memoController;
|
||||
|
||||
@@ -38,11 +39,13 @@ class _AddTransactionDialogState extends ConsumerState<AddTransactionDialog> {
|
||||
TextEditingController(text: widget.transaction!.amount.toString());
|
||||
memoController = TextEditingController(text: widget.transaction!.memo);
|
||||
transactionType = widget.transaction!.type;
|
||||
selectedDate = widget.transaction!.date;
|
||||
} else {
|
||||
amountController = TextEditingController();
|
||||
memoController = TextEditingController();
|
||||
selectedDate = DateTime.now();
|
||||
}
|
||||
final categories = ref.read(Store().budgetCategoriesProvider);
|
||||
final categories = ref.read(budgetCategoriesProvider);
|
||||
if (categories.isNotEmpty) {
|
||||
selectedBudgetCategory = categories.first;
|
||||
}
|
||||
@@ -51,21 +54,8 @@ class _AddTransactionDialogState extends ConsumerState<AddTransactionDialog> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (complete) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
Navigator.pop(context);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(widget.transaction != null
|
||||
? 'Transaction updated!'
|
||||
: 'Transaction added!'),
|
||||
),
|
||||
);
|
||||
});
|
||||
return Container();
|
||||
}
|
||||
final List<BudgetCategory> budgetCategories =
|
||||
ref.read(Store().budgetCategoriesProvider);
|
||||
ref.read(budgetCategoriesProvider);
|
||||
return SizedBox(
|
||||
width: BuildMedia(context).width * Styles.dialogScreenWidthFactor,
|
||||
child: budgetCategories.isEmpty
|
||||
@@ -260,9 +250,20 @@ class _AddTransactionDialogState extends ConsumerState<AddTransactionDialog> {
|
||||
onFieldSubmitted: (_) {},
|
||||
),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: loading ? null : () => submitTransaction(),
|
||||
child: const Text('Add'),
|
||||
UiButton(
|
||||
showLoading: true,
|
||||
text: 'ADD',
|
||||
color: Styles.lavender,
|
||||
onPressed: () => submitTransaction().then((_) {
|
||||
Navigator.pop(context);
|
||||
showSnack(
|
||||
ref: ref,
|
||||
text: widget.transaction != null
|
||||
? 'Transaction updated!'
|
||||
: 'Transaction added!',
|
||||
type: SnackType.success,
|
||||
);
|
||||
}),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -270,12 +271,9 @@ class _AddTransactionDialogState extends ConsumerState<AddTransactionDialog> {
|
||||
}
|
||||
|
||||
Future submitTransaction() async {
|
||||
setState(() {
|
||||
loading = true;
|
||||
});
|
||||
Map<String, dynamic>? data;
|
||||
if (widget.transaction != null) {
|
||||
data = await Api().put(
|
||||
data = await ref.read(apiProvider.notifier).put(
|
||||
path: 'transactions',
|
||||
data: Transaction.copyWith(widget.transaction!, {
|
||||
'memo': memoController.text.isNotEmpty ? memoController.text : null,
|
||||
@@ -285,7 +283,7 @@ class _AddTransactionDialogState extends ConsumerState<AddTransactionDialog> {
|
||||
: selectedBudgetCategory.id,
|
||||
}).toJson());
|
||||
} else {
|
||||
data = await Api().post(
|
||||
data = await ref.read(apiProvider.notifier).post(
|
||||
path: 'transactions',
|
||||
data: Transaction(
|
||||
amount: double.parse(amountController.text),
|
||||
@@ -304,26 +302,17 @@ class _AddTransactionDialogState extends ConsumerState<AddTransactionDialog> {
|
||||
final success = data != null ? data['success'] as bool : false;
|
||||
if (success) {
|
||||
if (widget.transaction != null) {
|
||||
ref
|
||||
.read(Store().dashboardProvider.notifier)
|
||||
.update({'transactions': data});
|
||||
ref.read(dashboardProvider.notifier).update({'transactions': data});
|
||||
} else {
|
||||
ref
|
||||
.read(Store().dashboardProvider.notifier)
|
||||
.add({'transactions': data});
|
||||
ref.read(dashboardProvider.notifier).add({'transactions': data});
|
||||
}
|
||||
complete = true;
|
||||
} else {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(widget.transaction != null
|
||||
showSnack(
|
||||
ref: ref,
|
||||
text: widget.transaction != null
|
||||
? 'Failed to edit transaction'
|
||||
: 'Failed to add transaction'),
|
||||
),
|
||||
);
|
||||
: 'Failed to add transaction',
|
||||
type: SnackType.error);
|
||||
}
|
||||
setState(() {
|
||||
loading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ class BudgetCategoryBar extends StatefulWidget {
|
||||
required this.currentAmount,
|
||||
required this.index,
|
||||
this.height = 32,
|
||||
this.innerPadding = 1.5});
|
||||
this.innerPadding = 2.5});
|
||||
|
||||
final int index;
|
||||
final double currentAmount;
|
||||
@@ -27,6 +27,7 @@ class BudgetCategoryBar extends StatefulWidget {
|
||||
|
||||
class _BudgetCategoryBarState extends State<BudgetCategoryBar> {
|
||||
double percentSpent = 0.0;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
Future.delayed(Duration(milliseconds: min(1600, 200 * widget.index)), () {
|
||||
@@ -76,7 +77,7 @@ class _BudgetCategoryBarState extends State<BudgetCategoryBar> {
|
||||
height: widget.height,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.black,
|
||||
borderRadius: BorderRadius.circular(14.0),
|
||||
borderRadius: BorderRadius.circular(13.0),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
|
||||
@@ -35,8 +35,8 @@ class _TransactionListItemState extends ConsumerState<TransactionListItem> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final transaction = ref.watch(Store().transactionsProvider)[widget.index];
|
||||
final budgetCategories = ref.read(Store().budgetCategoriesProvider);
|
||||
final transaction = ref.watch(transactionsProvider)[widget.index];
|
||||
final budgetCategories = ref.read(budgetCategoriesProvider);
|
||||
if (transaction.type == TransactionType.expense) {
|
||||
budgetCategory = budgetCategories.singleWhere(
|
||||
(category) => category.id == transaction.budgetCategoryId,
|
||||
|
||||
Reference in New Issue
Block a user