Skip to content

Commit

Permalink
feature-complete: categories and transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
rishabdhar12 committed Sep 4, 2024
1 parent a48016a commit a777d01
Show file tree
Hide file tree
Showing 14 changed files with 411 additions and 175 deletions.
61 changes: 41 additions & 20 deletions lib/core/common/data_table_view.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:budgeting_app/core/common/text.dart';
import 'package:budgeting_app/core/constants/colors.dart';
import 'package:budgeting_app/core/constants/strings.dart';
import 'package:budgeting_app/features/categories/domain/entities/local/categories_schema_isar.dart';
import 'package:flutter/material.dart';

Expand All @@ -17,26 +18,46 @@ class _DataTableViewState extends State<DataTableView> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Table(
columnWidths: {
0: FixedColumnWidth(MediaQuery.of(context).size.width * 0.50),
1: FixedColumnWidth(MediaQuery.of(context).size.width * 0.25),
2: FixedColumnWidth(MediaQuery.of(context).size.width * 0.25),
},
children: widget.categories!
.where((category) => category.duration == widget.duration)
.map((category) {
return TableRow(
children: [
_buildCell(category.name,
icon:
IconData(category.iconCode, fontFamily: 'MaterialIcons')),
_buildCell(category.amount.toString()),
_buildCell(category.totalDeducted.toString()),
],
);
}).toList(),
),
body: widget.categories!
.where((category) => category.duration == widget.duration)
.toList()
.isEmpty
? Center(
// crossAxisAlignment: CrossAxisAlignment.center,
child: textWidget(
text: widget.duration == AppStrings.daily
? AppStrings.nothingToShowToday
: widget.duration == AppStrings.weekly
? AppStrings.nothingToShowWeekly
: AppStrings.nothingToShowMonth,
color: ColorCodes.white,
fontSize: 18.0,
textAlign: TextAlign.center,
),
)
: Table(
columnWidths: {
0: FixedColumnWidth(MediaQuery.of(context).size.width * 0.50),
1: FixedColumnWidth(MediaQuery.of(context).size.width * 0.25),
2: FixedColumnWidth(MediaQuery.of(context).size.width * 0.25),
},
children: widget.categories!
.where((category) => category.duration == widget.duration)
.toList()
.reversed
.take(3)
.map((category) {
return TableRow(
children: [
_buildCell(category.name,
icon: IconData(category.iconCode,
fontFamily: 'MaterialIcons')),
_buildCell(category.amount.toString()),
_buildCell(category.totalDeducted.toString()),
],
);
}).toList(),
),
);
}
}
Expand Down
23 changes: 18 additions & 5 deletions lib/core/common/show_balance.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,33 @@ class ShowBalance extends StatefulWidget {
}

double totalBalance = 0.00;
double totalExpense = 0.00;
double percent = 0.00;

