Skip to content

Commit

Permalink
Merge branch 'release-2.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
mrlanu committed Jul 21, 2023
2 parents 603a264 + 43dfefc commit 9d88673
Show file tree
Hide file tree
Showing 70 changed files with 1,948 additions and 1,284 deletions.
Binary file added assets/images/money_back.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 10 additions & 12 deletions lib/accounts/cubit/accounts_cubit.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:async';

import 'package:bloc/bloc.dart';
import 'package:budget_app/accounts/models/accounts_view_filter.dart';
import 'package:budget_app/shared/shared.dart';
import 'package:budget_app/transactions/models/transaction.dart';
import 'package:equatable/equatable.dart';
Expand All @@ -18,11 +19,11 @@ class AccountsCubit extends Cubit<AccountsState> {
late final StreamSubscription<List<Account>> _accountsSubscription;

AccountsCubit(
{required String categoryId, required AccountsRepository accountsRepository,
{required AccountsViewFilter filter, required AccountsRepository accountsRepository,
required TransactionsRepository transactionsRepository})
: _accountsRepository = accountsRepository,
_transactionsRepository = transactionsRepository,
super(AccountsState(categoryId: categoryId)) {
super(AccountsState(filter: filter)) {
_transactionsSubscription = _transactionsRepository
.getTransactions()
.skip(1)
Expand All @@ -31,31 +32,28 @@ class AccountsCubit extends Cubit<AccountsState> {
});
_accountsSubscription = _accountsRepository
.getAccounts()
.skip(1)
.listen((accounts) {
fetchAllAccounts();
});
}

Future<void> fetchAllAccounts() async {
emit(
state.copyWith(status: DataStatus.loading));
try {
final accountList = await _accountsRepository.getAccounts().first;
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));
state.copyWith(status: DataStatus.success, accountList: accountList));
} catch (e) {
emit(
state.copyWith(status: DataStatus.error, errorMessage: e.toString()));
}
}

Future<void> changeExpanded(int index)async{
var accounts = [...state.accountList];
accounts[index] = accounts[index].copyWith(isExpanded: !accounts[index].isExpanded);
emit(state.copyWith(accountList: accounts));
}

