budget mockup, account settings & transactions filter
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import 'dart:async';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:csv/csv.dart';
|
import 'package:csv/csv.dart';
|
||||||
@@ -49,6 +50,11 @@ class AccountBloc extends Bloc<AccountEvent, AccountState> {
|
|||||||
on<AccountLoad>(_onAccountLoad);
|
on<AccountLoad>(_onAccountLoad);
|
||||||
// on<AccountExportJSON>(_onAccountImportJSON);
|
// on<AccountExportJSON>(_onAccountImportJSON);
|
||||||
// on<AccountExportCSV>(_onAccountImportJSON);
|
// on<AccountExportCSV>(_onAccountImportJSON);
|
||||||
|
on<AccountAdd>(_onAccountAdd);
|
||||||
|
on<AccountRemove>(_onAcountRemove);
|
||||||
|
on<AccountEditLabel>(_onAccountEditLabel);
|
||||||
|
on<AccountEditSaving>(_onAccountEditSaving);
|
||||||
|
on<AccountEditColor>(_onAccountEditColor);
|
||||||
|
|
||||||
_metadataRepository
|
_metadataRepository
|
||||||
.getAccountsStream()
|
.getAccountsStream()
|
||||||
@@ -103,7 +109,7 @@ class AccountBloc extends Bloc<AccountEvent, AccountState> {
|
|||||||
|
|
||||||
String accountLabel = line[3];
|
String accountLabel = line[3];
|
||||||
if (accounts[accountLabel] == null) {
|
if (accounts[accountLabel] == null) {
|
||||||
accounts[accountLabel] = Account(label: accountLabel);
|
accounts[accountLabel] = Account(label: accountLabel, color: 'FF74feff');
|
||||||
}
|
}
|
||||||
|
|
||||||
return Transaction(
|
return Transaction(
|
||||||
@@ -134,4 +140,72 @@ class AccountBloc extends Bloc<AccountEvent, AccountState> {
|
|||||||
state.copyWith(event.subAccounts)
|
state.copyWith(event.subAccounts)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_onAccountAdd(AccountAdd event, Emitter<AccountState> emit) async {
|
||||||
|
String uuid = const Uuid().v8();
|
||||||
|
Account account = Account(
|
||||||
|
label: 'Account $uuid',
|
||||||
|
color: 'FF74feff',
|
||||||
|
saving: false
|
||||||
|
);
|
||||||
|
emit(
|
||||||
|
state.copyWith(await _saveAccount(account))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
_onAcountRemove(AccountRemove event, Emitter<AccountState> emit) async {
|
||||||
|
Account accountToRemove = event.account;
|
||||||
|
List<Account> accounts = state.accounts;
|
||||||
|
List<Transaction> transactions = _transactionsRepository.getTransactions();
|
||||||
|
|
||||||
|
if (transactions.any((transaction) => transaction.account == accountToRemove.label)) {
|
||||||
|
emit(AccountRemoveFail());
|
||||||
|
emit(AccountState(accounts: accounts));
|
||||||
|
} else {
|
||||||
|
accounts.removeWhere((account) => account.label == accountToRemove.label);
|
||||||
|
emit(AccountRemoveSucess());
|
||||||
|
emit(
|
||||||
|
state.copyWith(await _metadataRepository.saveAccounts(accounts))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_onAccountEditLabel(AccountEditLabel event, Emitter<AccountState> emit) async {
|
||||||
|
Account account = event.account;
|
||||||
|
account.label = event.label;
|
||||||
|
emit(
|
||||||
|
state.copyWith(await _saveAccount(account))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
_onAccountEditSaving(AccountEditSaving event, Emitter<AccountState> emit) async {
|
||||||
|
Account account = event.account;
|
||||||
|
account.saving = event.saving;
|
||||||
|
emit(
|
||||||
|
state.copyWith(await _saveAccount(account))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
_onAccountEditColor(AccountEditColor event, Emitter<AccountState> emit) async {
|
||||||
|
Account account = event.account;
|
||||||
|
account.color = event.color;
|
||||||
|
emit(
|
||||||
|
state.copyWith(await _saveAccount(account))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<List<Account>> _saveAccount(Account accountToSave) async {
|
||||||
|
List<Account> accounts = _metadataRepository.getAccounts();
|
||||||
|
|
||||||
|
try {
|
||||||
|
Account accountFound = accounts.firstWhere((account) => account.label == accountToSave.label);
|
||||||
|
accountFound.color = accountToSave.color;
|
||||||
|
accountFound.saving = accountToSave.saving;
|
||||||
|
} catch (e) {
|
||||||
|
accounts.add(accountToSave);
|
||||||
|
}
|
||||||
|
|
||||||
|
await _metadataRepository.saveAccounts(accounts);
|
||||||
|
return accounts;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,3 +30,44 @@ final class AccountLoad extends AccountEvent {
|
|||||||
@override
|
@override
|
||||||
List<Object> get props => [subAccounts];
|
List<Object> get props => [subAccounts];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final class AccountEditColor extends AccountEvent {
|
||||||
|
final Account account;
|
||||||
|
final String color;
|
||||||
|
|
||||||
|
const AccountEditColor(this.account, this.color);
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [account, color];
|
||||||
|
}
|
||||||
|
|
||||||
|
final class AccountEditSaving extends AccountEvent {
|
||||||
|
final Account account;
|
||||||
|
final bool saving;
|
||||||
|
|
||||||
|
const AccountEditSaving(this.account, this.saving);
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [account, saving];
|
||||||
|
}
|
||||||
|
|
||||||
|
final class AccountEditLabel extends AccountEvent {
|
||||||
|
final Account account;
|
||||||
|
final String label;
|
||||||
|
|
||||||
|
const AccountEditLabel(this.account, this.label);
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [account, label];
|
||||||
|
}
|
||||||
|
|
||||||
|
final class AccountRemove extends AccountEvent {
|
||||||
|
final Account account;
|
||||||
|
|
||||||
|
const AccountRemove(this.account);
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [account];
|
||||||
|
}
|
||||||
|
|
||||||
|
final class AccountAdd extends AccountEvent {}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
part of 'account_bloc.dart';
|
part of 'account_bloc.dart';
|
||||||
|
|
||||||
final class AccountState extends Equatable {
|
final class AccountState {
|
||||||
final List<Account> accounts;
|
final List<Account> accounts;
|
||||||
|
|
||||||
const AccountState({
|
const AccountState({
|
||||||
@@ -12,7 +12,7 @@ final class AccountState extends Equatable {
|
|||||||
accounts: accounts ?? this.accounts,
|
accounts: accounts ?? this.accounts,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
|
||||||
List<Object?> get props => [accounts];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final class AccountRemoveFail extends AccountState {}
|
||||||
|
final class AccountRemoveSucess extends AccountState {}
|
||||||
@@ -7,7 +7,6 @@ import 'package:tunas/domains/charts/models/chart_item.dart';
|
|||||||
import 'package:tunas/repositories/metadata/metadata_repository.dart';
|
import 'package:tunas/repositories/metadata/metadata_repository.dart';
|
||||||
import 'package:tunas/repositories/metadata/models/category.dart';
|
import 'package:tunas/repositories/metadata/models/category.dart';
|
||||||
import 'package:tunas/repositories/transactions/models/transaction.dart';
|
import 'package:tunas/repositories/transactions/models/transaction.dart';
|
||||||
import 'package:tunas/repositories/transactions/models/transactions.dart';
|
|
||||||
import 'package:tunas/repositories/transactions/transactions_repository.dart';
|
import 'package:tunas/repositories/transactions/transactions_repository.dart';
|
||||||
|
|
||||||
part 'chart_event.dart';
|
part 'chart_event.dart';
|
||||||
@@ -138,7 +137,7 @@ class ChartBloc extends Bloc<ChartEvent, ChartState> {
|
|||||||
scopedMonthlyTotals[transactionDateDay] = FlSpot(transactionDateDay.toDouble(), transactionLine.subTotal);
|
scopedMonthlyTotals[transactionDateDay] = FlSpot(transactionDateDay.toDouble(), transactionLine.subTotal);
|
||||||
|
|
||||||
final category = state.categories[transaction.category];
|
final category = state.categories[transaction.category];
|
||||||
if (category == null || category.saving) {
|
if (category == null || category.transfert) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
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';
|
||||||
@@ -8,6 +7,7 @@ import 'package:tunas/domains/transaction/models/transaction_date.dart';
|
|||||||
import 'package:tunas/domains/transaction/models/transaction_description.dart';
|
import 'package:tunas/domains/transaction/models/transaction_description.dart';
|
||||||
import 'package:tunas/domains/transaction/models/transaction_line.dart';
|
import 'package:tunas/domains/transaction/models/transaction_line.dart';
|
||||||
import 'package:tunas/domains/transaction/models/transaction_value.dart';
|
import 'package:tunas/domains/transaction/models/transaction_value.dart';
|
||||||
|
import 'package:tunas/repositories/metadata/models/category.dart';
|
||||||
import 'package:tunas/repositories/transactions/models/transaction.dart';
|
import 'package:tunas/repositories/transactions/models/transaction.dart';
|
||||||
import 'package:tunas/repositories/transactions/transactions_repository.dart';
|
import 'package:tunas/repositories/transactions/transactions_repository.dart';
|
||||||
import 'package:uuid/uuid.dart';
|
import 'package:uuid/uuid.dart';
|
||||||
@@ -32,6 +32,7 @@ class TransactionBloc extends Bloc<TransactionEvent, TransactionState> {
|
|||||||
on<TransactionAdd>(_onTransactionAddDialog);
|
on<TransactionAdd>(_onTransactionAddDialog);
|
||||||
on<TransactionSetCurrent>(_onTransactionSetCurrent);
|
on<TransactionSetCurrent>(_onTransactionSetCurrent);
|
||||||
on<TransactionDeleteCurrent>(_onTransactionDeleteCurrent);
|
on<TransactionDeleteCurrent>(_onTransactionDeleteCurrent);
|
||||||
|
on<TransactionFilterCategory>(_onTransactionFilterCategory);
|
||||||
|
|
||||||
_transactionsRepository
|
_transactionsRepository
|
||||||
.getTransactionsStream()
|
.getTransactionsStream()
|
||||||
@@ -43,6 +44,7 @@ class TransactionBloc extends Bloc<TransactionEvent, TransactionState> {
|
|||||||
emit(state.copyWith(
|
emit(state.copyWith(
|
||||||
transactions: event.transactions,
|
transactions: event.transactions,
|
||||||
transactionsLines: computeResult.list,
|
transactionsLines: computeResult.list,
|
||||||
|
transactionsLinesFiltered: _applyCategoryFilter(computeResult.list),
|
||||||
globalTotal: computeResult.globalTotal,
|
globalTotal: computeResult.globalTotal,
|
||||||
accountsTotals: computeResult.accountsTotals,
|
accountsTotals: computeResult.accountsTotals,
|
||||||
));
|
));
|
||||||
@@ -172,6 +174,7 @@ 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),
|
||||||
globalTotal: computeResult.globalTotal,
|
globalTotal: computeResult.globalTotal,
|
||||||
accountsTotals: computeResult.accountsTotals,
|
accountsTotals: computeResult.accountsTotals,
|
||||||
));
|
));
|
||||||
@@ -221,10 +224,33 @@ 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),
|
||||||
globalTotal: computeResult.globalTotal,
|
globalTotal: computeResult.globalTotal,
|
||||||
accountsTotals: computeResult.accountsTotals,
|
accountsTotals: computeResult.accountsTotals,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
_onTransactionFilterCategory(TransactionFilterCategory event, Emitter<TransactionState> emit) {
|
||||||
|
List<TransactionLine> transactionsLinesFiltered = state.transactionsLines;
|
||||||
|
String? categoryLabel = event.category?.label;
|
||||||
|
if (categoryLabel != null) {
|
||||||
|
transactionsLinesFiltered = state.transactionsLines.where((transaction) => transaction.transaction.category == categoryLabel).toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
emit(state.copyWith(
|
||||||
|
transactionsLinesFiltered: transactionsLinesFiltered,
|
||||||
|
categoryFilter: event.category,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
List<TransactionLine> _applyCategoryFilter(List<TransactionLine> transactionsLines) {
|
||||||
|
List<TransactionLine> transactionsLinesFiltered = transactionsLines;
|
||||||
|
String? categoryLabel = state.categoryFilter?.label;
|
||||||
|
if (categoryLabel != null) {
|
||||||
|
transactionsLinesFiltered = state.transactionsLines.where((transaction) => transaction.transaction.category == categoryLabel).toList();
|
||||||
|
}
|
||||||
|
return transactionsLinesFiltered;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -72,3 +72,9 @@ final class TransactionSetCurrent extends TransactionEvent {
|
|||||||
final class TransactionDeleteCurrent extends TransactionEvent {
|
final class TransactionDeleteCurrent extends TransactionEvent {
|
||||||
const TransactionDeleteCurrent();
|
const TransactionDeleteCurrent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final class TransactionFilterCategory extends TransactionEvent {
|
||||||
|
final Category? category;
|
||||||
|
|
||||||
|
const TransactionFilterCategory(this.category);
|
||||||
|
}
|
||||||
@@ -6,6 +6,8 @@ final class TransactionState extends Equatable {
|
|||||||
|
|
||||||
final List<Transaction> transactions;
|
final List<Transaction> transactions;
|
||||||
final List<TransactionLine> transactionsLines;
|
final List<TransactionLine> transactionsLines;
|
||||||
|
final List<TransactionLine> transactionsLinesFiltered;
|
||||||
|
final Category? categoryFilter;
|
||||||
|
|
||||||
final TransactionDate transactionDate;
|
final TransactionDate transactionDate;
|
||||||
final TransactionCategory transactionCategory;
|
final TransactionCategory transactionCategory;
|
||||||
@@ -22,6 +24,7 @@ final class TransactionState extends Equatable {
|
|||||||
this.accountsTotals = const <String, double>{},
|
this.accountsTotals = const <String, double>{},
|
||||||
this.transactions = const [],
|
this.transactions = const [],
|
||||||
this.transactionsLines = const [],
|
this.transactionsLines = const [],
|
||||||
|
this.transactionsLinesFiltered = const [],
|
||||||
this.transactionDate = const TransactionDate.pure(),
|
this.transactionDate = const TransactionDate.pure(),
|
||||||
this.transactionCategory = const TransactionCategory.pure(),
|
this.transactionCategory = const TransactionCategory.pure(),
|
||||||
this.transactionDescription = const TransactionDescription.pure(),
|
this.transactionDescription = const TransactionDescription.pure(),
|
||||||
@@ -29,7 +32,8 @@ final class TransactionState extends Equatable {
|
|||||||
this.transactionValue = const TransactionValue.pure(),
|
this.transactionValue = const TransactionValue.pure(),
|
||||||
this.isValid = false,
|
this.isValid = false,
|
||||||
this.showAddDialog = false,
|
this.showAddDialog = false,
|
||||||
this.currentTransaction
|
this.currentTransaction,
|
||||||
|
this.categoryFilter,
|
||||||
});
|
});
|
||||||
|
|
||||||
TransactionState copyWith({
|
TransactionState copyWith({
|
||||||
@@ -37,6 +41,7 @@ final class TransactionState extends Equatable {
|
|||||||
Map<String, double>? accountsTotals,
|
Map<String, double>? accountsTotals,
|
||||||
List<Transaction>? transactions,
|
List<Transaction>? transactions,
|
||||||
List<TransactionLine>? transactionsLines,
|
List<TransactionLine>? transactionsLines,
|
||||||
|
List<TransactionLine>? transactionsLinesFiltered,
|
||||||
TransactionDate? transactionDate,
|
TransactionDate? transactionDate,
|
||||||
TransactionCategory? transactionCategory,
|
TransactionCategory? transactionCategory,
|
||||||
TransactionDescription? transactionDescription,
|
TransactionDescription? transactionDescription,
|
||||||
@@ -45,12 +50,14 @@ final class TransactionState extends Equatable {
|
|||||||
bool? isValid,
|
bool? isValid,
|
||||||
bool? showAddDialog,
|
bool? showAddDialog,
|
||||||
Transaction? currentTransaction,
|
Transaction? currentTransaction,
|
||||||
|
Category? categoryFilter,
|
||||||
}) {
|
}) {
|
||||||
return TransactionState(
|
return TransactionState(
|
||||||
globalTotal: globalTotal ?? this.globalTotal,
|
globalTotal: globalTotal ?? this.globalTotal,
|
||||||
accountsTotals: accountsTotals ?? this.accountsTotals,
|
accountsTotals: accountsTotals ?? this.accountsTotals,
|
||||||
transactions: transactions ?? this.transactions,
|
transactions: transactions ?? this.transactions,
|
||||||
transactionsLines: transactionsLines ?? this.transactionsLines,
|
transactionsLines: transactionsLines ?? this.transactionsLines,
|
||||||
|
transactionsLinesFiltered: transactionsLinesFiltered ?? this.transactionsLinesFiltered,
|
||||||
transactionDate: transactionDate ?? this.transactionDate,
|
transactionDate: transactionDate ?? this.transactionDate,
|
||||||
transactionCategory: transactionCategory ?? this.transactionCategory,
|
transactionCategory: transactionCategory ?? this.transactionCategory,
|
||||||
transactionDescription: transactionDescription ?? this.transactionDescription,
|
transactionDescription: transactionDescription ?? this.transactionDescription,
|
||||||
@@ -59,6 +66,7 @@ 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,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,6 +80,7 @@ final class TransactionState extends Equatable {
|
|||||||
isValid,
|
isValid,
|
||||||
showAddDialog,
|
showAddDialog,
|
||||||
currentTransaction,
|
currentTransaction,
|
||||||
|
categoryFilter,
|
||||||
];
|
];
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:tunas/pages/budgets/widgets/budgets_actions.dart';
|
import 'package:tunas/pages/budgets/widgets/budgets_actions.dart';
|
||||||
|
import 'package:tunas/pages/budgets/widgets/month_distribution.dart';
|
||||||
|
|
||||||
class BudgetsPage extends StatelessWidget {
|
class BudgetsPage extends StatelessWidget {
|
||||||
const BudgetsPage({super.key});
|
const BudgetsPage({super.key});
|
||||||
@@ -14,6 +15,7 @@ class BudgetsPage extends StatelessWidget {
|
|||||||
child: const Column(
|
child: const Column(
|
||||||
children: [
|
children: [
|
||||||
BudgetsActions(),
|
BudgetsActions(),
|
||||||
|
MonthDistribution()
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
73
lib/pages/budgets/widgets/month_distribution.dart
Normal file
73
lib/pages/budgets/widgets/month_distribution.dart
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
import 'package:fl_chart/fl_chart.dart';
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:tunas/pages/common/titled_container.dart';
|
||||||
|
|
||||||
|
class MonthDistribution extends StatelessWidget {
|
||||||
|
const MonthDistribution({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Column(
|
||||||
|
children: [
|
||||||
|
TitledContainer(
|
||||||
|
title: 'Prepare',
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
Text('Money to spare: 2300 €'),
|
||||||
|
Text('Loyer'),
|
||||||
|
Slider(
|
||||||
|
min: 0,
|
||||||
|
max: 2300,
|
||||||
|
value: 200,
|
||||||
|
onChanged: (value) => {},
|
||||||
|
),
|
||||||
|
Text('Loyer'),
|
||||||
|
Slider(
|
||||||
|
min: 0,
|
||||||
|
max: 2300,
|
||||||
|
value: 200,
|
||||||
|
onChanged: (value) => {},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
TitledContainer(
|
||||||
|
title: 'Compare',
|
||||||
|
height: 500,
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Text('Budget'),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
IconButton(
|
||||||
|
onPressed: () => {},
|
||||||
|
icon: const Icon(Icons.skip_previous)
|
||||||
|
),
|
||||||
|
Text('Fev 2024'),
|
||||||
|
IconButton(
|
||||||
|
onPressed: () => {},
|
||||||
|
icon: const Icon(Icons.skip_next)
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,12 +3,35 @@ import 'package:flutter/material.dart';
|
|||||||
class TitledContainer extends StatelessWidget {
|
class TitledContainer extends StatelessWidget {
|
||||||
final String title;
|
final String title;
|
||||||
final Widget child;
|
final Widget child;
|
||||||
|
final Widget? action;
|
||||||
|
final double? height;
|
||||||
|
final double? width;
|
||||||
|
|
||||||
const TitledContainer({super.key, required this.title, required this.child});
|
const TitledContainer({super.key, required this.title, required this.child, this.action, this.height, this.width});
|
||||||
|
|
||||||
|
Widget _computeTitleRow() {
|
||||||
|
List<Widget> children = [];
|
||||||
|
children.add(Text(
|
||||||
|
title,
|
||||||
|
style: const TextStyle(
|
||||||
|
fontWeight: FontWeight.w300,
|
||||||
|
fontSize: 20,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
Widget? actionWidget = action;
|
||||||
|
if (actionWidget != null) {
|
||||||
|
children.add(actionWidget);
|
||||||
|
}
|
||||||
|
return Row(
|
||||||
|
children: children
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Container(
|
return Container(
|
||||||
|
height: height,
|
||||||
|
width: width,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Theme.of(context).colorScheme.primaryContainer,
|
color: Theme.of(context).colorScheme.primaryContainer,
|
||||||
borderRadius: BorderRadius.circular(15),
|
borderRadius: BorderRadius.circular(15),
|
||||||
@@ -36,13 +59,7 @@ class TitledContainer extends StatelessWidget {
|
|||||||
borderRadius: const BorderRadius.only(topLeft: Radius.circular(15), topRight: Radius.circular(15)),
|
borderRadius: const BorderRadius.only(topLeft: Radius.circular(15), topRight: Radius.circular(15)),
|
||||||
),
|
),
|
||||||
padding: const EdgeInsets.symmetric(vertical: 5, horizontal: 15),
|
padding: const EdgeInsets.symmetric(vertical: 5, horizontal: 15),
|
||||||
child: Text(
|
child: _computeTitleRow()
|
||||||
title,
|
|
||||||
style: const TextStyle(
|
|
||||||
fontWeight: FontWeight.w300,
|
|
||||||
fontSize: 20,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -2,28 +2,71 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:tunas/domains/account/account_bloc.dart';
|
import 'package:tunas/domains/account/account_bloc.dart';
|
||||||
import 'package:tunas/pages/common/titled_container.dart';
|
import 'package:tunas/pages/common/titled_container.dart';
|
||||||
|
import 'package:tunas/repositories/metadata/models/account.dart';
|
||||||
|
|
||||||
class AccountSettings extends StatelessWidget {
|
class AccountSettings extends StatelessWidget {
|
||||||
const AccountSettings({super.key});
|
const AccountSettings({super.key});
|
||||||
|
|
||||||
List<Widget> _computeCategoryList(List<String> subAccounts) {
|
List<Widget> _computeCategoryList(BuildContext context, List<Account> accounts) {
|
||||||
return subAccounts.map((subAccount) => Row(
|
return accounts.map((account) => Row(
|
||||||
children: [
|
children: [
|
||||||
Text(subAccount),
|
IconButton(
|
||||||
|
onPressed: () {},
|
||||||
|
icon: const Icon(Icons.palette),
|
||||||
|
color: account.rgbToColor(),
|
||||||
|
),
|
||||||
|
IconButton(
|
||||||
|
onPressed: () => context.read<AccountBloc>().add(AccountEditSaving(account, !account.saving)),
|
||||||
|
icon: const Icon(Icons.savings),
|
||||||
|
color: account.saving ? Theme.of(context).colorScheme.primary : Theme.of(context).colorScheme.error,
|
||||||
|
),
|
||||||
|
Container(width: 5),
|
||||||
|
Expanded(
|
||||||
|
child: Text(account.label)
|
||||||
|
),
|
||||||
|
IconButton(
|
||||||
|
onPressed: () {},
|
||||||
|
icon: const Icon(Icons.edit),
|
||||||
|
),
|
||||||
|
IconButton(
|
||||||
|
onPressed: () => context.read<AccountBloc>().add(AccountRemove(account)),
|
||||||
|
icon: const Icon(Icons.delete),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
)).toList();
|
)).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocBuilder<AccountBloc, AccountState>(
|
return BlocConsumer<AccountBloc, AccountState>(
|
||||||
|
listener: (context, state) {
|
||||||
|
if (state is AccountRemoveSucess) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
const SnackBar(
|
||||||
|
backgroundColor: Colors.green,
|
||||||
|
content: Text('Account succesfuly removed !'),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
} else if (state is AccountRemoveFail) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
const SnackBar(
|
||||||
|
backgroundColor: Colors.red,
|
||||||
|
content: Text('Cannot remove account. Still present on some transactions.'),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
builder: (context, state) => TitledContainer(
|
builder: (context, state) => TitledContainer(
|
||||||
title: "Accounts",
|
title: "Accounts",
|
||||||
|
action: IconButton(
|
||||||
|
onPressed: () => context.read<AccountBloc>().add(AccountAdd()),
|
||||||
|
icon: const Icon(Icons.add),
|
||||||
|
),
|
||||||
child: SingleChildScrollView(
|
child: SingleChildScrollView(
|
||||||
scrollDirection: Axis.vertical,
|
scrollDirection: Axis.vertical,
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: _computeCategoryList(state.accounts.map((account) => account.label).toList()),
|
children: _computeCategoryList(context, state.accounts),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ class CategoriesSettings extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
IconButton(
|
IconButton(
|
||||||
onPressed: () {},
|
onPressed: () {},
|
||||||
icon: const Icon(Icons.savings),
|
icon: const Icon(Icons.swap_horiz),
|
||||||
color: category.saving ? Theme.of(context).colorScheme.primary : Theme.of(context).colorScheme.error,
|
color: category.transfert ? Theme.of(context).colorScheme.primary : Theme.of(context).colorScheme.error,
|
||||||
),
|
),
|
||||||
IconButton(
|
IconButton(
|
||||||
onPressed: () {},
|
onPressed: () {},
|
||||||
|
|||||||
35
lib/pages/transactions/widgets/category_filter.dart
Normal file
35
lib/pages/transactions/widgets/category_filter.dart
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:tunas/domains/category/category_bloc.dart';
|
||||||
|
import 'package:tunas/domains/transaction/transaction_bloc.dart';
|
||||||
|
import 'package:tunas/repositories/metadata/models/category.dart' as tunas_category;
|
||||||
|
|
||||||
|
class CategoryFilter extends StatelessWidget {
|
||||||
|
const CategoryFilter({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final categoryState = context.watch<CategoryBloc>().state;
|
||||||
|
return BlocBuilder<TransactionBloc, TransactionState>(
|
||||||
|
buildWhen: (previous, current) => previous.categoryFilter != current.categoryFilter,
|
||||||
|
builder: (context, state) => SizedBox(
|
||||||
|
width: 500,
|
||||||
|
child: DropdownButtonFormField<tunas_category.Category>(
|
||||||
|
value: state.categoryFilter,
|
||||||
|
onChanged: (value) => context.read<TransactionBloc>().add(TransactionFilterCategory(value!)),
|
||||||
|
items: categoryState.categories.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 TransactionFilterCategory(null)),
|
||||||
|
),
|
||||||
|
hintText: 'Category',
|
||||||
|
border: OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.circular(5),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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:tunas/domains/transaction/transaction_bloc.dart';
|
import 'package:tunas/domains/transaction/transaction_bloc.dart';
|
||||||
|
import 'package:tunas/pages/transactions/widgets/category_filter.dart';
|
||||||
import 'package:tunas/pages/transactions/widgets/transaction_add_dialog.dart';
|
import 'package:tunas/pages/transactions/widgets/transaction_add_dialog.dart';
|
||||||
|
|
||||||
class TransactionsActions extends StatelessWidget {
|
class TransactionsActions extends StatelessWidget {
|
||||||
@@ -22,6 +23,7 @@ class TransactionsActions extends StatelessWidget {
|
|||||||
fontSize: 35,
|
fontSize: 35,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
CategoryFilter(),
|
||||||
IconButton(
|
IconButton(
|
||||||
onPressed: () => TransactionAddDialog.show(context, null),
|
onPressed: () => TransactionAddDialog.show(context, null),
|
||||||
icon: const Icon(
|
icon: const Icon(
|
||||||
|
|||||||
@@ -9,13 +9,13 @@ class TransactionsList extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocBuilder<TransactionBloc, TransactionState>(
|
return BlocBuilder<TransactionBloc, TransactionState>(
|
||||||
buildWhen: (previous, current) => previous.transactionsLines != current.transactionsLines,
|
buildWhen: (previous, current) => previous.transactionsLinesFiltered != current.transactionsLinesFiltered,
|
||||||
builder: (context, state) => Expanded(
|
builder: (context, state) => Expanded(
|
||||||
child: ListView.builder(
|
child: ListView.builder(
|
||||||
itemCount: state.transactionsLines.length,
|
itemCount: state.transactionsLinesFiltered.length,
|
||||||
itemBuilder: (context, index) => TransactionLine(
|
itemBuilder: (context, index) => TransactionLine(
|
||||||
transaction: state.transactionsLines[index].transaction,
|
transaction: state.transactionsLinesFiltered[index].transaction,
|
||||||
subTotal: state.transactionsLines[index].subTotal
|
subTotal: state.transactionsLinesFiltered[index].subTotal
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -24,6 +24,10 @@ class MetadataRepository {
|
|||||||
return _budgetController.asBroadcastStream();
|
return _budgetController.asBroadcastStream();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<Account> getAccounts() {
|
||||||
|
return _accountController.value;
|
||||||
|
}
|
||||||
|
|
||||||
Stream<List<Account>> getAccountsStream() {
|
Stream<List<Account>> getAccountsStream() {
|
||||||
return _accountController.asBroadcastStream();
|
return _accountController.asBroadcastStream();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,13 +4,13 @@ class Category {
|
|||||||
String label;
|
String label;
|
||||||
String color;
|
String color;
|
||||||
bool essential;
|
bool essential;
|
||||||
bool saving;
|
bool transfert;
|
||||||
|
|
||||||
Category({
|
Category({
|
||||||
this.label = '',
|
this.label = '',
|
||||||
this.color = '',
|
this.color = '',
|
||||||
this.essential = false,
|
this.essential = false,
|
||||||
this.saving = false,
|
this.transfert = false,
|
||||||
});
|
});
|
||||||
|
|
||||||
factory Category.fromJson(Map<String, dynamic> json) {
|
factory Category.fromJson(Map<String, dynamic> json) {
|
||||||
@@ -18,7 +18,7 @@ class Category {
|
|||||||
label: json['label'],
|
label: json['label'],
|
||||||
color: json['color'],
|
color: json['color'],
|
||||||
essential: bool.parse(json['essential']),
|
essential: bool.parse(json['essential']),
|
||||||
saving: bool.parse(json['saving']),
|
transfert: bool.parse(json['transfert']),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -26,7 +26,7 @@ class Category {
|
|||||||
'label': label,
|
'label': label,
|
||||||
'color': color,
|
'color': color,
|
||||||
'essential': essential.toString(),
|
'essential': essential.toString(),
|
||||||
'saving': saving.toString(),
|
'transfert': transfert.toString(),
|
||||||
};
|
};
|
||||||
|
|
||||||
Color rgbToColor() {
|
Color rgbToColor() {
|
||||||
|
|||||||
@@ -12,6 +12,10 @@ class TransactionsRepository {
|
|||||||
required jsonRepository,
|
required jsonRepository,
|
||||||
}) : _jsonRepository = jsonRepository;
|
}) : _jsonRepository = jsonRepository;
|
||||||
|
|
||||||
|
List<Transaction> getTransactions() {
|
||||||
|
return _transactionsController.value;
|
||||||
|
}
|
||||||
|
|
||||||
Stream<List<Transaction>> getTransactionsStream() {
|
Stream<List<Transaction>> getTransactionsStream() {
|
||||||
return _transactionsController.asBroadcastStream();
|
return _transactionsController.asBroadcastStream();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user