diff --git a/lib/providers/product_provider.dart b/lib/providers/product_provider.dart index dcc35f1f623c2e900798bbb1c439154556798148..152ede38569909a8a4266b050e86bea1096dc8b5 100644 --- a/lib/providers/product_provider.dart +++ b/lib/providers/product_provider.dart @@ -4,14 +4,12 @@ import 'package:food_app/models/product_model.dart'; class ProductProvider with ChangeNotifier { List<ProductModel> herbsProductList = []; - List<ProductModel> freshProductList = []; - List<ProductModel> rootProductList = []; ProductModel productModel; fetchHerbsProductData() async { List<ProductModel> newList = []; QuerySnapshot value = - await FirebaseFirestore.instance.collection("HerbsProduct ").get(); + await FirebaseFirestore.instance.collection("HerbsProduct").get(); value.docs.forEach( (element) { productModel = ProductModel( @@ -30,12 +28,13 @@ class ProductProvider with ChangeNotifier { return herbsProductList; } + List<ProductModel> freshProductList = []; + fetchFreshProductData() async { List<ProductModel> newList = []; - QuerySnapshot value = await FirebaseFirestore.instance - .collection("FreshFruitsProduct ") - .get(); + QuerySnapshot value = + await FirebaseFirestore.instance.collection("FreshFruitsProduct").get(); value.docs.forEach( (element) { @@ -55,11 +54,13 @@ class ProductProvider with ChangeNotifier { return freshProductList; } + List<ProductModel> rootProductList = []; + fetchRootProductData() async { List<ProductModel> newList = []; QuerySnapshot value = await FirebaseFirestore.instance - .collection("RootVegetablesProduct ") + .collection("RootVegetablesProduct") .get(); value.docs.forEach( diff --git a/lib/screens/home_screens/home_screen.dart b/lib/screens/home_screens/home_screen.dart index 255d0b0f29e11017439ef621996d4c93dd674300..9e4a48461a90bc8c6d9612a2d4ce52209732bc48 100644 --- a/lib/screens/home_screens/home_screen.dart +++ b/lib/screens/home_screens/home_screen.dart @@ -37,27 +37,28 @@ class _HomeScreenState extends State<HomeScreen> { SingleChildScrollView( scrollDirection: Axis.horizontal, child: Row( - children: productProvider.getHerbsProductDataList.map((herbsProductData) { - return SingleProduct( - onTap: () { - Navigator.of(context).push( - MaterialPageRoute( - builder: (context) => ProductOverview( - productPrice: herbsProductData.productPrice, - productName: herbsProductData.productName, - productImage: - herbsProductData.productImage, + children: productProvider.getHerbsProductDataList.map( + (herbsProductData) { + return SingleProduct( + onTap: () { + Navigator.of(context).push( + MaterialPageRoute( + builder: (context) => ProductOverview( + productImage: herbsProductData.productImage, + productName: herbsProductData.productName, + productPrice: herbsProductData.productPrice, + + ), ), - ), - ); - }, - productPrice: herbsProductData.productPrice, - productImage: - herbsProductData.productImage, - productName: herbsProductData.productName, - ); - }, - ).toList(), + ); + }, + productImage: herbsProductData.productImage, + productName: herbsProductData.productName, + productPrice: herbsProductData.productPrice, + + ); + }, + ).toList(), // children: [ // ], @@ -87,27 +88,27 @@ class _HomeScreenState extends State<HomeScreen> { SingleChildScrollView( scrollDirection: Axis.horizontal, child: Row( - children: productProvider.getFreshProductDataList.map((freshProductData) { - return SingleProduct( - onTap: () { - Navigator.of(context).push( - MaterialPageRoute( - builder: (context) => ProductOverview( - productPrice: freshProductData.productPrice, - productName: freshProductData.productName, - productImage: - freshProductData.productImage, + children: productProvider.getFreshProductDataList.map( + (freshProductData) { + return SingleProduct( + onTap: () { + Navigator.of(context).push( + MaterialPageRoute( + builder: (context) => ProductOverview( + productImage: freshProductData.productImage, + productName: freshProductData.productName, + productPrice: freshProductData.productPrice, + ), ), - ), - ); - }, - productPrice: freshProductData.productPrice, - productImage: - freshProductData.productImage, - productName: freshProductData.productName, - ); - }, - ).toList(), + ); + }, + productImage: freshProductData.productImage, + productName: freshProductData.productName, + productPrice: freshProductData.productPrice, + + ); + }, + ).toList(), ), ), ], @@ -134,27 +135,27 @@ class _HomeScreenState extends State<HomeScreen> { SingleChildScrollView( scrollDirection: Axis.horizontal, child: Row( - children: productProvider.getRootProductDataList.map((rootProductData) { - return SingleProduct( - onTap: () { - Navigator.of(context).push( - MaterialPageRoute( - builder: (context) => ProductOverview( - productPrice: rootProductData.productPrice, - productName: rootProductData.productName, - productImage: - rootProductData.productImage, + children: productProvider.getRootProductDataList.map( + (rootProductData) { + return SingleProduct( + onTap: () { + Navigator.of(context).push( + MaterialPageRoute( + builder: (context) => ProductOverview( + productImage: rootProductData.productImage, + productName: rootProductData.productName, + productPrice: rootProductData.productPrice, + ), ), - ), - ); - }, - productPrice: rootProductData.productPrice, - productImage: - rootProductData.productImage, - productName: rootProductData.productName, - ); - }, - ).toList(), + ); + }, + productImage: rootProductData.productImage, + productName: rootProductData.productName, + productPrice: rootProductData.productPrice, + + ); + }, + ).toList(), ), ), ], @@ -165,6 +166,8 @@ class _HomeScreenState extends State<HomeScreen> { void initState() { ProductProvider productProvider = Provider.of(context, listen: false); productProvider.fetchHerbsProductData(); + productProvider.fetchFreshProductData(); + productProvider.fetchRootProductData(); super.initState(); }