diff --git a/lib/Views/demande_sortie_personnelle_page.dart b/lib/Views/demande_sortie_personnelle_page.dart index 8352ec2..65d5688 100644 --- a/lib/Views/demande_sortie_personnelle_page.dart +++ b/lib/Views/demande_sortie_personnelle_page.dart @@ -124,17 +124,30 @@ class _DemandeSortiePersonnellePageState try { final products = await _database.getProducts(); setState(() { - _products = products - .where((p) => - (p.stock ?? 0) > 0 && - p.pointDeVenteId == _userController.pointDeVenteId) - .toList(); + _products = products.where((p) { + // Check stock availability + print("point de vente id: ${_userController.pointDeVenteId}"); + bool hasStock = _userController.pointDeVenteId == 0 + ? (p.stock ?? 0) > 0 + : (p.stock ?? 0) > 0 && + p.pointDeVenteId == _userController.pointDeVenteId; + return hasStock; + }).toList(); + + // Setting filtered products _filteredProducts = _products; + + // End loading state _isLoading = false; }); + + // Start the animation _animationController.forward(); } catch (e) { - setState(() => _isLoading = false); + // Handle any errors + setState(() { + _isLoading = false; + }); _showErrorSnackbar('Impossible de charger les produits: $e'); } }