Skip to content

Commit

Permalink
Merge branch 'release-2.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
mrlanu committed Jul 3, 2023
2 parents 0a6ec1c + d67e6d2 commit 603a264
Show file tree
Hide file tree
Showing 101 changed files with 2,452 additions and 698 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Budget app
📱 ***My Budget app project on Flutter, the back-end (Java) is available [here](https://github.com/mrlanu/budget-app-back).*** 📱

📱
***My Budget app project on Flutter, the back-end (Java) is available [here](https://github.com/mrlanu/budget-app-back).
*** 📱

<p align="center">
<img src="assets/screenshots/0.png" alt="MyPic" width="170">
Expand All @@ -9,4 +12,8 @@
<img src="assets/screenshots/4.png" alt="MyPic" width="170">
<img src="assets/screenshots/5.png" alt="MyPic" width="170">
<img src="assets/screenshots/6.png" alt="MyPic" width="170">
<img src="assets/screenshots/7.png" alt="MyPic" width="170">
<img src="assets/screenshots/8.png" alt="MyPic" width="170">
<img src="assets/screenshots/9.png" alt="MyPic" width="170">
<img src="assets/screenshots/10.png" alt="MyPic" width="170">
</p>
Binary file added assets/images/piggy_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/screenshots/0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/screenshots/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/screenshots/10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/screenshots/2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/screenshots/3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/screenshots/4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/screenshots/5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/screenshots/6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/screenshots/7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/screenshots/8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/screenshots/9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions lib/account_edit/bloc/account_edit_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:bloc/bloc.dart';
import 'package:bloc_concurrency/bloc_concurrency.dart';
import 'package:budget_app/accounts/models/account.dart';
import 'package:budget_app/accounts/repository/accounts_repository.dart';
import 'package:budget_app/constants/api.dart';
import 'package:budget_app/transactions/models/transaction_type.dart';
import 'package:equatable/equatable.dart';
import 'package:flutter/cupertino.dart';
Expand All @@ -18,13 +19,12 @@ part 'account_edit_event.dart';
part 'account_edit_state.dart';

class AccountEditBloc extends Bloc<AccountEditEvent, AccountEditState> {
final String budgetId;
final CategoriesRepository _categoriesRepository;
final AccountsRepository _accountsRepository;
late final StreamSubscription<List<Category>> _categoriesSubscription;

AccountEditBloc(
{required this.budgetId,
{
required CategoriesRepository categoriesRepository,
required AccountsRepository accountsRepository})
: _categoriesRepository = categoriesRepository,
Expand Down Expand Up @@ -123,7 +123,7 @@ class AccountEditBloc extends Bloc<AccountEditEvent, AccountEditState> {
balance: double.parse(state.balance.value),
initialBalance: double.parse(state.balance.value),
includeInTotal: state.isIncludeInTotals,
budgetId: budgetId);
budgetId: await getBudgetId());
_accountsRepository.saveAccount(account: account);
Navigator.of(event.context).pop();
}
Expand Down
109 changes: 57 additions & 52 deletions lib/account_edit/view/account_edit_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import 'package:budget_app/account_edit/view/widgets/balance_input_field.dart';
import 'package:budget_app/account_edit/view/widgets/category_input_field.dart';
import 'package:budget_app/account_edit/view/widgets/include_switch.dart';
import 'package:budget_app/account_edit/view/widgets/name_input_field.dart';
import 'package:budget_app/app/repository/budget_repository.dart';
import 'package:budget_app/colors.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
Expand All @@ -15,60 +17,63 @@ class AccountEditDialog extends StatelessWidget {
builder: (context, state) {
return state.accStatus == AccountEditStatus.loading
? Center(child: CircularProgressIndicator())
: Dialog(
backgroundColor: Theme.of(context).colorScheme.secondaryContainer,
insetPadding: EdgeInsets.all(10),
child: Stack(
clipBehavior: Clip.none,
alignment: Alignment.center,
children: <Widget>[
Container(
height: 1500.h,
width: double.infinity,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
color: Theme.of(context).colorScheme.secondaryContainer,
),
padding: EdgeInsets.fromLTRB(20, 25, 20, 20),
child: Column(
children: [
Text(
'New Account',
style: TextStyle(
fontSize: Theme.of(context)
.textTheme
.titleLarge
?.fontSize),
: Center(
child: SingleChildScrollView(
child: Dialog(
insetPadding: EdgeInsets.all(10),
child: Stack(
clipBehavior: Clip.none,
alignment: Alignment.center,
children: <Widget>[
Container(
height: 1500.h,
width: double.infinity,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
color: BudgetColors.teal50,
),
SizedBox(
height: 50.h,
padding: EdgeInsets.fromLTRB(20, 25, 20, 20),
child: Column(
children: [
Text(
'New Account',
style: TextStyle(
fontSize: Theme.of(context)
.textTheme
.titleLarge
?.fontSize),
),
SizedBox(
height: 50.h,
),
CategoryInputField(),
SizedBox(
height: 75.h,
),
NameInputField(),
SizedBox(
height: 75.h,
),
BalanceInputField(),
SizedBox(
height: 75.h,
),
IncludeSwitch(),
SizedBox(
height: 75.h,
),
_SubmitButton(),
],
),
CategoryInputField(),
SizedBox(
height: 75.h,
),
NameInputField(),
SizedBox(
height: 75.h,
),
BalanceInputField(),
SizedBox(
height: 75.h,
),
IncludeSwitch(),
SizedBox(
height: 75.h,
),
_SubmitButton(),
],
),
),
/*Positioned(
top: -100,
child: Image.network("https://i.imgur.com/2yaf2wb.png",
width: 150, height: 150))*/
],
));
),
/*Positioned(
top: -100,
child: Image.network("https://i.imgur.com/2yaf2wb.png",
width: 150, height: 150))*/
],
)),
),
);
},
);
}
Expand Down
11 changes: 8 additions & 3 deletions lib/accounts/cubit/accounts_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ class AccountsCubit extends Cubit<AccountsState> {
late final StreamSubscription<List<Account>> _accountsSubscription;

AccountsCubit(
{required String budgetId, required String categoryId, required AccountsRepository accountsRepository,
{required String categoryId, required AccountsRepository accountsRepository,
required TransactionsRepository transactionsRepository})
: _accountsRepository = accountsRepository,
_transactionsRepository = transactionsRepository,
super(AccountsState(budgetId: budgetId, categoryId: categoryId)) {
super(AccountsState(categoryId: categoryId)) {
_transactionsSubscription = _transactionsRepository
.getTransactions()
.skip(1)
Expand All @@ -42,7 +42,12 @@ class AccountsCubit extends Cubit<AccountsState> {
state.copyWith(status: DataStatus.loading));
try {
final accountList = await _accountsRepository.getAccounts().first;
final filteredAccounts = accountList.where((acc) => acc.categoryId == state.categoryId).toList();
List<Account> filteredAccounts;
if(state.categoryId == 'all_accounts'){
filteredAccounts = accountList;
}else {
filteredAccounts = accountList.where((acc) => acc.categoryId == state.categoryId).toList();
}
emit(
state.copyWith(status: DataStatus.success, accountList: filteredAccounts));
} catch (e) {
Expand Down
6 changes: 2 additions & 4 deletions lib/accounts/cubit/accounts_state.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
part of 'accounts_cubit.dart';

class AccountsState extends Equatable {
final String budgetId;
final String categoryId;
final DataStatus status;
final List<Account> accountList;
final String? errorMessage;

const AccountsState(
{required this.budgetId, required this.categoryId, this.status = DataStatus.loading,
{required this.categoryId, this.status = DataStatus.loading,
this.accountList = const [],
this.errorMessage});

Expand All @@ -20,7 +19,6 @@ class AccountsState extends Equatable {
String? errorMessage,
}) {
return AccountsState(
budgetId: budgetId ?? this.budgetId,
categoryId: categoryId ?? this.categoryId,
status: status ?? this.status,
accountList: accountList ?? this.accountList,
Expand All @@ -29,5 +27,5 @@ class AccountsState extends Equatable {
}

@override
List<Object> get props => [budgetId, categoryId, status, accountList];
List<Object> get props => [categoryId, status, accountList];
}
26 changes: 7 additions & 19 deletions lib/accounts/repository/accounts_repository.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
import 'dart:convert';

import 'package:authentication_repository/authentication_repository.dart';
import 'package:http/http.dart' as http;
import 'package:rxdart/rxdart.dart';

import '../../constants/api.dart';
import '../../shared/models/budget.dart';
import '../models/account.dart';

abstract class AccountsRepository {
final User user;
final Budget budget;

AccountsRepository({required this.user, required this.budget});
Stream<List<Account>> getAccounts();
Future<void> fetchAllAccounts();
Future<void> saveAccount({required Account account});
Expand All @@ -27,11 +23,11 @@ class AccountFailure implements Exception {
}

class AccountsRepositoryImpl extends AccountsRepository {
static const baseURL = '10.0.2.2:8080';

final _accountsStreamController =
BehaviorSubject<List<Account>>.seeded(const []);

AccountsRepositoryImpl({required super.user, required super.budget});
AccountsRepositoryImpl();

@override
Stream<List<Account>> getAccounts() =>
Expand All @@ -42,9 +38,9 @@ class AccountsRepositoryImpl extends AccountsRepository {
var response;

final url = Uri.http(
baseURL, '/api/accounts', {'budgetId': budget.id});
baseURL, '/api/accounts', {'budgetId': await getBudgetId()});

response = await http.get(url, headers: await _getHeaders());
response = await http.get(url, headers: await getHeaders());

final accounts = List<Map<dynamic, dynamic>>.from(
json.decode(response.body) as List,
Expand All @@ -61,7 +57,7 @@ class AccountsRepositoryImpl extends AccountsRepository {
final url = Uri.http(baseURL, '/api/accounts');

final response = await http.post(url,
headers: await _getHeaders(), body: json.encode(account.toJson()));
headers: await getHeaders(), body: json.encode(account.toJson()));

final newAcc = Account.fromJson(jsonDecode(response.body));
final accounts = [..._accountsStreamController.value];
Expand All @@ -73,7 +69,7 @@ class AccountsRepositoryImpl extends AccountsRepository {
Future<void> deleteAccount({required Account account}) async {
final url = Uri.http(baseURL, '/api/accounts/${account.id}');

final resp = await http.delete(url, headers: await _getHeaders());
final resp = await http.delete(url, headers: await getHeaders());
if (resp.statusCode != 200) {
throw AccountFailure(jsonDecode(resp.body)['message']);
}
Expand All @@ -86,12 +82,4 @@ class AccountsRepositoryImpl extends AccountsRepository {
_accountsStreamController.add(accounts);
}
}

Future<Map<String, String>> _getHeaders() async {
final token = await user.token;
return {
"Content-Type": "application/json",
"Authorization": "Bearer $token"
};
}
}
3 changes: 0 additions & 3 deletions lib/accounts/view/accounts_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class AccountsPage extends StatelessWidget {
providers: [
BlocProvider(
create: (context) => AccountsCubit(
budgetId: appBloc.state.budget!.id,
categoryId: categoryId,
transactionsRepository:
context.read<TransactionsRepositoryImpl>(),
Expand All @@ -45,9 +44,7 @@ class AccountsPage extends StatelessWidget {
final textTheme = Theme.of(context).textTheme;
final scheme = Theme.of(context).colorScheme;
return Scaffold(
backgroundColor: scheme.secondaryContainer,
appBar: AppBar(
backgroundColor: scheme.primaryContainer,
title: Text('Accounts'),
centerTitle: true,
),
Expand Down
2 changes: 1 addition & 1 deletion lib/accounts_list/cubit/accounts_list_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class AccountsListCubit extends Cubit<AccountsListState> {
});
}

Future<void> onInit({required String budgetId}) async {
Future<void> onInit() async {
emit(state.copyWith(status: AccountsListStatus.loading));
final accounts = await _accountsRepository.getAccounts().first;
final categories = await _categoriesRepository.getCategories().first;
Expand Down
10 changes: 4 additions & 6 deletions lib/accounts_list/view/accounts_list_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:budget_app/account_edit/view/account_edit_form.dart';
import 'package:budget_app/accounts/repository/accounts_repository.dart';
import 'package:budget_app/app/app.dart';
import 'package:budget_app/categories/models/category.dart';
import 'package:budget_app/colors.dart';
import 'package:budget_app/home/cubit/home_cubit.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
Expand All @@ -28,7 +29,7 @@ class AccountsListPage extends StatelessWidget {
accountsRepository: context.read<AccountsRepositoryImpl>(),
categoriesRepository:
context.read<CategoriesRepositoryImpl>(),
)..onInit(budgetId: context.read<AppBloc>().state.budget!.id),
)..onInit(),
),
BlocProvider.value(value: homeCubit),
],
Expand Down Expand Up @@ -70,9 +71,7 @@ class AccountsListView extends StatelessWidget {
child: BlocBuilder<AccountsListCubit, AccountsListState>(
builder: (context, state) {
return Scaffold(
backgroundColor: Theme.of(context).colorScheme.secondaryContainer,
appBar: AppBar(
backgroundColor: scheme.primaryContainer,
title: Text('Accounts'),
),
body: Column(
Expand Down Expand Up @@ -115,7 +114,7 @@ class AccountsListView extends StatelessWidget {
),
),
ListTile(
tileColor: scheme.primaryContainer,
tileColor: BudgetColors.amber800,
title: Text(
'New Account',
style: TextStyle(
Expand All @@ -124,7 +123,7 @@ class AccountsListView extends StatelessWidget {
),
trailing: Icon(
Icons.add,
color: scheme.onSecondaryContainer,
color: BudgetColors.teal900,
),
onTap: () {
//context.read<AccountsListCubit>().onNewAccount();
Expand All @@ -144,7 +143,6 @@ class AccountsListView extends StatelessWidget {
context: context,
builder: (_) => BlocProvider(
create: (context) => AccountEditBloc(
budgetId: context.read<AppBloc>().state.budget!.id,
categoriesRepository:
context.read<CategoriesRepositoryImpl>(),
accountsRepository: context.read<AccountsRepositoryImpl>())
Expand Down
Loading

0 comments on commit 603a264

Please sign in to comment.