added transaction snackbar message
This commit is contained in:
@@ -37,6 +37,7 @@ class TransactionBloc extends Bloc<TransactionEvent, TransactionState> {
|
|||||||
on<TransactionDeleteCurrent>(_onTransactionDeleteCurrent);
|
on<TransactionDeleteCurrent>(_onTransactionDeleteCurrent);
|
||||||
on<TransactionFilterCategory>(_onTransactionFilterCategory);
|
on<TransactionFilterCategory>(_onTransactionFilterCategory);
|
||||||
on<TransactionFilterAccount>(_onTransactionFilterAccount);
|
on<TransactionFilterAccount>(_onTransactionFilterAccount);
|
||||||
|
on<TransactionResetSnackBar>(_onTransactionResetSnackBar);
|
||||||
|
|
||||||
_transactionsRepository
|
_transactionsRepository
|
||||||
.getTransactionsStream()
|
.getTransactionsStream()
|
||||||
@@ -181,6 +182,9 @@ class TransactionBloc extends Bloc<TransactionEvent, TransactionState> {
|
|||||||
transactionsLinesFiltered: _applyFilters(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'} !',
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -231,6 +235,9 @@ class TransactionBloc extends Bloc<TransactionEvent, TransactionState> {
|
|||||||
transactionsLinesFiltered: _applyFilters(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 !',
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -296,4 +303,12 @@ class TransactionBloc extends Bloc<TransactionEvent, TransactionState> {
|
|||||||
|
|
||||||
return transactionsLinesFiltered;
|
return transactionsLinesFiltered;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FutureOr<void> _onTransactionResetSnackBar(TransactionResetSnackBar event, Emitter<TransactionState> emit) {
|
||||||
|
emit(state.copyWith(
|
||||||
|
showSnackBar: false,
|
||||||
|
snackBarIsError: false,
|
||||||
|
snackBarMessage: '',
|
||||||
|
));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -84,3 +84,7 @@ final class TransactionFilterAccount extends TransactionEvent {
|
|||||||
|
|
||||||
const TransactionFilterAccount(this.account);
|
const TransactionFilterAccount(this.account);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final class TransactionResetSnackBar extends TransactionEvent {
|
||||||
|
const TransactionResetSnackBar();
|
||||||
|
}
|
||||||
@@ -20,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>{},
|
||||||
@@ -36,6 +40,9 @@ final class TransactionState extends Equatable {
|
|||||||
this.currentTransaction,
|
this.currentTransaction,
|
||||||
this.categoryFilter,
|
this.categoryFilter,
|
||||||
this.accountFilter,
|
this.accountFilter,
|
||||||
|
this.showSnackBar = false,
|
||||||
|
this.snackBarMessage = '',
|
||||||
|
this.snackBarIsError = false,
|
||||||
});
|
});
|
||||||
|
|
||||||
TransactionState copyWith({
|
TransactionState copyWith({
|
||||||
@@ -54,6 +61,9 @@ final class TransactionState extends Equatable {
|
|||||||
Transaction? currentTransaction,
|
Transaction? currentTransaction,
|
||||||
Category? categoryFilter,
|
Category? categoryFilter,
|
||||||
Account? accountFilter,
|
Account? accountFilter,
|
||||||
|
bool? showSnackBar,
|
||||||
|
String? snackBarMessage,
|
||||||
|
bool? snackBarIsError,
|
||||||
}) {
|
}) {
|
||||||
return TransactionState(
|
return TransactionState(
|
||||||
globalTotal: globalTotal ?? this.globalTotal,
|
globalTotal: globalTotal ?? this.globalTotal,
|
||||||
@@ -71,6 +81,9 @@ final class TransactionState extends Equatable {
|
|||||||
currentTransaction: currentTransaction ?? this.currentTransaction,
|
currentTransaction: currentTransaction ?? this.currentTransaction,
|
||||||
categoryFilter: categoryFilter ?? this.categoryFilter,
|
categoryFilter: categoryFilter ?? this.categoryFilter,
|
||||||
accountFilter: accountFilter ?? this.accountFilter,
|
accountFilter: accountFilter ?? this.accountFilter,
|
||||||
|
showSnackBar: showSnackBar ?? this.showSnackBar,
|
||||||
|
snackBarMessage: snackBarMessage ?? this.snackBarMessage,
|
||||||
|
snackBarIsError: snackBarIsError ?? this.snackBarIsError,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,6 +102,9 @@ final class TransactionState extends Equatable {
|
|||||||
currentTransaction,
|
currentTransaction,
|
||||||
categoryFilter,
|
categoryFilter,
|
||||||
accountFilter,
|
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,11 +11,24 @@ 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,
|
padding: mediaQuery.padding,
|
||||||
child: const Column(
|
child: const Column(
|
||||||
children: [
|
children: [
|
||||||
@@ -22,7 +37,8 @@ class TransactionsPage extends StatelessWidget {
|
|||||||
TransactionsList(),
|
TransactionsList(),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
)
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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(),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user