class _ShowBalanceState extends State<ShowBalance> {
calcTotalBalance(List<Categories>? categories) {
totalBalance = 0.00;
totalExpense = 0.00;
if (categories!.isNotEmpty) {
for (Categories category in categories) {
totalBalance += category.amount;
totalExpense += category.totalDeducted;
}
}
}

calcPercent() {
percent = ((totalExpense * 100) / totalBalance);
}

@override
Widget build(BuildContext context) {
return BlocBuilder<LocalCategoriesBloc, LocalCategoriesState>(
builder: (context, state) {
if (state is LocalCategoriesFetchedState) {
final categories = state.categories;
calcTotalBalance(categories);
calcPercent();

return Column(
crossAxisAlignment: CrossAxisAlignment.start,
Expand Down Expand Up @@ -82,10 +91,12 @@ class _ShowBalanceState extends State<ShowBalance> {
),
const SizedBox(height: 2),
textWidget(
text: "-${AppStrings.rupee} 0.00",
text: "-${AppStrings.rupee} $totalExpense",
fontSize: 22.0,
fontWeight: FontWeight.bold,
color: ColorCodes.blue,
color: percent >= 80.00
? ColorCodes.red
: ColorCodes.blue,
),
],
),
Expand All @@ -98,20 +109,22 @@ class _ShowBalanceState extends State<ShowBalance> {
curve: Curves.easeInOut,
tween: Tween<double>(
begin: 0,
end: totalBalance != 0 ? totalBalance - 2000.00 : 0.00,
end: totalBalance != 0 ? totalBalance - totalExpense : 0.00,
),
builder: (context, value, _) => LinearProgressIndicator(
minHeight: 10.0,
borderRadius: BorderRadius.circular(12.0),
backgroundColor: ColorCodes.darkGreen,
value: totalBalance != 0 ? value / totalBalance : 0,
value: totalBalance != 0 ? totalExpense / totalBalance : 0,
valueColor:
const AlwaysStoppedAnimation<Color>(ColorCodes.white),
),
),
const SizedBox(height: 4.0),
textWidget(
text: "30% ${AppStrings.percentOfIncome}", fontSize: 12.0),
text:
"${percent.toStringAsFixed(2)} ${percent < 50.0 ? AppStrings.percentOfIncomeGood : percent < 80.0 ? AppStrings.percentOfIncomeWarning : AppStrings.percentOfIncomeExceed}",
fontSize: 12.0),
],
);
}
Expand Down
2 changes: 2 additions & 0 deletions lib/core/common/text_form_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Widget textFormField({
double contentPaddingVertical = 16.0,
void Function(String)? onChanged,
String? prefixText,
int maxLines = 1,
}) {
return Container(
height: height,
Expand All @@ -32,6 +33,7 @@ Widget textFormField({
enabled: enabled,
validator: validator,
onChanged: onChanged,
maxLines: maxLines,
decoration: InputDecoration(
prefixText: prefixText,
suffixIcon: suffixIcon,
Expand Down
2 changes: 2 additions & 0 deletions lib/core/constants/colors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
class ColorCodes {
static const splashBackground = Color(0xFF00D09E);
static const appBackground = Color(0xFF052224);
static const appBackgroundWithTransparency = Color(0xFF093030);
static const buttonColor = Color(0xFF00D09E);
static const lightGreen = Color(0xFFDFF7E2);
static const yellow = Color.fromARGB(255, 247, 247, 103);
Expand All @@ -14,4 +15,5 @@ class ColorCodes {
static const blue = Color(0xFF3299FF);
static const darkBlue = Color(0xFF0068FF);
static const lightBlue = Color(0xFF6DB6FE);
static const red = Colors.red;
}
19 changes: 18 additions & 1 deletion lib/core/constants/strings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,34 @@ class AppStrings {
static const String monthly = "Monthly";
static const String totalBalance = "Total Balance";
static const String totalExpense = "Total Expense";
static const String percentOfIncome = "% of your income, Looks Good";
static const String percentOfIncomeGood =
"% of your budget – Right on the Money!";
static const String percentOfIncomeWarning =
"% of your budget – Tread Lightly!";
static const String percentOfIncomeExceed =
"% of your budget – Whoa, Slow Down!";
static const String savingsOnGoals = "Savings\non Goals";
static const String revenueDuration = "Revenue Last";
static const String savingsDuration = "Savings Last";
static const String add = "Add";
static const String nothingToShow = "Nothing to show!";
static const String nothingToShowToday = "No fresh transactions for today!";
static const String nothingToShowWeekly =
"No fresh transactions for this week!";
static const String nothingToShowMonth =
"No fresh transactions for this month!";
static const String newCategory = "New Category";
static const String categoryName = "Category Name";
static const String save = "Save";
static const String cancel = "Cancel";
static const String enterAmount = "Enter Amount";
static const String amountFormText = "Amount spent";
static const String allFieldsMandatory = "All fields are mandatory";
static const String addExpense = "Add Expense";
static const String noTransactions =
"Looks like your wallet's been on vacation! 🏖️ \n\nNo transactions to show.";
static const String enterDate = "Enter Date";
static const String expenseTitle = "Expense Title";
static const String expenseText = "What did you spend on?";
static const String message = "Additional info";
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:developer';

import 'package:budgeting_app/core/common/back_button.dart';
import 'package:budgeting_app/core/common/date_picker.dart';
import 'package:budgeting_app/core/common/elevated_button.dart';
import 'package:budgeting_app/core/common/text.dart';
Expand Down Expand Up @@ -97,25 +98,11 @@ class _SignUpScreenState extends State<SignUpScreen> {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
GestureDetector(
onTap: () {
backButton(
context,
onPressed: () {
context.go(RouteNames.loginOrSignUp);
},
child: Container(
width: 56.0,
height: 56.0,
decoration: const BoxDecoration(
color: ColorCodes.buttonColor,
shape: BoxShape.circle,
),
child: const Center(
child: Icon(
CupertinoIcons.back,
color: ColorCodes.appBackground,
size: 39.0,
),
),
),
),
SizedBox(
height: MediaQuery.of(context).size.height / 8,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,16 @@ class CategoriesTxnScreen extends StatefulWidget {

final TextEditingController _newCategoryController = TextEditingController();
final TextEditingController _amountController = TextEditingController();
String _selectedDuration = "Monthly";
String _selectedDuration = AppStrings.monthly;

class _CategoriesTxnScreenState extends State<CategoriesTxnScreen> {
@override
void initState() {
// _selectedDuration = "Monthly";
BlocProvider.of<LocalCategoriesBloc>(context)
.add(const GetCategoriesEvent());
super.initState();
}

// @override
// void dispose() {
// _newCategoryController.dispose();
// _amountController.dispose();
// super.dispose();
// }

@override
Widget build(BuildContext context) {
return Scaffold(
Expand Down Expand Up @@ -166,14 +158,17 @@ class _CategoriesTxnScreenState extends State<CategoriesTxnScreen> {
return AlertDialog(
backgroundColor: ColorCodes.appBackground,
content: SizedBox(
// padding: const EdgeInsets.symmetric(vertical: 20.0),
width: MediaQuery.of(context).size.width,
child: Column(
mainAxisSize: MainAxisSize.min,
height: 480.0,
child: ListView(
// mainAxisSize: MainAxisSize.min,
children: <Widget>[
Container(
height: 50.0,
width: 50.0,
padding: const EdgeInsets.all(4.0),
margin: const EdgeInsets.symmetric(horizontal: 100.0),
decoration: BoxDecoration(
color: ColorCodes.lightBlue,
borderRadius: BorderRadius.circular(10.0),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class BottomNavigationBloc
BottomNavigationBloc() : super(const HomeState()) {
on<HomeEvent>(_onLoadHome);
on<AnalysisEvent>(_onLoadAnalysis);
on<TransactionEvent>(_onLoadTransaction);
// on<TransactionEvent>(_onLoadTransaction);
on<CategoriesTxnEvent>(_onLoadCategoriesTxn);
on<ProfileEvent>(_onLoadProfile);
}
Expand All @@ -21,10 +21,10 @@ class BottomNavigationBloc
emit(const AnalysisState());
}

void _onLoadTransaction(
TransactionEvent event, Emitter<BottomNavigationState> emit) {
emit(const TransactionState());
}
// void _onLoadTransaction(
// TransactionEvent event, Emitter<BottomNavigationState> emit) {
// emit(const TransactionState());
// }

void _onLoadCategoriesTxn(
CategoriesTxnEvent event, Emitter<BottomNavigationState> emit) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ class AnalysisEvent extends BottomNavigationEvent {
List<Object> get props => [];
}

class TransactionEvent extends BottomNavigationEvent {
const TransactionEvent();
// class TransactionEvent extends BottomNavigationEvent {
// const TransactionEvent();

@override
List<Object> get props => [];
}
// @override
// List<Object> get props => [];
// }

class CategoriesTxnEvent extends BottomNavigationEvent {
const CategoriesTxnEvent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,22 @@ class AnalysisState extends BottomNavigationState {
List<Object> get props => [index, title];
}

class TransactionState extends BottomNavigationState {
const TransactionState();
// class TransactionState extends BottomNavigationState {
// const TransactionState();

@override
final int index = 2;
final String title = "Transaction";
// @override
// final int index = 2;
// final String title = "Transaction";

@override
List<Object> get props => [index, title];
}
// @override
// List<Object> get props => [index, title];
// }

class CategoriesTxnState extends BottomNavigationState {
const CategoriesTxnState();

@override
final int index = 3;
final int index = 2;
final String title = "CategoriesTxn";

@override
Expand All @@ -56,7 +56,7 @@ class ProfileState extends BottomNavigationState {
const ProfileState();

@override
final int index = 4;
final int index = 3;
final String title = "Profile";

@override
Expand Down
Loading

0 comments on commit a777d01

Please sign in to comment.