Skip to content
Open
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
2 changes: 2 additions & 0 deletions lib/core/l10n/app_ar.arb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@
"currencyCode": "دينار",
"spendingTrend": "اتجاه الإنفاق",
"noDataAvailable": "لا توجد بيانات متاحة",
"current_balance":"الرصيد الحالي",
"how_much_money": "ما مقدار المال المتوفر لديك حاليًا؟"
"no_spending_categories": "لا يوجد معاملات متاحة",
"month_january": "يناير",
"month_february": "فبراير",
Expand Down
2 changes: 2 additions & 0 deletions lib/core/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@
"total": {}
}
},
"current_balance":"Current balance",
"how_much_money": "How much money do you have right now?",
"no_spending_categories": "No spending categories available",
"month_january": "January",
"month_february": "February",
Expand Down
65 changes: 60 additions & 5 deletions lib/presentation/account_setup/cubit/account_setup_cubit.dart
Original file line number Diff line number Diff line change
@@ -1,20 +1,75 @@
import 'package:flutter_bloc/flutter_bloc.dart';

import '../../../domain/repository/account_repository.dart';
import 'account_setup_state.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

class AccountSetupCubit extends Cubit<AccountSetupState> {
final AccountRepository _accountSetupRepository;

AccountSetupCubit(this._accountSetupRepository) : super(AccountSetupState());

Future<void> fetchCurrencies() async {
try{
try {
final currencies = await _accountSetupRepository.getCurrencies();
emit(state.copyWith(currencies : currencies,isLoading: false));
}catch(e){
emit(state.copyWith(currencies: currencies, isLoading: false));
} catch (e) {
emit(state.copyWith(isLoading: false, errorMessage: e.toString()));
}
}


}
bool _accountSetUpStep1ValidationInput() {
return state.currency.isNotEmpty && state.salary.isNotEmpty && state.salaryDay.isNotEmpty;
}

bool _accountSetUpStep2ValidationInput() {
return state.currentBalance.isNotEmpty;
}

void onSalaryChanged(String salary){
emit(state.copyWith(salary: salary));
_updateButtonEnabledState();
}

void onCurrencyChanged(String currency){
emit(state.copyWith(currency: currency));
_updateButtonEnabledState();
}

void onSalaryDayChanged(String salaryDay){
emit(state.copyWith(salaryDay: salaryDay));
_updateButtonEnabledState();
}

void onCurrentBalanceChanged(String currentBalance) {
emit(state.copyWith(currentBalance: currentBalance));
_updateButtonEnabledState();
}

void _updateButtonEnabledState() {

bool isButtonEnable = switch (state.accountStep) {
AccountStep.step1 => _accountSetUpStep1ValidationInput(),
AccountStep.step2 => _accountSetUpStep2ValidationInput(),
AccountStep.step3 => false,
};
emit(state.copyWith(isButtonEnabled: isButtonEnable));
}

void onNextStep() {
switch (state.accountStep) {
case AccountStep.step1:
emit(state.copyWith(accountStep: AccountStep.step2));
_updateButtonEnabledState();
break;
case AccountStep.step2:
emit(state.copyWith(accountStep: AccountStep.step3));
_updateButtonEnabledState();
break;
case AccountStep.step3:
// submit account setup date
emit(state.copyWith(navigateToHome: true));
break;
}
}
}
30 changes: 24 additions & 6 deletions lib/presentation/account_setup/cubit/account_setup_state.dart
Original file line number Diff line number Diff line change
@@ -1,36 +1,51 @@

import 'package:moneyplus/domain/entity/currency.dart';

enum AccountStep {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think AccountSetupStep would be clearer

step1,
step2,
step3,
}

