complete category issue

This commit is contained in:
2025-03-20 18:21:48 +05:30
parent 7ab5c896f0
commit 6a10900f68
21 changed files with 1198 additions and 420 deletions

View File

@@ -6,6 +6,7 @@ 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/ProductCategoryModel.dart';
import 'package:grocery_app/src/data/product_category.dart';
import 'package:grocery_app/src/logic/provider/home_provider.dart';
@@ -33,6 +34,7 @@ class _FruitVeggieDetailState extends State<FruitVeggieDetail> {
final productProvider =
Provider.of<ProductProvider>(context, listen: false);
productProvider.getAllcategory(context);
productProvider.getCategoryByLevel();
productProvider.gettAllProduct(context, "", true, '');
});
@@ -84,16 +86,7 @@ class _FruitVeggieDetailState extends State<FruitVeggieDetail> {
),
),
actions: [
// Padding(
// padding: const EdgeInsets.only(right: 10),
// child: InkWell(
// onTap: () {},
// child: Icon(
// MdiIcons.magnify,
// size: 35,
// ),
// ),
// )
],
),
body: Padding(
@@ -465,108 +458,7 @@ 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);
@@ -590,8 +482,8 @@ class _FruitVeggieDetailState extends State<FruitVeggieDetail> {
),
);
} else {
final categories = [Datum(id: "all", name: "ALL")];
categories.addAll(provider.categoryList.cast<Datum>());
final categories = [DatumCategory(id: "all", name: "ALL")];
categories.addAll(provider.categoryList.cast<DatumCategory>());
return Container(
decoration: const BoxDecoration(color: Colors.white),
@@ -602,6 +494,8 @@ class _FruitVeggieDetailState extends State<FruitVeggieDetail> {
itemBuilder: (context, index) {
var category = categories[index];
return Padding(
padding: const EdgeInsets.only(bottom: 8),
child: InkWell(
@@ -637,47 +531,105 @@ class _FruitVeggieDetailState extends State<FruitVeggieDetail> {
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Column(
children: [
Center(
child: Container(
// decoration: BoxDecoration(
// color: activeIndexProvider.activeIndex ==
// index
// ? Colors.greenAccent.withOpacity(0.1)
// : APPCOLOR.bgGrey,
// borderRadius: BorderRadius.circular(5),
// ),
child: AppNetworkImage(
height: 30,
width: 50,
imageUrl: category.image ??
'https://i.pinimg.com/originals/a5/f3/5f/a5f35fb23e942809da3df91b23718e8d.png',
backGroundColor: APPCOLOR.bgGrey,
radius: 10,
if (category.name == "ALL") ...{
if (provider.categoriesss.isNotEmpty)
PopupMenuButton<ProductCategoryModel>(
onSelected: (ProductCategoryModel value) {
activeIndexProvider.setActiveIndex(0);
if (value.id == "all") {
provider.iscroll = true;
provider.products.clear();
provider.isLoadingg = false;
provider.hasMore = true;
provider.page = 1;
provider.gettAllProduct(
context, "", true, '');
provider.getAllcategory(context);
} else {
provider.categoryList.clear();
provider.getSubcategory(
context, value.id);
}
provider.setSelectedCategory(value);
},
itemBuilder: (BuildContext context) =>
provider.categoriesss
.map(
(category) => PopupMenuItem(
value: category,
child: Text(
category.name ?? "Unknown"),
),
)
.toList(),
child: Padding(
padding: const EdgeInsets.symmetric(
vertical: 10,
horizontal: 10,
),
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
SizedBox(
width: 20,
child: Text(
provider.selectedCategory?.name ??
"All",
maxLines: 1,
style: context.customMedium(
APPCOLOR.balck1A1A1A,
12,
),
),
),
Icon(
Icons.arrow_drop_down,
size: 20,
color: APPCOLOR.balck1A1A1A,
),
],
),
),
),
SizedBox(
height: 5,
),
Container(
width: 50,
child: Text(
category.name,
textAlign: TextAlign.center,
maxLines: 2,
overflow: TextOverflow.ellipsis,
style:
activeIndexProvider.activeIndex == index
? context.customExtraBold(
APPCOLOR.balck1A1A1A, 9)
: context.customMedium(
APPCOLOR.balck1A1A1A, 10),
} else ...{
Column(
children: [
Center(
child: Container(
child: AppNetworkImage(
height: 30,
width: 50,
imageUrl: category.image ??
'https://i.pinimg.com/originals/a5/f3/5f/a5f35fb23e942809da3df91b23718e8d.png',
backGroundColor: APPCOLOR.bgGrey,
radius: 10,
),
),
),
),
],
),
SizedBox(
height: 5,
),
Container(
width: 50,
child: Text(
category.name,
textAlign: TextAlign.center,
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: activeIndexProvider.activeIndex ==
index
? context.customExtraBold(
APPCOLOR.balck1A1A1A, 9)
: context.customMedium(
APPCOLOR.balck1A1A1A, 10),
),
),
],
),
},
SizedBox(
width: 5,
),