fixed category issue

This commit is contained in:
2025-03-04 16:52:39 +05:30
parent 401d82ac70
commit c3616afd86
5 changed files with 143 additions and 32 deletions

View File

@@ -6,6 +6,8 @@ import 'package:fluttertoast/fluttertoast.dart';
import 'package:go_router/go_router.dart';
import 'package:grocery_app/src/common_widget/network_image.dart';
import 'package:grocery_app/src/core/routes/routes.dart';
import 'package:grocery_app/src/data/product_category.dart';
import 'package:grocery_app/src/logic/provider/home_provider.dart';
import 'package:grocery_app/src/ui/data_notfound.dart';
import 'package:grocery_app/utils/constants/assets_constant.dart';
@@ -456,52 +458,162 @@ class _FruitVeggieDetailState extends State<FruitVeggieDetail> {
return discountPercentage.round();
}
// Widget filterCategory() {
// final activeIndexProvider = Provider.of<ProductProvider>(context);
// return Consumer<ProductProvider>(builder: (context, provider, child) {
// if (provider.iscategroyloading) {
// return Center(
// child: Container(
// width: 20,
// height: 20,
// decoration: BoxDecoration(
// color: APPCOLOR.bgGrey,
// borderRadius: BorderRadius.circular(10),
// border: Border.all(
// color: APPCOLOR.bgGrey,
// width: 1,
// )),
// child: const Center(
// child: CupertinoActivityIndicator(),
// ),
// ));
// } else if (provider.categoryList.isEmpty) {
// return SizedBox.shrink();
// } else {
// return Container(
// decoration: const BoxDecoration(color: Colors.white),
// width: 100,
// child: ListView.builder(
// itemCount: provider.categoryList.length,
// scrollDirection: Axis.vertical,
// itemBuilder: (context, index) {
// var category = provider.categoryList[index];
// return InkWell(
// onTap: () {
// provider.iscroll = true;
// provider.products.clear();
// provider.isLoadingg = false;
// provider.hasMore = true;
// provider.page = 1;
// provider.notifyListeners();
// 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,
// child: Column(
// children: [
// Row(
// children: [
// Expanded(
// child: Center(
// child: Container(
// decoration: BoxDecoration(
// color:
// activeIndexProvider.activeIndex == index
// ? Colors.greenAccent.withOpacity(0.1)
// : APPCOLOR.bgGrey,
// borderRadius: BorderRadius.circular(5),
// ),
// child: AppNetworkImage(
// height: 80,
// width: 80,
// imageUrl: category.image ??
// 'https://i.pinimg.com/originals/a5/f3/5f/a5f35fb23e942809da3df91b23718e8d.png',
// backGroundColor: APPCOLOR.bgGrey,
// radius: 10,
// ),
// ),
// ),
// ),
// Container(
// width: 3,
// height: 100,
// color: activeIndexProvider.activeIndex == index
// ? APPCOLOR.lightGreen
// : Colors.transparent,
// ),
// ],
// ),
// Text(
// category.name,
// textAlign: TextAlign.center,
// maxLines: 2,
// overflow: TextOverflow.ellipsis,
// style: activeIndexProvider.activeIndex == index
// ? context.customExtraBold(APPCOLOR.balck1A1A1A, 14)
// : context.customMedium(APPCOLOR.balck1A1A1A, 14),
// ),
// ],
// ),
// ),
// );
// },
// ),
// );
// }
// });
// }
Widget filterCategory() {
final activeIndexProvider = Provider.of<ProductProvider>(context);
return Consumer<ProductProvider>(builder: (context, provider, child) {
if (provider.iscategroyloading) {
return Center(
child: Container(
width: 20,
height: 20,
decoration: BoxDecoration(
child: Container(
width: 20,
height: 20,
decoration: BoxDecoration(
color: APPCOLOR.bgGrey,
borderRadius: BorderRadius.circular(10),
border: Border.all(
color: APPCOLOR.bgGrey,
width: 1,
)),
child: const Center(
child: CupertinoActivityIndicator(),
),
),
child: const Center(
child: CupertinoActivityIndicator(),
),
),
));
} else if (provider.categoryList.isEmpty) {
return SizedBox.shrink();
);
} else {
// Add "All" category at the beginning
final categories = [Datum(id: "all", name: "ALL")];
categories.addAll(provider.categoryList.cast<Datum>());
return Container(
decoration: const BoxDecoration(color: Colors.white),
width: 100,
child: ListView.builder(
itemCount: provider.categoryList.length,
itemCount: categories.length,
scrollDirection: Axis.vertical,
itemBuilder: (context, index) {
var category = provider.categoryList[index];
var category = categories[index];
return InkWell(
onTap: () {
provider.iscroll = true;
provider.products.clear(); // Clear existing products
provider.products.clear();
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, '');
provider.page = 1;
provider.notifyListeners();
if (category.id == "all") {
provider.gettAllProduct(context, "", true, '');
} else {
// Load filtered products
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,