feat: enhance product picker and improve error handling in inventory screen

This commit is contained in:
Nils-Johan Gynther
2026-04-25 07:47:35 +02:00
parent 5a85bd4526
commit 53afcc98a9
2 changed files with 31 additions and 9 deletions
@@ -57,16 +57,26 @@ class _CreateInventoryScreenState
final token = await ref.read(authStateProvider.future);
final api = ref.read(apiClientProvider);
final data = await api.getJson(ProductApiPaths.list, token: token);
final list = data is List<dynamic>
? data
: (data is Map<String, dynamic> && data['items'] is List<dynamic>)
? data['items'] as List<dynamic>
: const <dynamic>[];
if (mounted) {
setState(() {
_products = (data as List<dynamic>)
_products = list
.map((e) => e as Map<String, dynamic>)
.toList();
_loadingProducts = false;
});
}
} catch (_) {
} catch (e) {
if (mounted) setState(() => _loadingProducts = false);
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(mapErrorToUserMessage(e, context))),
);
}
}
}
@@ -147,7 +157,7 @@ class _CreateInventoryScreenState
final productOptions = sortedProducts
.map(
(p) => (
id: p['id'] as int,
id: (p['id'] as num).toInt(),
name: (p['canonicalName'] ?? p['name'] ?? '').toString(),
),
)