feat: enhance product picker and improve error handling in inventory screen
This commit is contained in:
@@ -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(),
|
||||
),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user