pagination
This commit is contained in:
@@ -16,15 +16,41 @@ import 'package:grocery_app/utils/extensions/extensions.dart';
|
||||
class ProductProvider extends ChangeNotifier {
|
||||
final _homeRepo = getIt<ProductRepo>();
|
||||
|
||||
bool isLoadingg = true;
|
||||
String searchValue = '';
|
||||
|
||||
bool isLoadingg = false;
|
||||
|
||||
List<Product> products = [];
|
||||
|
||||
Future<void> gettAllProduct(BuildContext context, String id) async {
|
||||
var data = {};
|
||||
int page = 1;
|
||||
final int limit = 8;
|
||||
|
||||
print("skdjhfgkf ${id}");
|
||||
bool hasMore = true;
|
||||
|
||||
bool iscroll = true;
|
||||
Future<void> gettAllProduct(
|
||||
BuildContext context, String id, bool status, String search) async {
|
||||
if (isLoadingg || !hasMore) return;
|
||||
print("kjldfgjklfjkdgjkhlfg");
|
||||
if (id.isNotEmpty) {
|
||||
products.clear();
|
||||
|
||||
hasMore = true;
|
||||
}
|
||||
|
||||
if (status) {
|
||||
isLoadingg = true;
|
||||
}
|
||||
;
|
||||
|
||||
notifyListeners();
|
||||
var data = {
|
||||
"page": page,
|
||||
"limit": limit,
|
||||
"minPrice": "",
|
||||
"minPrice": "",
|
||||
"search": search
|
||||
};
|
||||
var result = await _homeRepo.getAllProduct(data, context, id);
|
||||
return result.fold(
|
||||
(error) {
|
||||
@@ -32,13 +58,66 @@ class ProductProvider extends ChangeNotifier {
|
||||
notifyListeners();
|
||||
},
|
||||
(response) {
|
||||
products = response.data!;
|
||||
// products = response.data!;
|
||||
// page++;
|
||||
// print(
|
||||
// "jksdhfgkjdfkhjghkjdfhgkjdf ${response.data} ${response.data!.isNotEmpty}");
|
||||
// if (response.data != null && response.data!.isNotEmpty) {
|
||||
// products.addAll(response.data!);
|
||||
// // products = response.data!;
|
||||
// page++;
|
||||
// } else {
|
||||
// hasMore = false;
|
||||
// }
|
||||
|
||||
if (response.data != null && response.data!.isNotEmpty) {
|
||||
if (id.isNotEmpty) {
|
||||
products = response.data!;
|
||||
} else {
|
||||
products.addAll(response.data!);
|
||||
}
|
||||
page++;
|
||||
|
||||
if (response.data!.length < limit) {
|
||||
hasMore = false;
|
||||
}
|
||||
} else {
|
||||
hasMore = false;
|
||||
}
|
||||
|
||||
isLoadingg = false;
|
||||
notifyListeners();
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
bool isHomeLoadingg = false;
|
||||
|
||||
List<Product> homeproducts = [];
|
||||
|
||||
|
||||
Future<void> getHomeProduct(BuildContext context,String id, String search) async
|
||||
{
|
||||
isHomeLoadingg = true;
|
||||
|
||||
notifyListeners();
|
||||
var data = {"minPrice": "", "minPrice": "", "search": search};
|
||||
var result = await _homeRepo.getAllProduct(data, context,id);
|
||||
return result.fold(
|
||||
(error) {
|
||||
isLoadingg = false;
|
||||
notifyListeners();
|
||||
},
|
||||
(response)
|
||||
{
|
||||
homeproducts = response.data!;
|
||||
|
||||
isHomeLoadingg = false;
|
||||
notifyListeners();
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
ProductDetailsData productDetails = ProductDetailsData();
|
||||
bool isProductLoading = true;
|
||||
|
||||
@@ -68,11 +147,11 @@ class ProductProvider extends ChangeNotifier {
|
||||
|
||||
bool isBestdealingloading = true;
|
||||
|
||||
Future<void> getBestDealProduct(BuildContext context) async {
|
||||
isBestdealingloading = true;
|
||||
notifyListeners();
|
||||
var data = {};
|
||||
|
||||
Future<void> getBestDealProduct(BuildContext context,String search) async
|
||||
{
|
||||
isBestdealingloading = true;
|
||||
notifyListeners();
|
||||
var data = {"minPrice": "", "minPrice": "", "search": search};
|
||||
var result = await _homeRepo.getBestDealProduct(data, context);
|
||||
return result.fold(
|
||||
(error) {
|
||||
@@ -87,6 +166,9 @@ class ProductProvider extends ChangeNotifier {
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
List<Datum> categoryList = [];
|
||||
|
||||
bool iscategroyloading = true;
|
||||
@@ -254,7 +336,7 @@ class ProductProvider extends ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
// void toggleWishlist1(String productId)
|
||||
// void toggleWishlist1(String productId)
|
||||
// {
|
||||
// for (var product in products) {
|
||||
// if (product.id == productId) {
|
||||
@@ -396,8 +478,7 @@ class ProductProvider extends ChangeNotifier {
|
||||
notifyListeners(); // Update UI after adding to cart
|
||||
},
|
||||
);
|
||||
} catch (e)
|
||||
{
|
||||
} catch (e) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text("Product already added"),
|
||||
@@ -584,5 +665,14 @@ class ProductProvider extends ChangeNotifier {
|
||||
);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////// all carts////////////////////////
|
||||
///////////////////////////////////////////////////// all filter ////////////////////////
|
||||
|
||||
int _selectedIndex = 0;
|
||||
|
||||
int get selectedIndex => _selectedIndex;
|
||||
|
||||
void setSelectedIndex(BuildContext context, int index) {
|
||||
_selectedIndex = index;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user