@override
Future<void> close() {
_transactionsSubscription.cancel();
Expand Down
13 changes: 8 additions & 5 deletions lib/accounts/cubit/accounts_state.dart
Original file line number Diff line number Diff line change
@@ -1,31 +1,34 @@
part of 'accounts_cubit.dart';

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

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

List<Account> get filteredAccounts => filter.applyAll(accountList);

AccountsState copyWith({
String? budgetId,
String? categoryId,
DataStatus? status,
List<Account>? accountList,
AccountsViewFilter? filter,
String? errorMessage,
}) {
return AccountsState(
categoryId: categoryId ?? this.categoryId,
status: status ?? this.status,
accountList: accountList ?? this.accountList,
filter: filter ?? this.filter,
errorMessage: errorMessage ?? this.errorMessage,
);
}

@override
List<Object> get props => [categoryId, status, accountList];
List<Object> get props => [status, accountList, filter];
}
30 changes: 28 additions & 2 deletions lib/accounts/models/account.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Account extends Equatable{
final double initialBalance;
final bool includeInTotal;
final String budgetId;
final bool isExpanded;

const Account({
this.id,
Expand All @@ -24,9 +25,34 @@ class Account extends Equatable{
required this.balance,
required this.initialBalance,
this.includeInTotal = true,
required this.budgetId
required this.budgetId,
this.isExpanded = false
});

Account copyWith({
String? id,
String? name,
String? categoryId,
String? currency,
double? balance,
double? initialBalance,
bool? includeInTotal,
String? budgetId,
bool? isExpanded,
}){
return Account(
id: id ?? this.id,
name: name ?? this.name,
categoryId: categoryId ?? this.categoryId,
currency: currency ?? this.currency,
balance: balance ?? this.balance,
initialBalance: initialBalance ?? this.initialBalance,
includeInTotal: includeInTotal ?? this.includeInTotal,
budgetId: budgetId ?? this.budgetId,
isExpanded: isExpanded ?? this.isExpanded
);
}

String extendName(List<Category> categories){
final category = categories.where((element) => element.id == this.categoryId).first;
return '${category.name} / ${this.name}';
Expand All @@ -36,5 +62,5 @@ class Account extends Equatable{
Map<String, dynamic> toJson() => _$AccountToJson(this);

@override
List<Object?> get props => [id, name, balance];
List<Object?> get props => [id, name, balance, isExpanded];
}
14 changes: 14 additions & 0 deletions lib/accounts/models/accounts_view_filter.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import 'account.dart';

class AccountsViewFilter {
final String filterId;
const AccountsViewFilter({required this.filterId});

bool apply({required Account account}) {
return account.categoryId == filterId;
}

List<Account> applyAll(Iterable<Account> accountsList) {
return accountsList.where((acc) => apply(account: acc)).toList();
}
}
102 changes: 0 additions & 102 deletions lib/accounts/view/accounts_page.dart

This file was deleted.

4 changes: 1 addition & 3 deletions lib/accounts_list/view/accounts_list_page.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:budget_app/account_edit/bloc/account_edit_bloc.dart';
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';
Expand All @@ -17,8 +16,7 @@ class AccountsListPage extends StatelessWidget {
const AccountsListPage({Key? key}) : super(key: key);

static Route<void> route(
{required HomeCubit homeCubit,
required List<Category> accountCategories}) {
{required HomeCubit homeCubit}) {
return MaterialPageRoute(
fullscreenDialog: true,
builder: (context) {
Expand Down
3 changes: 3 additions & 0 deletions lib/app/view/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:google_fonts/google_fonts.dart';

import '../../constants/constants.dart';
import '../../subcategories/repository/subcategories_repository.dart';
import '../../theme.dart';
import '../../transactions/transaction/view/transaction_page.dart';
Expand Down Expand Up @@ -67,6 +68,8 @@ class _AppViewState extends State<AppView> {

@override
Widget build(BuildContext context) {
w = MediaQuery.of(context).size.width;
h = MediaQuery.of(context).size.height;
return ScreenUtilInit(
designSize: const Size(1080, 2160),
minTextAdapt: true,
Expand Down
1 change: 1 addition & 0 deletions lib/colors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class BudgetColors {
static const Color statusBar = Color(0xFF00695C);
static const Color teal900 = Color(0xFF004D40);
static const Color teal600 = Color(0xFF00897B);
static const Color teal300 = Color(0xFF4DB6AC);
static const Color teal50 = Color(0xFFE0F2F1);
static const Color teal100 = Color(0xFFB2DFDB);
static const Color teal200 = Color(0xFF80CBC4);
Expand Down
5 changes: 3 additions & 2 deletions lib/constants/api.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import 'dart:convert';
import 'package:flutter/foundation.dart' show kIsWeb;

import 'package:budget_app/shared/models/budget.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:shared_preferences/shared_preferences.dart';

const baseURL = '10.0.2.2:8080';
final baseURL = kIsWeb ? 'localhost:8080' : '10.0.2.2:8080';

Future<Map<String, String>> getHeaders() async {

Expand All @@ -27,4 +28,4 @@ Future<String> getBudgetId() async {
budget = Budget(id: '', userId: '');
}
return budget.id;
}
}
9 changes: 9 additions & 0 deletions lib/constants/constants.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// defined in app.dart
import 'package:adaptive_breakpoints/adaptive_breakpoints.dart';
import 'package:flutter/cupertino.dart';

late double w;
late double h;

bool isDisplayDesktop(BuildContext context) =>
getWindowType(context) >= AdaptiveWindowType.medium;
Loading

0 comments on commit 9d88673

Please sign in to comment.