Compare commits
3 Commits
6a9da33283
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
f4294e0e11
|
|||
|
78614bd021
|
|||
|
f1d7d31a3c
|
@@ -1,11 +1,15 @@
|
|||||||
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:krezus/repositories/transactions/models/transaction.dart';
|
import 'package:krezus/repositories/transactions/models/transaction.dart';
|
||||||
|
|
||||||
class TransactionLine {
|
class TransactionLine extends Equatable{
|
||||||
Transaction transaction;
|
final Transaction transaction;
|
||||||
double subTotal;
|
final double subTotal;
|
||||||
|
|
||||||
TransactionLine({
|
const TransactionLine({
|
||||||
required this.transaction,
|
required this.transaction,
|
||||||
required this.subTotal,
|
required this.subTotal,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [transaction, subTotal];
|
||||||
}
|
}
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:formz/formz.dart';
|
import 'package:formz/formz.dart';
|
||||||
@@ -7,6 +9,7 @@ import 'package:krezus/domains/transaction/models/transaction_date.dart';
|
|||||||
import 'package:krezus/domains/transaction/models/transaction_description.dart';
|
import 'package:krezus/domains/transaction/models/transaction_description.dart';
|
||||||
import 'package:krezus/domains/transaction/models/transaction_line.dart';
|
import 'package:krezus/domains/transaction/models/transaction_line.dart';
|
||||||
import 'package:krezus/domains/transaction/models/transaction_value.dart';
|
import 'package:krezus/domains/transaction/models/transaction_value.dart';
|
||||||
|
import 'package:krezus/repositories/metadata/models/account.dart';
|
||||||
import 'package:krezus/repositories/metadata/models/category.dart';
|
import 'package:krezus/repositories/metadata/models/category.dart';
|
||||||
import 'package:krezus/repositories/transactions/models/transaction.dart';
|
import 'package:krezus/repositories/transactions/models/transaction.dart';
|
||||||
import 'package:krezus/repositories/transactions/transactions_repository.dart';
|
import 'package:krezus/repositories/transactions/transactions_repository.dart';
|
||||||
@@ -33,18 +36,20 @@ class TransactionBloc extends Bloc<TransactionEvent, TransactionState> {
|
|||||||
on<TransactionSetCurrent>(_onTransactionSetCurrent);
|
on<TransactionSetCurrent>(_onTransactionSetCurrent);
|
||||||
on<TransactionDeleteCurrent>(_onTransactionDeleteCurrent);
|
on<TransactionDeleteCurrent>(_onTransactionDeleteCurrent);
|
||||||
on<TransactionFilterCategory>(_onTransactionFilterCategory);
|
on<TransactionFilterCategory>(_onTransactionFilterCategory);
|
||||||
|
on<TransactionFilterAccount>(_onTransactionFilterAccount);
|
||||||
|
on<TransactionResetSnackBar>(_onTransactionResetSnackBar);
|
||||||
|
|
||||||
_transactionsRepository
|
_transactionsRepository
|
||||||
.getTransactionsStream()
|
.getTransactionsStream()
|
||||||
.listen((transactions) => add(TransactionsLoad(transactions)));
|
.listen((transactions) => add(TransactionsLoad(transactions)));
|
||||||
}
|
}
|
||||||
|
|
||||||
_onAccountLoad(TransactionsLoad event, Emitter<TransactionState> emit) {
|
FutureOr<void> _onAccountLoad(TransactionsLoad event, Emitter<TransactionState> emit) {
|
||||||
var computeResult = _computeTransactionLine(event.transactions);
|
var computeResult = _computeTransactionLine(event.transactions);
|
||||||
emit(state.copyWith(
|
emit(state.copyWith(
|
||||||
transactions: event.transactions,
|
transactions: event.transactions,
|
||||||
transactionsLines: computeResult.list,
|
transactionsLines: computeResult.list,
|
||||||
transactionsLinesFiltered: _applyCategoryFilter(computeResult.list),
|
transactionsLinesFiltered: _applyFilters(computeResult.list),
|
||||||
globalTotal: computeResult.globalTotal,
|
globalTotal: computeResult.globalTotal,
|
||||||
accountsTotals: computeResult.accountsTotals,
|
accountsTotals: computeResult.accountsTotals,
|
||||||
));
|
));
|
||||||
@@ -73,7 +78,7 @@ class TransactionBloc extends Bloc<TransactionEvent, TransactionState> {
|
|||||||
return (list: output, globalTotal: globalTotal, accountsTotals: accountsTotals, categories: categories.toList());
|
return (list: output, globalTotal: globalTotal, accountsTotals: accountsTotals, categories: categories.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
_onTransactionDateChange(
|
FutureOr<void> _onTransactionDateChange(
|
||||||
TransactionDateChange event, Emitter<TransactionState> emit
|
TransactionDateChange event, Emitter<TransactionState> emit
|
||||||
) {
|
) {
|
||||||
final transactionDate = TransactionDate.dirty(event.date);
|
final transactionDate = TransactionDate.dirty(event.date);
|
||||||
@@ -83,7 +88,7 @@ class TransactionBloc extends Bloc<TransactionEvent, TransactionState> {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
_onTransactionCategoryChange(
|
FutureOr<void> _onTransactionCategoryChange(
|
||||||
TransactionCategoryChange event, Emitter<TransactionState> emit
|
TransactionCategoryChange event, Emitter<TransactionState> emit
|
||||||
) {
|
) {
|
||||||
final transactionCategory = TransactionCategory.dirty(event.category);
|
final transactionCategory = TransactionCategory.dirty(event.category);
|
||||||
@@ -93,7 +98,7 @@ class TransactionBloc extends Bloc<TransactionEvent, TransactionState> {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
_onTransactionDescriptionChange(
|
FutureOr<void> _onTransactionDescriptionChange(
|
||||||
TransactionDescriptionChange event, Emitter<TransactionState> emit
|
TransactionDescriptionChange event, Emitter<TransactionState> emit
|
||||||
) {
|
) {
|
||||||
final transactionDescription = TransactionDescription.dirty(event.description);
|
final transactionDescription = TransactionDescription.dirty(event.description);
|
||||||
@@ -103,7 +108,7 @@ class TransactionBloc extends Bloc<TransactionEvent, TransactionState> {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
_onTransactionAccountChange(
|
FutureOr<void> _onTransactionAccountChange(
|
||||||
TransactionAccountChange event, Emitter<TransactionState> emit
|
TransactionAccountChange event, Emitter<TransactionState> emit
|
||||||
) {
|
) {
|
||||||
final transactionAccount = TransactionAccount.dirty(event.account);
|
final transactionAccount = TransactionAccount.dirty(event.account);
|
||||||
@@ -113,7 +118,7 @@ class TransactionBloc extends Bloc<TransactionEvent, TransactionState> {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
_onTransactionValueChange(
|
FutureOr<void> _onTransactionValueChange(
|
||||||
TransactionValueChange event, Emitter<TransactionState> emit
|
TransactionValueChange event, Emitter<TransactionState> emit
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
@@ -131,19 +136,19 @@ class TransactionBloc extends Bloc<TransactionEvent, TransactionState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_onTransactionOpenAddDialog(
|
FutureOr<void> _onTransactionOpenAddDialog(
|
||||||
TransactionOpenAddDialog event, Emitter<TransactionState> emit
|
TransactionOpenAddDialog event, Emitter<TransactionState> emit
|
||||||
) {
|
) {
|
||||||
emit(state.copyWith(showAddDialog: true));
|
emit(state.copyWith(showAddDialog: true));
|
||||||
}
|
}
|
||||||
|
|
||||||
_onTransactionHideAddDialog(
|
FutureOr<void> _onTransactionHideAddDialog(
|
||||||
TransactionHideAddDialog event, Emitter<TransactionState> emit
|
TransactionHideAddDialog event, Emitter<TransactionState> emit
|
||||||
) {
|
) {
|
||||||
emit(state.copyWith(showAddDialog: false));
|
emit(state.copyWith(showAddDialog: false));
|
||||||
}
|
}
|
||||||
|
|
||||||
_onTransactionAddDialog(
|
FutureOr<void> _onTransactionAddDialog(
|
||||||
TransactionAdd event, Emitter<TransactionState> emit
|
TransactionAdd event, Emitter<TransactionState> emit
|
||||||
) {
|
) {
|
||||||
if (state.isValid) {
|
if (state.isValid) {
|
||||||
@@ -174,14 +179,17 @@ class TransactionBloc extends Bloc<TransactionEvent, TransactionState> {
|
|||||||
// transactionValue: const TransactionValue.pure(),
|
// transactionValue: const TransactionValue.pure(),
|
||||||
transactions: transactions,
|
transactions: transactions,
|
||||||
transactionsLines: computeResult.list,
|
transactionsLines: computeResult.list,
|
||||||
transactionsLinesFiltered: _applyCategoryFilter(computeResult.list),
|
transactionsLinesFiltered: _applyFilters(computeResult.list),
|
||||||
globalTotal: computeResult.globalTotal,
|
globalTotal: computeResult.globalTotal,
|
||||||
accountsTotals: computeResult.accountsTotals,
|
accountsTotals: computeResult.accountsTotals,
|
||||||
|
showSnackBar: true,
|
||||||
|
snackBarIsError: false,
|
||||||
|
snackBarMessage: 'Transaction ${currentTransaction == null ? 'added' : 'updated'} !',
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_onTransactionSetCurrent(
|
FutureOr<void> _onTransactionSetCurrent(
|
||||||
TransactionSetCurrent event, Emitter<TransactionState> emit
|
TransactionSetCurrent event, Emitter<TransactionState> emit
|
||||||
) {
|
) {
|
||||||
Transaction? transaction = event.transaction;
|
Transaction? transaction = event.transaction;
|
||||||
@@ -206,7 +214,7 @@ class TransactionBloc extends Bloc<TransactionEvent, TransactionState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_onTransactionDeleteCurrent(
|
FutureOr<void> _onTransactionDeleteCurrent(
|
||||||
TransactionDeleteCurrent event, Emitter<TransactionState> emit
|
TransactionDeleteCurrent event, Emitter<TransactionState> emit
|
||||||
) {
|
) {
|
||||||
Transaction? currentTransaction = state.currentTransaction;
|
Transaction? currentTransaction = state.currentTransaction;
|
||||||
@@ -224,33 +232,83 @@ class TransactionBloc extends Bloc<TransactionEvent, TransactionState> {
|
|||||||
transactionValue: const TransactionValue.pure(),
|
transactionValue: const TransactionValue.pure(),
|
||||||
transactions: transactions,
|
transactions: transactions,
|
||||||
transactionsLines: computeResult.list,
|
transactionsLines: computeResult.list,
|
||||||
transactionsLinesFiltered: _applyCategoryFilter(computeResult.list),
|
transactionsLinesFiltered: _applyFilters(computeResult.list),
|
||||||
globalTotal: computeResult.globalTotal,
|
globalTotal: computeResult.globalTotal,
|
||||||
accountsTotals: computeResult.accountsTotals,
|
accountsTotals: computeResult.accountsTotals,
|
||||||
|
showSnackBar: true,
|
||||||
|
snackBarIsError: false,
|
||||||
|
snackBarMessage: 'Transaction removed !',
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
_onTransactionFilterCategory(TransactionFilterCategory event, Emitter<TransactionState> emit) {
|
FutureOr<void> _onTransactionFilterCategory(TransactionFilterCategory event, Emitter<TransactionState> emit) {
|
||||||
List<TransactionLine> transactionsLinesFiltered = state.transactionsLines;
|
emit(TransactionState(
|
||||||
String? categoryLabel = event.category?.label;
|
globalTotal: state.globalTotal,
|
||||||
if (categoryLabel != null) {
|
accountsTotals: state.accountsTotals,
|
||||||
transactionsLinesFiltered = state.transactionsLines.where((transaction) => transaction.transaction.category == categoryLabel).toList();
|
transactions: state.transactions,
|
||||||
}
|
transactionsLines: state.transactionsLines,
|
||||||
|
transactionsLinesFiltered: state.transactionsLinesFiltered,
|
||||||
|
transactionDate: state.transactionDate,
|
||||||
|
transactionCategory: state.transactionCategory,
|
||||||
|
transactionDescription: state.transactionDescription,
|
||||||
|
transactionAccount: state.transactionAccount,
|
||||||
|
transactionValue: state.transactionValue,
|
||||||
|
isValid: state.isValid,
|
||||||
|
showAddDialog: state.showAddDialog,
|
||||||
|
currentTransaction: state.currentTransaction,
|
||||||
|
categoryFilter: event.category,
|
||||||
|
accountFilter: state.accountFilter,
|
||||||
|
));
|
||||||
|
|
||||||
emit(state.copyWith(
|
emit(state.copyWith(
|
||||||
transactionsLinesFiltered: transactionsLinesFiltered,
|
transactionsLinesFiltered: _applyFilters(state.transactionsLines),
|
||||||
categoryFilter: event.category,
|
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
List<TransactionLine> _applyCategoryFilter(List<TransactionLine> transactionsLines) {
|
FutureOr<void> _onTransactionFilterAccount(TransactionFilterAccount event, Emitter<TransactionState> emit) {
|
||||||
|
emit(TransactionState(
|
||||||
|
globalTotal: state.globalTotal,
|
||||||
|
accountsTotals: state.accountsTotals,
|
||||||
|
transactions: state.transactions,
|
||||||
|
transactionsLines: state.transactionsLines,
|
||||||
|
transactionsLinesFiltered: state.transactionsLinesFiltered,
|
||||||
|
transactionDate: state.transactionDate,
|
||||||
|
transactionCategory: state.transactionCategory,
|
||||||
|
transactionDescription: state.transactionDescription,
|
||||||
|
transactionAccount: state.transactionAccount,
|
||||||
|
transactionValue: state.transactionValue,
|
||||||
|
isValid: state.isValid,
|
||||||
|
showAddDialog: state.showAddDialog,
|
||||||
|
currentTransaction: state.currentTransaction,
|
||||||
|
categoryFilter: state.categoryFilter,
|
||||||
|
accountFilter: event.account,
|
||||||
|
));
|
||||||
|
emit(state.copyWith(
|
||||||
|
transactionsLinesFiltered: _applyFilters(state.transactionsLines),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
List<TransactionLine> _applyFilters(List<TransactionLine> transactionsLines) {
|
||||||
List<TransactionLine> transactionsLinesFiltered = transactionsLines;
|
List<TransactionLine> transactionsLinesFiltered = transactionsLines;
|
||||||
String? categoryLabel = state.categoryFilter?.label;
|
String? categoryLabel = state.categoryFilter?.label;
|
||||||
if (categoryLabel != null) {
|
if (categoryLabel != null) {
|
||||||
transactionsLinesFiltered = state.transactionsLines.where((transaction) => transaction.transaction.category == categoryLabel).toList();
|
transactionsLinesFiltered = transactionsLinesFiltered.where((transaction) => transaction.transaction.category == categoryLabel).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String? accountLabel = state.accountFilter?.label;
|
||||||
|
if (accountLabel != null) {
|
||||||
|
transactionsLinesFiltered = transactionsLinesFiltered.where((transaction) => transaction.transaction.account == accountLabel).toList();
|
||||||
|
}
|
||||||
|
|
||||||
return transactionsLinesFiltered;
|
return transactionsLinesFiltered;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FutureOr<void> _onTransactionResetSnackBar(TransactionResetSnackBar event, Emitter<TransactionState> emit) {
|
||||||
|
emit(state.copyWith(
|
||||||
|
showSnackBar: false,
|
||||||
|
snackBarIsError: false,
|
||||||
|
snackBarMessage: '',
|
||||||
|
));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -77,4 +77,14 @@ final class TransactionFilterCategory extends TransactionEvent {
|
|||||||
final Category? category;
|
final Category? category;
|
||||||
|
|
||||||
const TransactionFilterCategory(this.category);
|
const TransactionFilterCategory(this.category);
|
||||||
|
}
|
||||||
|
|
||||||
|
final class TransactionFilterAccount extends TransactionEvent {
|
||||||
|
final Account? account;
|
||||||
|
|
||||||
|
const TransactionFilterAccount(this.account);
|
||||||
|
}
|
||||||
|
|
||||||
|
final class TransactionResetSnackBar extends TransactionEvent {
|
||||||
|
const TransactionResetSnackBar();
|
||||||
}
|
}
|
||||||
@@ -8,6 +8,7 @@ final class TransactionState extends Equatable {
|
|||||||
final List<TransactionLine> transactionsLines;
|
final List<TransactionLine> transactionsLines;
|
||||||
final List<TransactionLine> transactionsLinesFiltered;
|
final List<TransactionLine> transactionsLinesFiltered;
|
||||||
final Category? categoryFilter;
|
final Category? categoryFilter;
|
||||||
|
final Account? accountFilter;
|
||||||
|
|
||||||
final TransactionDate transactionDate;
|
final TransactionDate transactionDate;
|
||||||
final TransactionCategory transactionCategory;
|
final TransactionCategory transactionCategory;
|
||||||
@@ -19,6 +20,10 @@ final class TransactionState extends Equatable {
|
|||||||
|
|
||||||
final Transaction? currentTransaction;
|
final Transaction? currentTransaction;
|
||||||
|
|
||||||
|
final bool showSnackBar;
|
||||||
|
final String snackBarMessage;
|
||||||
|
final bool snackBarIsError;
|
||||||
|
|
||||||
const TransactionState({
|
const TransactionState({
|
||||||
this.globalTotal = 0,
|
this.globalTotal = 0,
|
||||||
this.accountsTotals = const <String, double>{},
|
this.accountsTotals = const <String, double>{},
|
||||||
@@ -34,6 +39,10 @@ final class TransactionState extends Equatable {
|
|||||||
this.showAddDialog = false,
|
this.showAddDialog = false,
|
||||||
this.currentTransaction,
|
this.currentTransaction,
|
||||||
this.categoryFilter,
|
this.categoryFilter,
|
||||||
|
this.accountFilter,
|
||||||
|
this.showSnackBar = false,
|
||||||
|
this.snackBarMessage = '',
|
||||||
|
this.snackBarIsError = false,
|
||||||
});
|
});
|
||||||
|
|
||||||
TransactionState copyWith({
|
TransactionState copyWith({
|
||||||
@@ -51,6 +60,10 @@ final class TransactionState extends Equatable {
|
|||||||
bool? showAddDialog,
|
bool? showAddDialog,
|
||||||
Transaction? currentTransaction,
|
Transaction? currentTransaction,
|
||||||
Category? categoryFilter,
|
Category? categoryFilter,
|
||||||
|
Account? accountFilter,
|
||||||
|
bool? showSnackBar,
|
||||||
|
String? snackBarMessage,
|
||||||
|
bool? snackBarIsError,
|
||||||
}) {
|
}) {
|
||||||
return TransactionState(
|
return TransactionState(
|
||||||
globalTotal: globalTotal ?? this.globalTotal,
|
globalTotal: globalTotal ?? this.globalTotal,
|
||||||
@@ -66,12 +79,19 @@ final class TransactionState extends Equatable {
|
|||||||
isValid: isValid ?? this.isValid,
|
isValid: isValid ?? this.isValid,
|
||||||
showAddDialog: showAddDialog ?? this.showAddDialog,
|
showAddDialog: showAddDialog ?? this.showAddDialog,
|
||||||
currentTransaction: currentTransaction ?? this.currentTransaction,
|
currentTransaction: currentTransaction ?? this.currentTransaction,
|
||||||
categoryFilter: categoryFilter,
|
categoryFilter: categoryFilter ?? this.categoryFilter,
|
||||||
|
accountFilter: accountFilter ?? this.accountFilter,
|
||||||
|
showSnackBar: showSnackBar ?? this.showSnackBar,
|
||||||
|
snackBarMessage: snackBarMessage ?? this.snackBarMessage,
|
||||||
|
snackBarIsError: snackBarIsError ?? this.snackBarIsError,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object?> get props => [
|
List<Object?> get props => [
|
||||||
|
transactions,
|
||||||
|
transactionsLines,
|
||||||
|
transactionsLinesFiltered,
|
||||||
transactionDate,
|
transactionDate,
|
||||||
transactionCategory,
|
transactionCategory,
|
||||||
transactionDescription,
|
transactionDescription,
|
||||||
@@ -81,6 +101,10 @@ final class TransactionState extends Equatable {
|
|||||||
showAddDialog,
|
showAddDialog,
|
||||||
currentTransaction,
|
currentTransaction,
|
||||||
categoryFilter,
|
categoryFilter,
|
||||||
|
accountFilter,
|
||||||
|
showSnackBar,
|
||||||
|
snackBarMessage,
|
||||||
|
snackBarIsError,
|
||||||
];
|
];
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:krezus/domains/transaction/transaction_bloc.dart';
|
||||||
import 'package:krezus/pages/transactions/widgets/transactions_actions.dart';
|
import 'package:krezus/pages/transactions/widgets/transactions_actions.dart';
|
||||||
import 'package:krezus/pages/transactions/widgets/transactions_header.dart';
|
import 'package:krezus/pages/transactions/widgets/transactions_header.dart';
|
||||||
import 'package:krezus/pages/transactions/widgets/transactions_list.dart';
|
import 'package:krezus/pages/transactions/widgets/transactions_list.dart';
|
||||||
@@ -9,20 +11,34 @@ class TransactionsPage extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
MediaQueryData mediaQuery = MediaQuery.of(context);
|
MediaQueryData mediaQuery = MediaQuery.of(context);
|
||||||
return Center(
|
return BlocListener<TransactionBloc, TransactionState>(
|
||||||
child: Container(
|
listenWhen: (previous, current) => previous.showSnackBar != current.showSnackBar,
|
||||||
constraints: const BoxConstraints(
|
listener: (context, state) {
|
||||||
maxWidth: 1000
|
if (state.showSnackBar) {
|
||||||
|
ScaffoldMessenger
|
||||||
|
.of(context)
|
||||||
|
.showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
backgroundColor: state.snackBarIsError ? Colors.red : Colors.green,
|
||||||
|
content: Text(state.snackBarMessage),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
context.read<TransactionBloc>().add(const TransactionResetSnackBar());
|
||||||
|
}
|
||||||
|
},
|
||||||
|
child: Center(
|
||||||
|
child: Container(
|
||||||
|
constraints: const BoxConstraints(maxWidth: 1000),
|
||||||
|
padding: mediaQuery.padding,
|
||||||
|
child: const Column(
|
||||||
|
children: [
|
||||||
|
TransactionsActions(),
|
||||||
|
TransactionsHeader(),
|
||||||
|
TransactionsList(),
|
||||||
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
padding: mediaQuery.padding,
|
),
|
||||||
child: const Column(
|
|
||||||
children: [
|
|
||||||
TransactionsActions(),
|
|
||||||
TransactionsHeader(),
|
|
||||||
TransactionsList(),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
36
lib/pages/transactions/widgets/account_filter.dart
Normal file
36
lib/pages/transactions/widgets/account_filter.dart
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:krezus/domains/account/account_bloc.dart';
|
||||||
|
import 'package:krezus/domains/transaction/transaction_bloc.dart';
|
||||||
|
import 'package:krezus/repositories/metadata/models/account.dart';
|
||||||
|
|
||||||
|
class AccountFilter extends StatelessWidget {
|
||||||
|
const AccountFilter({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final accountState = context.watch<AccountBloc>().state;
|
||||||
|
|
||||||
|
return BlocBuilder<TransactionBloc, TransactionState>(
|
||||||
|
buildWhen: (previous, current) => previous.accountFilter != current.accountFilter,
|
||||||
|
builder: (context, state) => SizedBox(
|
||||||
|
width: 300,
|
||||||
|
child: DropdownButtonFormField<Account>(
|
||||||
|
value: state.accountFilter,
|
||||||
|
onChanged: (value) => context.read<TransactionBloc>().add(TransactionFilterAccount(value!)),
|
||||||
|
items: accountState.accounts.map((e) => DropdownMenuItem(value: e, child: Text(e.label))).toList(),
|
||||||
|
decoration: InputDecoration(
|
||||||
|
suffixIcon: IconButton(
|
||||||
|
icon: const Icon(Icons.filter_alt_off),
|
||||||
|
onPressed: () => context.read<TransactionBloc>().add(const TransactionFilterAccount(null)),
|
||||||
|
),
|
||||||
|
hintText: 'Account',
|
||||||
|
border: OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.circular(5),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,10 +10,11 @@ class CategoryFilter extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final categoryState = context.watch<CategoryBloc>().state;
|
final categoryState = context.watch<CategoryBloc>().state;
|
||||||
|
|
||||||
return BlocBuilder<TransactionBloc, TransactionState>(
|
return BlocBuilder<TransactionBloc, TransactionState>(
|
||||||
buildWhen: (previous, current) => previous.categoryFilter != current.categoryFilter,
|
buildWhen: (previous, current) => previous.categoryFilter != current.categoryFilter,
|
||||||
builder: (context, state) => SizedBox(
|
builder: (context, state) => SizedBox(
|
||||||
width: 500,
|
width: 300,
|
||||||
child: DropdownButtonFormField<krezus_category.Category>(
|
child: DropdownButtonFormField<krezus_category.Category>(
|
||||||
value: state.categoryFilter,
|
value: state.categoryFilter,
|
||||||
onChanged: (value) => context.read<TransactionBloc>().add(TransactionFilterCategory(value!)),
|
onChanged: (value) => context.read<TransactionBloc>().add(TransactionFilterCategory(value!)),
|
||||||
|
|||||||
@@ -21,8 +21,8 @@ class TransactionAddDialog extends StatelessWidget {
|
|||||||
BlocProvider.value(value: BlocProvider.of<CategoryBloc>(context)),
|
BlocProvider.value(value: BlocProvider.of<CategoryBloc>(context)),
|
||||||
BlocProvider.value(value: BlocProvider.of<AccountBloc>(context)),
|
BlocProvider.value(value: BlocProvider.of<AccountBloc>(context)),
|
||||||
],
|
],
|
||||||
child: const TransactionAddDialog()
|
child: const TransactionAddDialog(),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,18 +32,18 @@ class TransactionAddDialog extends StatelessWidget {
|
|||||||
final actions = [
|
final actions = [
|
||||||
IconButton(
|
IconButton(
|
||||||
onPressed: () => TransactionAddDialog.hide(context),
|
onPressed: () => TransactionAddDialog.hide(context),
|
||||||
icon: const Icon(Icons.close)
|
icon: const Icon(Icons.close),
|
||||||
),
|
),
|
||||||
IconButton(
|
IconButton(
|
||||||
onPressed: () => context.read<TransactionBloc>().add(const TransactionAdd()),
|
onPressed: () => context.read<TransactionBloc>().add(const TransactionAdd()),
|
||||||
icon: const Icon(Icons.save)
|
icon: const Icon(Icons.save),
|
||||||
),
|
),
|
||||||
];
|
];
|
||||||
|
|
||||||
if (currentTransaction != null) {
|
if (currentTransaction != null) {
|
||||||
actions.add(IconButton(
|
actions.add(IconButton(
|
||||||
onPressed: () => context.read<TransactionBloc>().add(const TransactionDeleteCurrent()),
|
onPressed: () => context.read<TransactionBloc>().add(const TransactionDeleteCurrent()),
|
||||||
icon: const Icon(Icons.delete)
|
icon: const Icon(Icons.delete),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,8 +57,8 @@ class TransactionAddDialog extends StatelessWidget {
|
|||||||
builder: (context, state) => AlertDialog(
|
builder: (context, state) => AlertDialog(
|
||||||
title: Text(state.currentTransaction == null ? 'Add Transaction' : 'Edit Transaction'),
|
title: Text(state.currentTransaction == null ? 'Add Transaction' : 'Edit Transaction'),
|
||||||
actions: _computeActions(context, state.currentTransaction),
|
actions: _computeActions(context, state.currentTransaction),
|
||||||
content: const TransactionForm()
|
content: const TransactionForm(),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:krezus/domains/transaction/transaction_bloc.dart';
|
import 'package:krezus/domains/transaction/transaction_bloc.dart';
|
||||||
|
import 'package:krezus/pages/transactions/widgets/account_filter.dart';
|
||||||
import 'package:krezus/pages/transactions/widgets/category_filter.dart';
|
import 'package:krezus/pages/transactions/widgets/category_filter.dart';
|
||||||
import 'package:krezus/pages/transactions/widgets/transaction_add_dialog.dart';
|
import 'package:krezus/pages/transactions/widgets/transaction_add_dialog.dart';
|
||||||
|
|
||||||
@@ -31,6 +32,7 @@ class TransactionsActions extends StatelessWidget {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
const CategoryFilter(),
|
const CategoryFilter(),
|
||||||
|
const AccountFilter(),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -47,6 +49,7 @@ class TransactionsActions extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
const CategoryFilter(),
|
const CategoryFilter(),
|
||||||
|
const AccountFilter(),
|
||||||
IconButton(
|
IconButton(
|
||||||
onPressed: () => TransactionAddDialog.show(context, null),
|
onPressed: () => TransactionAddDialog.show(context, null),
|
||||||
icon: const Icon(
|
icon: const Icon(
|
||||||
|
|||||||
@@ -15,10 +15,10 @@ class TransactionsList extends StatelessWidget {
|
|||||||
itemCount: state.transactionsLinesFiltered.length,
|
itemCount: state.transactionsLinesFiltered.length,
|
||||||
itemBuilder: (context, index) => TransactionLine(
|
itemBuilder: (context, index) => TransactionLine(
|
||||||
transaction: state.transactionsLinesFiltered[index].transaction,
|
transaction: state.transactionsLinesFiltered[index].transaction,
|
||||||
subTotal: state.transactionsLinesFiltered[index].subTotal
|
subTotal: state.transactionsLinesFiltered[index].subTotal,
|
||||||
)
|
),
|
||||||
)
|
),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,14 +1,15 @@
|
|||||||
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:uuid/uuid.dart';
|
import 'package:uuid/uuid.dart';
|
||||||
|
|
||||||
class Transaction {
|
class Transaction extends Equatable {
|
||||||
String uuid;
|
final String uuid;
|
||||||
DateTime date;
|
final DateTime date;
|
||||||
String category;
|
final String category;
|
||||||
String description;
|
final String description;
|
||||||
String account;
|
final String account;
|
||||||
double value;
|
final double value;
|
||||||
|
|
||||||
Transaction({
|
const Transaction({
|
||||||
required this.uuid,
|
required this.uuid,
|
||||||
required this.date,
|
required this.date,
|
||||||
required this.category,
|
required this.category,
|
||||||
@@ -36,4 +37,7 @@ class Transaction {
|
|||||||
'account': account,
|
'account': account,
|
||||||
'value': value.toString(),
|
'value': value.toString(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [uuid, date, category, description, account, value];
|
||||||
}
|
}
|
||||||
67
pubspec.lock
67
pubspec.lock
@@ -5,10 +5,10 @@ packages:
|
|||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: archive
|
name: archive
|
||||||
sha256: "22600aa1e926be775fa5fe7e6894e7fb3df9efda8891c73f70fb3262399a432d"
|
sha256: cb6a278ef2dbb298455e1a713bda08524a175630ec643a242c399c932a0a1f7d
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "3.4.10"
|
version: "3.6.1"
|
||||||
args:
|
args:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@@ -81,14 +81,6 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.18.0"
|
version: "1.18.0"
|
||||||
convert:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: convert
|
|
||||||
sha256: "0f08b14755d163f6e2134cb58222dd25ea2a2ee8a195e53983d57c075324d592"
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "3.1.1"
|
|
||||||
cross_file:
|
cross_file:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@@ -173,10 +165,10 @@ packages:
|
|||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: fl_chart
|
name: fl_chart
|
||||||
sha256: "2b7c1f5d867da9a054661641c8f499c55c47c39acccb97b3bc673f5fa9a39e74"
|
sha256: d0f0d49112f2f4b192481c16d05b6418bd7820e021e265a3c22db98acf7ed7fb
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.67.0"
|
version: "0.68.0"
|
||||||
flex_color_picker:
|
flex_color_picker:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
@@ -202,10 +194,10 @@ packages:
|
|||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: flutter_bloc
|
name: flutter_bloc
|
||||||
sha256: f0ecf6e6eb955193ca60af2d5ca39565a86b8a142452c5b24d96fb477428f4d2
|
sha256: b594505eac31a0518bdcb4b5b79573b8d9117b193cc80cc12e17d639b10aa27a
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "8.1.5"
|
version: "8.1.6"
|
||||||
flutter_keyboard_visibility:
|
flutter_keyboard_visibility:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@@ -266,10 +258,15 @@ packages:
|
|||||||
dependency: "direct dev"
|
dependency: "direct dev"
|
||||||
description:
|
description:
|
||||||
name: flutter_lints
|
name: flutter_lints
|
||||||
sha256: "9e8c3858111da373efc5aa341de011d9bd23e2c5c5e0c62bccf32438e192d7b1"
|
sha256: "3f41d009ba7172d5ff9be5f6e6e6abb4300e263aab8866d2a0842ed2a70f8f0c"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "3.0.2"
|
version: "4.0.0"
|
||||||
|
flutter_localizations:
|
||||||
|
dependency: "direct main"
|
||||||
|
description: flutter
|
||||||
|
source: sdk
|
||||||
|
version: "0.0.0"
|
||||||
flutter_plugin_android_lifecycle:
|
flutter_plugin_android_lifecycle:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@@ -308,34 +305,34 @@ packages:
|
|||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: image
|
name: image
|
||||||
sha256: "4c68bfd5ae83e700b5204c1e74451e7bf3cf750e6843c6e158289cf56bda018e"
|
sha256: "2237616a36c0d69aef7549ab439b833fb7f9fb9fc861af2cc9ac3eedddd69ca8"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "4.1.7"
|
version: "4.2.0"
|
||||||
js:
|
intl:
|
||||||
dependency: transitive
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: js
|
name: intl
|
||||||
sha256: c1b2e9b5ea78c45e1a0788d29606ba27dc5f71f019f32ca5140f61ef071838cf
|
sha256: "3bc132a9dbce73a7e4a21a17d06e1878839ffbf975568bc875c60537824b0c4d"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.7.1"
|
version: "0.18.1"
|
||||||
json_annotation:
|
json_annotation:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: json_annotation
|
name: json_annotation
|
||||||
sha256: b10a7b2ff83d83c777edba3c6a0f97045ddadd56c944e1a23a3fdf43a1bf4467
|
sha256: "1ce844379ca14835a50d2f019a3099f419082cfdd231cd86a142af94dd5c6bb1"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "4.8.1"
|
version: "4.9.0"
|
||||||
lints:
|
lints:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: lints
|
name: lints
|
||||||
sha256: cbf8d4b858bb0134ef3ef87841abdf8d63bfc255c266b7bf6b39daa1085c4290
|
sha256: "976c774dd944a42e83e2467f4cc670daef7eed6295b10b36ae8c85bcbf828235"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "3.0.0"
|
version: "4.0.0"
|
||||||
logging:
|
logging:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
@@ -444,10 +441,10 @@ packages:
|
|||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: platform
|
name: platform
|
||||||
sha256: "12220bb4b65720483f8fa9450b4332347737cf8213dd2840d8b2c823e47243ec"
|
sha256: "9b71283fc13df574056616011fb138fd3b793ea47cc509c189a6c3fa5f8a1a65"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "3.1.4"
|
version: "3.1.5"
|
||||||
plugin_platform_interface:
|
plugin_platform_interface:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@@ -460,10 +457,10 @@ packages:
|
|||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: pointer_interceptor
|
name: pointer_interceptor
|
||||||
sha256: bd18321519718678d5fa98ad3a3359cbc7a31f018554eab80b73d08a7f0c165a
|
sha256: d0a8e660d1204eaec5bd34b34cc92174690e076d2e4f893d9d68c486a13b07c4
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.10.1"
|
version: "0.10.1+1"
|
||||||
pointer_interceptor_ios:
|
pointer_interceptor_ios:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@@ -488,14 +485,6 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.10.1+2"
|
version: "0.10.1+2"
|
||||||
pointycastle:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: pointycastle
|
|
||||||
sha256: "79fbafed02cfdbe85ef3fd06c7f4bc2cbcba0177e61b765264853d4253b21744"
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "3.9.0"
|
|
||||||
provider:
|
provider:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|||||||
@@ -12,9 +12,9 @@ dependencies:
|
|||||||
sdk: flutter
|
sdk: flutter
|
||||||
|
|
||||||
cupertino_icons: ^1.0.2
|
cupertino_icons: ^1.0.2
|
||||||
fl_chart: ^0.67.0
|
fl_chart: ^0.68.0
|
||||||
logging: ^1.2.0
|
logging: ^1.2.0
|
||||||
flutter_bloc: ^8.1.4
|
flutter_bloc: ^8.1.6
|
||||||
path_provider: ^2.1.1
|
path_provider: ^2.1.1
|
||||||
equatable: ^2.0.5
|
equatable: ^2.0.5
|
||||||
rxdart: ^0.27.7
|
rxdart: ^0.27.7
|
||||||
@@ -25,12 +25,15 @@ dependencies:
|
|||||||
flutter_typeahead: ^5.2.0
|
flutter_typeahead: ^5.2.0
|
||||||
flex_color_picker: ^3.3.1
|
flex_color_picker: ^3.3.1
|
||||||
dynamic_color: ^1.6.9
|
dynamic_color: ^1.6.9
|
||||||
|
flutter_localizations:
|
||||||
|
sdk: flutter
|
||||||
|
intl: any
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
|
|
||||||
flutter_lints: ^3.0.1
|
flutter_lints: ^4.0.0
|
||||||
flutter_launcher_icons: "^0.13.1"
|
flutter_launcher_icons: "^0.13.1"
|
||||||
|
|
||||||
flutter:
|
flutter:
|
||||||
|
|||||||
Reference in New Issue
Block a user