Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions lib/core/di/injection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ import 'package:moneyplus/domain/repository/transaction_repository.dart';
import 'package:moneyplus/presentation/account_setup/cubit/account_setup_cubit.dart';
import 'package:moneyplus/presentation/transactions/cubit/transaction_cubit.dart';

import '../../presentation/createAccount/cubit/create_account_cubit.dart';
import '../../data/repository/account_repository.dart';
import '../../data/repository/authentication_repository.dart';
import '../../data/repository/fake_statistics_repository.dart';
import '../../data/repository/transaction_repository.dart';
import '../../data/repository/statistics_repository_impl.dart';
import '../../data/repository/transaction_repository.dart';
import '../../data/repository/user_money_repository.dart';
import '../../data/service/app_secrets_provider.dart';
import '../../data/service/supabase_service.dart';
Expand All @@ -17,9 +15,10 @@ import '../../domain/repository/authentication_repository.dart';
import '../../domain/repository/statistics_repository.dart';
import '../../domain/repository/user_money_repository.dart';
import '../../domain/validator/authentication_validator.dart';
import '../../presentation/createAccount/cubit/create_account_cubit.dart';
import '../../presentation/expense/cubit/add_expense_cubit.dart';
import '../../presentation/home/cubit/home_cubit.dart';
import '../../presentation/income/cubit/add_income_cubit.dart';
import '../../presentation/expense/cubit/add_expense_cubit.dart';
import '../../presentation/login/cubit/login_cubit.dart';
import '../../presentation/statistics/cubit/statistics_cubit.dart';
import '../../presentation/trasnaction_details/trasnaction_details_cubit.dart';
Expand Down Expand Up @@ -64,10 +63,6 @@ void initDI() {
() => TransactionRepositoryImpl(service: getIt<SupabaseService>()),
);

getIt.registerLazySingleton<AccountSetupCubit>(
() => AccountSetupCubit(getIt<AccountRepository>()),
);

getIt.registerLazySingleton<AccountSetupCubit>(
() => AccountSetupCubit(getIt<AccountRepository>()),
);
Expand Down
2 changes: 1 addition & 1 deletion lib/data/repository/user_money_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class UserRepositoryImpl implements UserMoneyRepository {
Future<double> getSavingSpendingPercentage(int month, int year) async {
_validateMonth(month);
final isJanuary = month == 1;
final previousMonth = isJanuary ? 12 : month;
final previousMonth = isJanuary ? 12 : month - 1;
final previousYear = isJanuary ? year - 1 : year;

final [
Expand Down
63 changes: 34 additions & 29 deletions lib/design_system/widgets/income_expense.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,38 +59,43 @@ class IncomeExpense extends StatelessWidget {
colorFilter: ColorFilter.mode(operationColor, BlendMode.srcIn),
),
),
Padding(
padding: EdgeInsets.fromLTRB(0, 4, 10, 4),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
label,
style: typography.label.xSmall?.copyWith(color: colors.body),
),
Row(
children: [
Text(
isIncome ? '+' : '-',
style: typography.title.medium.copyWith(
color: operationColor,
Expanded(
child: Padding(
padding: EdgeInsets.fromLTRB(0, 4, 10, 4),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
label,
style: typography.label.xSmall?.copyWith(color: colors.body),
),
Row(
children: [
Text(
isIncome ? '+' : '-',
style: typography.title.medium.copyWith(
color: operationColor,
),
),
),
Text(
l10n.moneyAmount(
amount,
currency
Expanded(
child: Text(
l10n.moneyAmount(
amount,
currency
),
style: TextStyle(
color: colors.title,
fontSize: 14,
fontWeight: FontWeight.w500,
),
overflow: TextOverflow.ellipsis,
),
style: TextStyle(
color: colors.title,
fontSize: 14,
fontWeight: FontWeight.w500,
),
),
],
),
],
],
),
],
),
),
),
],
Expand Down
5 changes: 1 addition & 4 deletions lib/design_system/widgets/top_spending_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,5 @@ class TopSpendingCard extends StatelessWidget {
}