class AccountSetupState {
final String currency;
final double salary;
final int salaryDay;
final String salary;
final String salaryDay;
final String query;
final bool isButtonEnabled;
final List<Currency> currencies;
final bool isLoading;
final String errorMessage;
final AccountStep accountStep;
final String currentBalance;
final bool navigateToHome;

AccountSetupState({
this.currency = "",
this.salary = 0.0,
this.salaryDay = 0,
this.salary = "",
this.salaryDay = "",
this.query = "",
this.isButtonEnabled = false,
this.currencies = const [],
this.isLoading = true,
this.errorMessage = "",
this.accountStep = AccountStep.step1,
this.currentBalance = "",
this.navigateToHome = false,
});

AccountSetupState copyWith({
String? currency,
double? salary,
int? salaryDay,
String? salary,
String? salaryDay,
String? query,
bool? isButtonEnabled,
List<Currency>? currencies,
String? errorMessage,
bool? isLoading,
AccountStep? accountStep,
String? currentBalance,
bool? navigateToHome,
}) {
return AccountSetupState(
currency: currency ?? this.currency,
Expand All @@ -41,6 +56,9 @@ class AccountSetupState {
currencies: currencies?? this.currencies,
errorMessage: errorMessage?? this.errorMessage,
isLoading: isLoading?? this.isLoading,
accountStep: accountStep?? this.accountStep,
currentBalance: currentBalance?? this.currentBalance,
navigateToHome: navigateToHome?? this.navigateToHome,
);
}
}
142 changes: 80 additions & 62 deletions lib/presentation/account_setup/screen/account_setup_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:flutter_svg/svg.dart';
import 'package:moneyplus/design_system/assets/app_assets.dart';
import 'package:moneyplus/design_system/widgets/app_bar.dart';
import 'package:moneyplus/presentation/account_setup/screen/page1.dart';
import 'package:moneyplus/presentation/account_setup/screen/page2.dart';

import '../../../core/l10n/app_localizations.dart';
import '../../../design_system/theme/money_extension_context.dart';
Expand Down Expand Up @@ -42,74 +43,91 @@ class _AccountSetupScreenState extends State<AccountSetupScreen> {

return BlocProvider(
create: (context) => cubit..fetchCurrencies(),
child: BlocBuilder<AccountSetupCubit, AccountSetupState>(
builder: (context, state) {
return Scaffold(
backgroundColor: context.colors.surface,
body: SafeArea(
child: Padding(
padding: const EdgeInsetsDirectional.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
CustomAppBar(
leading: AppBarCircleButton(
assetPath: AppAssets.icArrowLeft, onTap: () {}),
title: l10n.accountSetup,
trailing: SvgPicture.asset(AppAssets.appBrand,),
),
SizedBox(height: 36,),
Indicator(currentIndex: currentIndex),
SizedBox(height: 16,),
Text(
l10n.stepOfTotal(currentIndex + 1, 3),
style: context.typography.label.small.copyWith(
color: context.colors.body,
child: BlocListener<AccountSetupCubit, AccountSetupState>(
listener: (context, state) {
if (state.accountStep.index != currentIndex) {
pageController.animateToPage(
state.accountStep.index,
duration: const Duration(milliseconds: 300),
curve: Curves.easeInOut,
);
setState(() {
currentIndex = state.accountStep.index;
});
}
if (state.navigateToHome) {
// navigate to home
}
},
child: BlocBuilder<AccountSetupCubit, AccountSetupState>(
builder: (context, state) {
return Scaffold(
backgroundColor: context.colors.surface,
body: SafeArea(
child: Padding(
padding: const EdgeInsetsDirectional.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
CustomAppBar(
leading: AppBarCircleButton(
assetPath: AppAssets.icArrowLeft,
onTap: () {
Navigator.pop(context);
},
),
title: l10n.accountSetup,
trailing: SvgPicture.asset(AppAssets.appBrand),
),
SizedBox(height: 36),
Indicator(currentIndex: currentIndex),
SizedBox(height: 16),
Text(
l10n.stepOfTotal(currentIndex + 1, 3),
style: context.typography.label.small.copyWith(
color: context.colors.body,
),
),
SizedBox(height: 4),
Text(
l10n.setUpYourAccount,
style: context.typography.headline.medium.copyWith(
color: context.colors.title,
),
),
),
SizedBox(height: 4),
Text(
l10n.setUpYourAccount,
style: context.typography.headline.medium.copyWith(
color: context.colors.title,
SizedBox(height: 4),
Expanded(
child: PageView(
controller: pageController,
physics: const NeverScrollableScrollPhysics(),
onPageChanged: (index) {
setState(() {
currentIndex = index;
});
},
children: [
SingleChildScrollView(child: Page1(state: state,)),
SingleChildScrollView(child: Page2(currency: state.currency, currentBalanceState: state.currentBalance)),
// page3()
],
),
),
),
SizedBox(height: 4),
Expanded(
child: PageView(
controller: pageController,
onPageChanged: (index) {
setState(() {
currentIndex = index;
});
DefaultButton(
text: state.accountStep == AccountStep.step3
? l10n.finishSetup
: l10n.next,
isEnabled: state.isButtonEnabled,
onPressed: () {
context.read<AccountSetupCubit>().onNextStep();
},
children: [
SingleChildScrollView(child: Page1(state: state))
// page2()
// page3()
],
),
),
DefaultButton(
text: currentIndex == 2 ? l10n.finishSetup : l10n.next,
isEnabled: false,
onPressed: () {
if (currentIndex < 2) {
pageController.nextPage(
duration: const Duration(milliseconds: 300),
curve: Curves.easeInOut,
);
} else {
// Navigate to home
}
},
),
],
],
),
),
),
),
);
},
);
},
),
),
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:moneyplus/design_system/assets/app_assets.dart';
import 'package:moneyplus/design_system/theme/money_extension_context.dart';
import 'package:moneyplus/design_system/widgets/text_field.dart';

import '../../../core/l10n/app_localizations.dart';
import '../../../design_system/widgets/buttons/button/default_button.dart';
import '../cubit/account_setup_cubit.dart';
import '../cubit/account_setup_state.dart';
import 'currency_list.dart';

Expand Down Expand Up @@ -65,9 +67,9 @@ class _CurrencyBottomSheetState extends State<CurrencyBottomSheet> {
),
child: MTextField(
hint: l10n.search,
value: searchController.text,
value: widget.state.query,
onChanged: (value) {
searchController.text = value;
context.read<AccountSetupCubit>().onCurrencyChanged(value);
},
leading: Padding(
padding: const EdgeInsetsDirectional.only(
Expand Down
Loading
Loading