Skip to content
Snippets Groups Projects
Commit 7d6d6a6e authored by Harshil Patel's avatar Harshil Patel
Browse files

"Product model method in provider"

parent eee5a88c
No related branches found
No related tags found
1 merge request!3Main product
...@@ -4,20 +4,26 @@ import 'package:flutter/cupertino.dart'; ...@@ -4,20 +4,26 @@ import 'package:flutter/cupertino.dart';
import 'package:food_app/models/product_model.dart'; import 'package:food_app/models/product_model.dart';
class ProductProvider with ChangeNotifier { class ProductProvider with ChangeNotifier {
List<ProductModel> herbsProductList = [];
ProductModel productModel; ProductModel productModel;
productModels(QueryDocumentSnapshot element) {
productModel = ProductModel(
productImage: element.get("productImage"),
productName: element.get("productName"),
productPrice: element.get("productPrice"),
);
}
// Display Herbs Drawer
List<ProductModel> herbsProductList = [];
fetchHerbsProductData() async { fetchHerbsProductData() async {
List<ProductModel> newList = []; List<ProductModel> newList = [];
QuerySnapshot value = QuerySnapshot value =
await FirebaseFirestore.instance.collection("HerbsProduct ").get(); await FirebaseFirestore.instance.collection("HerbsProduct ").get();
value.docs.forEach( value.docs.forEach(
(element) { (element) {
productModel = ProductModel( productModels(element);
productImage: element.get("productImage"),
productName: element.get("productName"),
productPrice: element.get("productPrice"),
);
newList.add(productModel); newList.add(productModel);
}, },
); );
...@@ -29,22 +35,18 @@ class ProductProvider with ChangeNotifier { ...@@ -29,22 +35,18 @@ class ProductProvider with ChangeNotifier {
return herbsProductList; return herbsProductList;
} }
// Display Fresh Drawer
List<ProductModel> freshProductList = []; List<ProductModel> freshProductList = [];
fetchFreshProductData() async { fetchFreshProductData() async {
List<ProductModel> newList = []; List<ProductModel> newList = [];
QuerySnapshot value = await FirebaseFirestore.instance QuerySnapshot value =
.collection("FreshFruitsProduct") await FirebaseFirestore.instance.collection("FreshFruitsProduct").get();
.get();
value.docs.forEach( value.docs.forEach(
(element) { (element) {
productModel = ProductModel( productModels(element);
productImage: element.get("productImage"),
productName: element.get("productName"),
productPrice: element.get("productPrice"),
);
newList.add(productModel); newList.add(productModel);
}, },
); );
...@@ -56,6 +58,7 @@ class ProductProvider with ChangeNotifier { ...@@ -56,6 +58,7 @@ class ProductProvider with ChangeNotifier {
return freshProductList; return freshProductList;
} }
// Display Root Drawer
List<ProductModel> rootProductList = []; List<ProductModel> rootProductList = [];
fetchRootProductData() async { fetchRootProductData() async {
...@@ -67,11 +70,7 @@ class ProductProvider with ChangeNotifier { ...@@ -67,11 +70,7 @@ class ProductProvider with ChangeNotifier {
value.docs.forEach( value.docs.forEach(
(element) { (element) {
productModel = ProductModel( productModels(element);
productImage: element.get("productImage"),
productName: element.get("productName"),
productPrice: element.get("productPrice"),
);
newList.add(productModel); newList.add(productModel);
}, },
); );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment