Added working edit transaction

This commit is contained in:
Nathan Anderson
2023-07-22 21:29:32 -06:00
parent eba628bb4c
commit 18aad2b3d5
28 changed files with 1959 additions and 430 deletions
+251 -223
View File
@@ -1,15 +1,21 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:helpers/helpers.dart';
import 'package:rluv/features/budget/screens/transactions_listview.dart';
import 'package:rluv/features/budget/widgets/add_transaction_dialog.dart';
import 'package:rluv/features/budget/widgets/budget_category_bar.dart';
import 'package:rluv/features/budget/widgets/budget_net_bar.dart';
import 'package:rluv/global/styles.dart';
import 'package:rluv/global/utils.dart';
import '../../../global/store.dart';
import '../../../models/transaction_model.dart';
import '../widgets/add_budget_category_dialog.dart';
class BudgetOverviewScreen extends ConsumerStatefulWidget {
const BudgetOverviewScreen({super.key});
const BudgetOverviewScreen({super.key, required this.initialData});
final Map<String, dynamic> initialData;
@override
ConsumerState<BudgetOverviewScreen> createState() =>
@@ -20,234 +26,256 @@ class _BudgetOverviewScreenState extends ConsumerState<BudgetOverviewScreen> {
final budgetListScrollController = ScrollController();
@override
Widget build(BuildContext context) {
final budgetCategoriesRef = ref.watch(Store().budgetCategoriesProvider);
final budgetCategories = ref.watch(Store().budgetCategoriesProvider);
final transactions = ref.watch(Store().transactionsProvider);
final screen = BuildMedia(context).size;
return budgetCategoriesRef.when(
data: ((budgetCategories) => RefreshIndicator(
onRefresh: () async {
final _ = await ref.refresh(Store().dashboardProvider.future);
},
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: [
/// TOP HALF, TITLE & OVERVIEW
Container(
height: screen.height * 0.33,
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),
const BudgetNetBar(isPositive: true, net: 5024.64),
const Spacer(),
const BudgetNetBar(isPositive: false, net: 2004.37),
const Spacer(),
],
),
const Spacer(flex: 2),
Text(
formatDate(DateTime.now()),
style:
const TextStyle(fontSize: 16, color: Styles.electricBlue),
),
/// BOTTOM HALF, BUDGET BREAKDOWN
Expanded(
child: SizedBox(
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),
),
),
Scrollbar(
controller: budgetListScrollController,
thumbVisibility: true,
child: ListView(
controller: budgetListScrollController,
shrinkWrap: true,
children: [
for (final budget in budgetCategories)
Row(
children: [
Padding(
padding:
const EdgeInsets.all(8.0),
child: SizedBox(
width: 85,
child: Text(
budget.name,
style: const TextStyle(
fontSize: 16.0),
),
),
),
AnimatedContainer(
duration: const Duration(
milliseconds: 500),
child: Expanded(
child: Padding(
padding: const EdgeInsets.only(
right: 18.0),
child: Stack(
children: [
Container(
height: 30,
decoration: BoxDecoration(
color: Colors.black,
borderRadius:
BorderRadius
.circular(10.0),
),
),
Padding(
padding:
const EdgeInsets.all(
2.0),
child: Container(
height: 26,
decoration:
BoxDecoration(
color: Styles
.emptyBarGrey,
borderRadius:
BorderRadius
.circular(
10.0),
),
),
),
Padding(
padding:
const EdgeInsets.all(
2.0),
child: SizedBox(
height: 26,
child:
FractionallySizedBox(
heightFactor: 1.0,
widthFactor: 0.5,
child: Container(
decoration:
BoxDecoration(
color:
budget.color,
borderRadius:
BorderRadius
.circular(
10.0),
),
),
),
),
),
],
),
)),
)
],
),
const SizedBox(height: 20),
],
),
),
],
),
),
),
const Spacer(),
Padding(
padding: const EdgeInsets.only(bottom: 24.0),
child: 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: Text(
'Transaction History',
textAlign: TextAlign.center,
style: TextStyle(fontSize: 25),
),
),
),
onTap: () {
printRed('FIXME');
},
),
),
),
),
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 const AddTransactionDialog();
},
);
},
),
),
),
],
),
),
],
),
),
)
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(),
],
),
)),
loading: () => const CircularProgressIndicator(),
error: (error, stackTrace) => Text('Error: $error, \n\n$stackTrace'),
),
/// 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(
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(),
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(),
],
),
),
)
],
),
);
}
}
@@ -0,0 +1,63 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:rluv/features/budget/widgets/transaction_list_item.dart';
import 'package:rluv/global/styles.dart';
import '../../../global/store.dart';
class TransactionsListview extends ConsumerStatefulWidget {
const TransactionsListview({super.key});
@override
ConsumerState<TransactionsListview> createState() =>
_TransactionsListviewState();
}
class _TransactionsListviewState extends ConsumerState<TransactionsListview> {
@override
Widget build(BuildContext context) {
final transactions = ref.watch(Store().transactionsProvider);
transactions.sort(
(a, b) => b.date.compareTo(a.date),
);
return Scaffold(
backgroundColor: Styles.purpleNurple,
body: SafeArea(
child: Stack(
children: [
if (transactions.isEmpty) ...[
const Center(
child: Text('No transactions'),
),
],
if (transactions.isNotEmpty)
Column(
children: [
const SizedBox(height: 28),
const Text(
'Transaction History',
style: TextStyle(fontSize: 28),
textAlign: TextAlign.center,
),
Expanded(
child: ListView.builder(
physics: const BouncingScrollPhysics(),
itemCount: transactions.length,
itemBuilder: (BuildContext context, int index) {
return TransactionListItem(
index: index,
);
},
),
),
],
),
IconButton(
icon: const Icon(Icons.chevron_left),
onPressed: () => Navigator.pop(context)),
],
),
),
);
}
}