Fix adding a new beneficiary in the loan screen

This commit is contained in:
PapaTutuWawa 2025-05-12 22:22:01 +02:00
parent e0c16031ef
commit ba78685bfd

View File

@ -74,13 +74,54 @@ class AddBudgetState extends State<AddLoanPopup> {
children: [ children: [
OutlinedButton( OutlinedButton(
onPressed: () async { onPressed: () async {
if (_beneficiaryTextController.text.isEmpty) { final beneficiaryName = _beneficiaryTextController.text;
if (_selectedBeneficiary == null && beneficiaryName.isEmpty) {
return; return;
} }
final bloc = GetIt.I.get<CoreCubit>(); Beneficiary? beneficiary = _selectedBeneficiary?.item;
if (beneficiary == null ||
getBeneficiaryName(beneficiary) != beneficiaryName) {
// Add a new beneficiary, if none was selected
final result = await showDialog<bool>(
context: context,
builder:
(context) => AlertDialog(
title: Text(t.common.beneficiary.addBeneficiary.title),
content: Text(
t.common.beneficiary.addBeneficiary.body(name: beneficiaryName),
),
actions: [
TextButton(
style: TextButton.styleFrom(
textStyle: Theme.of(context).textTheme.labelLarge,
),
child: Text(t.modals.add),
onPressed: () => Navigator.of(context).pop(true),
),
TextButton(
style: TextButton.styleFrom(
textStyle: Theme.of(context).textTheme.labelLarge,
),
child: Text(t.modals.cancel),
onPressed: () => Navigator.of(context).pop(false),
),
],
),
);
if (result == null || !result) {
return;
}
beneficiary =
Beneficiary()
..name = beneficiaryName
..type = BeneficiaryType.other;
await upsertBeneficiary(beneficiary);
}
final loan = final loan =
Loan()..beneficiary.value = _selectedBeneficiary!.item; Loan()..beneficiary.value = beneficiary;
await upsertLoan(loan); await upsertLoan(loan);
widget.onDone(); widget.onDone();
}, },