String _formatPercentage(double value) {
if (value % 1 == 0) {
return value.toInt().toString();
}
return value.toString();
return value.round().toString();
}
21 changes: 16 additions & 5 deletions lib/presentation/home/cubit/home_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class HomeCubit extends Cubit<HomeState> {
HomeCubit({required this.userMoneyRepository}) : super(HomeLoading());

void getData({required int month, required int year}) async {
emit(HomeLoading());
try {
final loadedContent = HomeLoaded(
currentBalance: await getTotalBalance(),
Expand All @@ -33,24 +34,34 @@ class HomeCubit extends Cubit<HomeState> {
}

void setSelectedDate(int month, int year) async {
if ((state as HomeLoaded).selectedMonth == month &&
(state as HomeLoaded).selectedYear == year) {
if (state is! HomeLoaded) return;
final loadedState = state as HomeLoaded;

if (loadedState.selectedMonth == month && loadedState.selectedYear == year) {
return;
}
final loadedState = state as HomeLoaded;
emit(HomeLoading());
var expense = await getTotalMonthExpense(month, year);
var income = await getTotalMonthIncome(month, year);
final expense = await getTotalMonthExpense(month, year);
final income = await getTotalMonthIncome(month, year);
final topSpendingCategories = await getTopSpendingCategories(month, year);
final savingSpendingPercentage = await getSavingSpendingPercentage(month, year);
emit(
loadedState.copyWith(
totalMonthIncome: income,
totalMonthExpense: expense,
topSpendingCategories: topSpendingCategories,
currentSavingSpendingPercentage: savingSpendingPercentage,
selectedMonth: month,
selectedYear: year,
),
);
}

void onRefreshHomeScreen(){
final currentDate = DateTime.now();
getData(month: currentDate.month, year: currentDate.year);
}

Future<double> getTotalBalance() async {
return await userMoneyRepository.getTotalBalance();
}
Expand Down
23 changes: 16 additions & 7 deletions lib/presentation/home/screen/home_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class _HomeScreenState extends State<HomeScreen> {
getIt<HomeCubit>()..getData(month: currentDate.month, year: currentDate.year),
child: BlocBuilder<HomeCubit, HomeState>(
builder: (context, state) {
final cubit = context.read<HomeCubit>();
var content = switch (state) {
HomeLoading() => Scaffold(
backgroundColor: MoneyColors.light.surface,
Expand All @@ -71,11 +72,14 @@ class _HomeScreenState extends State<HomeScreen> {
scrollController: _scrollController,
showAppBarOnly: showAppBarOnly,
setSelectedDate: (date) {
context.read<HomeCubit>().setSelectedDate(
cubit.setSelectedDate(
date.month,
date.year,
);
},
reloadScreen: (){
cubit.onRefreshHomeScreen();
}
),
HomeError() => Scaffold(
body: Center(child: Text(state.errorMessage)),
Expand All @@ -94,6 +98,7 @@ Widget _loadedContent({
required ScrollController scrollController,
required bool showAppBarOnly,
required Function(DateTime) setSelectedDate,
required Function reloadScreen,
}) {
final colors = context.colors;
final topSpendingCategories = state.topSpendingCategories;
Expand All @@ -113,7 +118,8 @@ Widget _loadedContent({
showAppBarOnly: showAppBarOnly,
state: state,
onDatePick: setSelectedDate,
context: context
context: context,
reloadScreen: reloadScreen
),
),
),
Expand Down Expand Up @@ -219,7 +225,8 @@ Widget _topSection({
required bool showAppBarOnly,
required HomeLoaded state,
required Function(DateTime) onDatePick,
required BuildContext context
required BuildContext context,
required Function reloadScreen,
}) {
final colors = MoneyColors.light;
if (showAppBarOnly) {
Expand Down Expand Up @@ -293,8 +300,9 @@ Widget _topSection({
child: VarientButton(
text: "Add",
iconPath: AppAssets.addMoney,
onPressed: () {
AddIncomeRoute().push(context);
onPressed: () async {
await AddIncomeRoute().push(context);
reloadScreen();
},
),
),
Expand All @@ -303,8 +311,9 @@ Widget _topSection({
child: SMSecondaryButton(
text: "Spend",
iconPath: AppAssets.spendMoney,
onPressed: () {
AddExpenseRoute().push(context);
onPressed: () async {
await AddExpenseRoute().push(context);
reloadScreen();
},
),
),
Expand Down
6 changes: 5 additions & 1 deletion lib/presentation/home/widget/current_balance.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class _CurrentBalanceCardState extends State<CurrentBalanceCard> {
children: [
SvgPicture.asset(percentageIcon, width: 16, height: 16),
Text(
"${widget.percentage}% $percentageText",
"${_formatPercentage(widget.percentage)}% $percentageText",
style: typography.label.xSmall?.copyWith(
color: percentageColor,
),
Expand All @@ -99,3 +99,7 @@ class _CurrentBalanceCardState extends State<CurrentBalanceCard> {
});
}
}

String _formatPercentage(double value) {
return value.round().toString();
}