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 {
|
bool get _canConfirm {
|
||||||
if (_entryMode == _ProductEntryMode.create) {
|
if (_isCreatingProduct) return false;
|
||||||
return !_isCreatingProduct &&
|
if (_entryMode == _ProductEntryMode.create) return true;
|
||||||
_newProductNameCtrl.text.trim().isNotEmpty &&
|
|
||||||
_newCategoryId != null;
|
|
||||||
}
|
|
||||||
return _productId != null;
|
return _productId != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _confirm() async {
|
Future<void> _confirm() async {
|
||||||
if (_entryMode == _ProductEntryMode.create) {
|
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);
|
setState(() => _isCreatingProduct = true);
|
||||||
try {
|
try {
|
||||||
final newProduct = await widget.onCreate!(
|
final newProduct = await widget.onCreate!(
|
||||||
_newProductNameCtrl.text.trim(),
|
trimmedName,
|
||||||
_newCategoryId!,
|
_newCategoryId!,
|
||||||
);
|
);
|
||||||
if (newProduct == null || !mounted) {
|
if (newProduct == null || !mounted) {
|
||||||
|
|||||||
Reference in New Issue
Block a user