fix(receipt-import): show explicit validation errors on create-and-select
This commit is contained in:
@@ -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<void> _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) {
|
||||
|
||||
Reference in New Issue
Block a user