Allow deleting templates
This commit is contained in:
@@ -4,6 +4,7 @@ import 'package:get_it/get_it.dart';
|
||||
import 'package:okane/database/collections/account.dart';
|
||||
import 'package:okane/database/collections/beneficiary.dart';
|
||||
import 'package:okane/database/collections/expense_category.dart';
|
||||
import 'package:okane/database/collections/template.dart';
|
||||
import 'package:okane/database/collections/transaction.dart';
|
||||
import 'package:okane/database/database.dart';
|
||||
import 'package:okane/ui/state/core.dart';
|
||||
@@ -12,13 +13,18 @@ import 'package:okane/ui/utils.dart';
|
||||
import 'package:okane/ui/widgets/add_expense_category.dart';
|
||||
import 'package:searchfield/searchfield.dart';
|
||||
|
||||
typedef AddTransactionCallback = void Function(Transaction);
|
||||
|
||||
class AddTransactionWidget extends StatefulWidget {
|
||||
final VoidCallback onAdd;
|
||||
final AddTransactionCallback onAdd;
|
||||
|
||||
final Account activeAccountItem;
|
||||
|
||||
final TransactionTemplate? template;
|
||||
|
||||
const AddTransactionWidget({
|
||||
super.key,
|
||||
this.template,
|
||||
required this.activeAccountItem,
|
||||
required this.onAdd,
|
||||
});
|
||||
@@ -38,7 +44,26 @@ class _AddTransactionWidgetState extends State<AddTransactionWidget> {
|
||||
|
||||
TransactionDirection _selectedDirection = TransactionDirection.send;
|
||||
|
||||
ExpenseCategory? _expenseCategory = null;
|
||||
ExpenseCategory? _expenseCategory;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
if (widget.template != null) {
|
||||
_selectedDirection =
|
||||
widget.template!.amount > 0
|
||||
? TransactionDirection.receive
|
||||
: TransactionDirection.send;
|
||||
_amountTextController.text = widget.template!.amount.toString();
|
||||
_beneficiaryTextController.text =
|
||||
widget.template!.beneficiary.value!.name;
|
||||
_selectedBeneficiary = SearchFieldListItem(
|
||||
getBeneficiaryName(widget.template!.beneficiary.value!),
|
||||
item: widget.template!.beneficiary.value!,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String getBeneficiaryName(Beneficiary item) {
|
||||
return switch (item.type) {
|
||||
@@ -122,7 +147,7 @@ class _AddTransactionWidgetState extends State<AddTransactionWidget> {
|
||||
await upsertTransaction(otherTransaction);
|
||||
}
|
||||
|
||||
widget.onAdd();
|
||||
widget.onAdd(transaction);
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
Reference in New Issue
Block a user