From dd4c2fe8b302dcad93b172101b859965accb6124 Mon Sep 17 00:00:00 2001 From: Nils-Johan Gynther Date: Sat, 2 May 2026 20:00:41 +0200 Subject: [PATCH] fix(receipt-import): show explicit validation errors on create-and-select --- .../presentation/receipt_import_tab.dart | 32 +++++++++++++++---- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/flutter/lib/features/import/presentation/receipt_import_tab.dart b/flutter/lib/features/import/presentation/receipt_import_tab.dart index 90a7fa9c..7d9cdbf6 100644 --- a/flutter/lib/features/import/presentation/receipt_import_tab.dart +++ b/flutter/lib/features/import/presentation/receipt_import_tab.dart @@ -354,21 +354,39 @@ class _EditDialogState extends State<_EditDialog> { } bool get _canConfirm { - if (_entryMode == _ProductEntryMode.create) { - return !_isCreatingProduct && - _newProductNameCtrl.text.trim().isNotEmpty && - _newCategoryId != null; - } + if (_isCreatingProduct) return false; + if (_entryMode == _ProductEntryMode.create) return true; return _productId != null; } Future _confirm() async { if (_entryMode == _ProductEntryMode.create) { - if (widget.onCreate == null || _newCategoryId == null) return; + final trimmedName = _newProductNameCtrl.text.trim(); + if (trimmedName.isEmpty) { + ScaffoldMessenger.of(context).showSnackBar( + const SnackBar(content: Text('Ange ett produktnamn först.')), + ); + return; + } + + if (_newCategoryId == null) { + ScaffoldMessenger.of(context).showSnackBar( + const SnackBar(content: Text('Välj kategori innan du skapar produkten.')), + ); + return; + } + + if (widget.onCreate == null) { + ScaffoldMessenger.of(context).showSnackBar( + const SnackBar(content: Text('Produktskapande är inte tillgängligt i den här vyn.')), + ); + return; + } + setState(() => _isCreatingProduct = true); try { final newProduct = await widget.onCreate!( - _newProductNameCtrl.text.trim(), + trimmedName, _newCategoryId!, ); if (newProduct == null || !mounted) {