pagination
This commit is contained in:
@@ -21,14 +21,36 @@ class FruitVeggieDetail extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _FruitVeggieDetailState extends State<FruitVeggieDetail> {
|
||||
final ScrollController _scrollController = ScrollController();
|
||||
@override
|
||||
void initState() {
|
||||
Provider.of<ProductProvider>(context, listen: false)
|
||||
.getAllcategory(context);
|
||||
// Ensuring the context is available before accessing the provider
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
final productProvider =
|
||||
Provider.of<ProductProvider>(context, listen: false);
|
||||
productProvider.getAllcategory(context);
|
||||
|
||||
productProvider.gettAllProduct(context, "", true, '');
|
||||
});
|
||||
|
||||
_scrollController.addListener(() {
|
||||
if (_scrollController.position.pixels ==
|
||||
_scrollController.position.maxScrollExtent) {
|
||||
final productProvider =
|
||||
Provider.of<ProductProvider>(context, listen: false);
|
||||
productProvider.gettAllProduct(context, "", false, '');
|
||||
}
|
||||
});
|
||||
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_scrollController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
@@ -41,8 +63,6 @@ class _FruitVeggieDetailState extends State<FruitVeggieDetail> {
|
||||
width: 20,
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
Provider.of<ProductProvider>(context, listen: false)
|
||||
.gettAllProduct(context, "");
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: SvgPicture.asset(
|
||||
@@ -60,16 +80,16 @@ class _FruitVeggieDetailState extends State<FruitVeggieDetail> {
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(right: 10),
|
||||
child: InkWell(
|
||||
onTap: () {},
|
||||
child: Icon(
|
||||
MdiIcons.magnify,
|
||||
size: 35,
|
||||
),
|
||||
),
|
||||
)
|
||||
// Padding(
|
||||
// padding: const EdgeInsets.only(right: 10),
|
||||
// child: InkWell(
|
||||
// onTap: () {},
|
||||
// child: Icon(
|
||||
// MdiIcons.magnify,
|
||||
// size: 35,
|
||||
// ),
|
||||
// ),
|
||||
// )
|
||||
],
|
||||
),
|
||||
body: Row(
|
||||
@@ -114,7 +134,11 @@ class _FruitVeggieDetailState extends State<FruitVeggieDetail> {
|
||||
final itemHeight = itemWidth * 1.5;
|
||||
|
||||
return GridView.builder(
|
||||
itemCount: provider.products.length,
|
||||
controller: _scrollController,
|
||||
// itemCount: provider.products.length,
|
||||
|
||||
itemCount:
|
||||
provider.products.length + (provider.hasMore ? 1 : 0),
|
||||
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: 2,
|
||||
childAspectRatio: itemWidth / itemHeight,
|
||||
@@ -122,8 +146,30 @@ class _FruitVeggieDetailState extends State<FruitVeggieDetail> {
|
||||
mainAxisSpacing: 10,
|
||||
),
|
||||
itemBuilder: (context, index) {
|
||||
if (index == provider.products.length) {
|
||||
return SizedBox.shrink();
|
||||
// return Center(
|
||||
// child: Padding(
|
||||
// padding: const EdgeInsets.only(left: 120),
|
||||
// child: Center(
|
||||
// child: Container(
|
||||
// width: 30,
|
||||
// height: 30,
|
||||
// decoration: BoxDecoration(
|
||||
// color: Colors.transparent,
|
||||
// borderRadius: BorderRadius.circular(20),
|
||||
// border: Border.all(
|
||||
// color: APPCOLOR.bgGrey,
|
||||
// width: 1,
|
||||
// )),
|
||||
// child: const Center(
|
||||
// child: CupertinoActivityIndicator(),
|
||||
// ),
|
||||
// )),
|
||||
// )
|
||||
// ); // Show loader when fetching more data
|
||||
}
|
||||
var product = provider.products[index];
|
||||
|
||||
return InkWell(
|
||||
onTap: () {
|
||||
context.push(MyRoutes.PRODUCTDETAILS,
|
||||
@@ -425,9 +471,20 @@ class _FruitVeggieDetailState extends State<FruitVeggieDetail> {
|
||||
var category = provider.categoryList[index];
|
||||
return InkWell(
|
||||
onTap: () {
|
||||
provider.isLoadingg = true;
|
||||
provider.gettAllProduct(context, "/category/${category.id}");
|
||||
provider.iscroll = true;
|
||||
provider.products.clear(); // Clear existing products
|
||||
provider.isLoadingg = false;
|
||||
provider.hasMore = true;
|
||||
provider.page = 1; // Reset page for new category
|
||||
provider
|
||||
.notifyListeners(); // Notify listeners before fetching data
|
||||
provider.gettAllProduct(
|
||||
context, "/category/${category.id}", true, '');
|
||||
activeIndexProvider.setActiveIndex(index);
|
||||
// provider.isLoadingg = false;
|
||||
// provider.hasMore = false;
|
||||
// provider.gettAllProduct(context, "/category/${category.id}");
|
||||
// activeIndexProvider.setActiveIndex(index);
|
||||
},
|
||||
child: SizedBox(
|
||||
height: 150,
|
||||
|
||||
Reference in New Issue
Block a user