Resolve map problem.
This commit is contained in:
@@ -85,6 +85,18 @@ class AddExpenseDialog extends StatefulWidget {
|
||||
/// The expense to edit (null for new expense).
|
||||
final Expense? expenseToEdit;
|
||||
|
||||
/// Optional initial category for a new expense.
|
||||
final ExpenseCategory? initialCategory;
|
||||
|
||||
/// Optional initial amount for a new expense.
|
||||
final double? initialAmount;
|
||||
|
||||
/// Optional initial splits (userId -> amount) for a new expense.
|
||||
final Map<String, double>? initialSplits;
|
||||
|
||||
/// Optional initial description for a new expense.
|
||||
final String? initialDescription;
|
||||
|
||||
/// Creates an AddExpenseDialog.
|
||||
///
|
||||
/// [group] is the group for the expense.
|
||||
@@ -95,6 +107,10 @@ class AddExpenseDialog extends StatefulWidget {
|
||||
required this.group,
|
||||
required this.currentUser,
|
||||
this.expenseToEdit,
|
||||
this.initialCategory,
|
||||
this.initialAmount,
|
||||
this.initialSplits,
|
||||
this.initialDescription,
|
||||
});
|
||||
|
||||
@override
|
||||
@@ -146,7 +162,10 @@ class _AddExpenseDialogState extends State<AddExpenseDialog> {
|
||||
super.initState();
|
||||
// Initialize form fields and splits based on whether editing or creating
|
||||
_selectedDate = widget.expenseToEdit?.date ?? DateTime.now();
|
||||
_selectedCategory = widget.expenseToEdit?.category ?? ExpenseCategory.other;
|
||||
_selectedCategory =
|
||||
widget.expenseToEdit?.category ??
|
||||
widget.initialCategory ??
|
||||
ExpenseCategory.other;
|
||||
_selectedCurrency = widget.expenseToEdit?.currency ?? ExpenseCurrency.eur;
|
||||
_paidById = widget.expenseToEdit?.paidById ?? widget.currentUser.id;
|
||||
|
||||
@@ -159,9 +178,32 @@ class _AddExpenseDialogState extends State<AddExpenseDialog> {
|
||||
}
|
||||
_splitEqually = false;
|
||||
} else {
|
||||
// Creating: initialize splits for all group members
|
||||
for (final member in widget.group.members) {
|
||||
_splits[member.userId] = 0;
|
||||
// Creating: initialize splits
|
||||
if (widget.initialDescription != null) {
|
||||
_descriptionController.text = widget.initialDescription!;
|
||||
}
|
||||
|
||||
if (widget.initialAmount != null) {
|
||||
_amountController.text = widget.initialAmount.toString();
|
||||
}
|
||||
|
||||
if (widget.initialSplits != null) {
|
||||
_splits.addAll(widget.initialSplits!);
|
||||
// Fill remaining members with 0 if not in initialSplits
|
||||
for (final member in widget.group.members) {
|
||||
if (!_splits.containsKey(member.userId)) {
|
||||
_splits[member.userId] = 0;
|
||||
} else {
|
||||
// If we have specific splits, we probably aren't splitting equally by default logic
|
||||
// unless we want to force it. For reimbursement, we likely set exact amounts.
|
||||
_splitEqually = false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Default behavior: initialize splits for all group members
|
||||
for (final member in widget.group.members) {
|
||||
_splits[member.userId] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user