fix(receipt-import): show create-product errors in modal dialog
This commit is contained in:
@@ -363,23 +363,17 @@ class _EditDialogState extends State<_EditDialog> {
|
|||||||
if (_entryMode == _ProductEntryMode.create) {
|
if (_entryMode == _ProductEntryMode.create) {
|
||||||
final trimmedName = _newProductNameCtrl.text.trim();
|
final trimmedName = _newProductNameCtrl.text.trim();
|
||||||
if (trimmedName.isEmpty) {
|
if (trimmedName.isEmpty) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
showGlobalErrorDialog(context, 'Ange ett produktnamn först.');
|
||||||
const SnackBar(content: Text('Ange ett produktnamn först.')),
|
|
||||||
);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_newCategoryId == null) {
|
if (_newCategoryId == null) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
showGlobalErrorDialog(context, 'Välj kategori innan du skapar produkten.');
|
||||||
const SnackBar(content: Text('Välj kategori innan du skapar produkten.')),
|
|
||||||
);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (widget.onCreate == null) {
|
if (widget.onCreate == null) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
showGlobalErrorDialog(context, 'Produktskapande är inte tillgängligt i den här vyn.');
|
||||||
const SnackBar(content: Text('Produktskapande är inte tillgängligt i den här vyn.')),
|
|
||||||
);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -391,11 +385,7 @@ class _EditDialogState extends State<_EditDialog> {
|
|||||||
);
|
);
|
||||||
if (newProduct == null || !mounted) {
|
if (newProduct == null || !mounted) {
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
showGlobalErrorDialog(context, 'Kunde inte skapa produkten. Försök igen.');
|
||||||
const SnackBar(
|
|
||||||
content: Text('Kunde inte skapa produkten. Försök igen.'),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -409,24 +399,17 @@ class _EditDialogState extends State<_EditDialog> {
|
|||||||
_productCategorySource = _newCategorySource ?? CategorySelectionSource.manual;
|
_productCategorySource = _newCategorySource ?? CategorySelectionSource.manual;
|
||||||
} on ApiException catch (e) {
|
} on ApiException catch (e) {
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
showGlobalErrorDialog(
|
||||||
SnackBar(
|
context,
|
||||||
content: Text(
|
e.message.trim().isEmpty
|
||||||
e.message.trim().isEmpty
|
? 'Kunde inte skapa produkten. Försök igen.'
|
||||||
? 'Kunde inte skapa produkten. Försök igen.'
|
: e.message,
|
||||||
: e.message,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
showGlobalErrorDialog(context, 'Kunde inte skapa produkten. Försök igen.');
|
||||||
const SnackBar(
|
|
||||||
content: Text('Kunde inte skapa produkten. Försök igen.'),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
Reference in New Issue
Block a user