Fix adding a new beneficiary in the loan screen
This commit is contained in:
parent
e0c16031ef
commit
ba78685bfd
@ -74,13 +74,54 @@ class AddBudgetState extends State<AddLoanPopup> {
|
||||
children: [
|
||||
OutlinedButton(
|
||||
onPressed: () async {
|
||||
if (_beneficiaryTextController.text.isEmpty) {
|
||||
final beneficiaryName = _beneficiaryTextController.text;
|
||||
if (_selectedBeneficiary == null && beneficiaryName.isEmpty) {
|
||||
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 =
|
||||
Loan()..beneficiary.value = _selectedBeneficiary!.item;
|
||||
Loan()..beneficiary.value = beneficiary;
|
||||
await upsertLoan(loan);
|
||||
widget.onDone();
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user