refactor(receipt-import): streamline category tree loading and enhance error handling

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
Nils-Johan Gynther
2026-05-03 15:47:35 +02:00
parent 046dad870f
commit 5864a6f111
3 changed files with 145 additions and 58 deletions
@@ -17,7 +17,7 @@ class EditDialog extends StatefulWidget {
final ItemEdit current;
final List<ProductOption> products;
final List<AdminCategoryNode> categoryTree;
final Future<ProductOption?> Function(String name, int categoryId)? onCreate;
final Future<ProductOption?> Function(String name, int? categoryId)? onCreate;
final ImportProductEntryMode? initialEntryMode;
const EditDialog({
@@ -212,10 +212,6 @@ class _EditDialogState extends State<EditDialog> {
showGlobalErrorDialog(context, 'Ange ett produktnamn först.');
return;
}
if (_newCategoryId == null) {
showGlobalErrorDialog(context, 'Välj kategori innan du skapar produkten.');
return;
}
if (widget.onCreate == null) {
showGlobalErrorDialog(context, 'Produktskapande är inte tillgängligt i den här vyn.');
return;
@@ -223,7 +219,7 @@ class _EditDialogState extends State<EditDialog> {
setState(() => _isCreatingProduct = true);
try {
final newProduct = await widget.onCreate!(trimmedName, _newCategoryId!);
final newProduct = await widget.onCreate!(trimmedName, _newCategoryId);
if (newProduct == null || !mounted) {
if (mounted) {
showGlobalErrorDialog(context, 'Kunde inte skapa produkten. Försök igen.');