From f1abe0e17908ad431631fd9ac11faf2900c133c6 Mon Sep 17 00:00:00 2001 From: ram-flutterdeveloper Date: Sun, 11 May 2025 09:25:49 +0530 Subject: [PATCH] final category issue fixed --- .DS_Store | Bin 10244 -> 10244 bytes .dart_tool/dartpad/web_plugin_registrant.dart | 38 + .dart_tool/package_config.json | 1127 +++++++++++++++++ .dart_tool/package_config_subset | 745 +++++++++++ .dart_tool/version | 1 + .flutter-plugins | 63 + .flutter-plugins-dependencies | 1 + lib/src/logic/provider/home_provider.dart | 56 +- lib/src/logic/repo/product_repo.dart | 5 +- lib/src/logic/services/home_locator.dart | 17 +- .../ui/fruitvegidetail/category_product.dart | 458 +++---- .../fruitvegidetail/fruit_veggie_detail.dart | 23 +- lib/src/ui/home/home_screen.dart | 2 +- 13 files changed, 2225 insertions(+), 311 deletions(-) create mode 100644 .dart_tool/dartpad/web_plugin_registrant.dart create mode 100644 .dart_tool/package_config.json create mode 100644 .dart_tool/package_config_subset create mode 100644 .dart_tool/version create mode 100644 .flutter-plugins create mode 100644 .flutter-plugins-dependencies diff --git a/.DS_Store b/.DS_Store index 54d0adb3dec0b7a189dcdf3f8e0d6c71d585047d..0456c3159b5872244be4491ba5179ff8456d8c28 100644 GIT binary patch delta 78 zcmZn(XbITBCp!6{V5zXNg^`YesYR`hLbbWMfsTT?k-=n7A>+-bL~Xe?vng<}5>RE$ F1ORN^6<`1W delta 42 ncmZn(XbITBC(5{Ea)Ef^ getAllcategory(BuildContext context) async { var data = {}; - var result = await _homeRepo.getAllcategory(data, context); - return result.fold( - (error) { - print("djhgfjdfhjg ${error}"); - iscategroyloading = false; - notifyListeners(); - }, - (response) { - print("jdshfjghdhfjhgjd"); - - categoryList = response.data!; - iscategroyloading = false; - notifyListeners(); - }, - ); - } - - Future getSubcategory(BuildContext context, String? id) async { - var data = {"parentId": id}; - - print("kdjhgkjfkjgkj ${id}"); - var result = await _homeRepo.getSubcategory(data, context); return result.fold( (error) { - print("djhgfjdfhjg ${error}"); iscategroyloading = false; notifyListeners(); }, (response) { - print("dsfdgdfgfhfghjghjghjghjhkghj"); categoryList = response!; iscategroyloading = false; notifyListeners(); @@ -279,10 +255,31 @@ class ProductProvider extends ChangeNotifier { ); } + // Future getSubcategory(BuildContext context, String? id) async { + // var data = {"parentId": id}; + + // var result = await _homeRepo.getSubcategory(data, context); + // return result.fold( + // (error) { + // print("djhgfjdfhjg ${error}"); + // subCategoryloading = false; + // notifyListeners(); + // }, + // (response) { + // print("dsfdgdfgfhfghjghjghjghjhkghj"); + // categoryList = response!; + // subCategoryloading = false; + // notifyListeners(); + // }, + // ); + // } + List categoriesss = []; ProductCategoryModel? selectedCategory; + bool subCategoryloading = true; + Future getCategoryByLevel() async { categoriesss.clear(); @@ -290,6 +287,7 @@ class ProductProvider extends ChangeNotifier { result.fold( (error) { + subCategoryloading = false; print("Error fetching categories: $error"); notifyListeners(); }, @@ -302,6 +300,7 @@ class ProductProvider extends ChangeNotifier { } else { print("No categories found."); } + subCategoryloading = false; notifyListeners(); // Notify UI after update }, ); @@ -534,10 +533,9 @@ class ProductProvider extends ChangeNotifier { ), ); }, - (response) - async { - cartItems.add(productId); - + (response) async { + cartItems.add(productId); + Fluttertoast.showToast( msg: "Added to cart successfully!", toastLength: Toast.LENGTH_SHORT, @@ -547,7 +545,7 @@ class ProductProvider extends ChangeNotifier { fontSize: 14.0, ); iscardAdded = true; - notifyListeners(); + notifyListeners(); }, ); } catch (e) { diff --git a/lib/src/logic/repo/product_repo.dart b/lib/src/logic/repo/product_repo.dart index ce80e2c..7cda1a0 100644 --- a/lib/src/logic/repo/product_repo.dart +++ b/lib/src/logic/repo/product_repo.dart @@ -94,7 +94,7 @@ class ProductRepo { ProductCategory productCategory = productCategoryFromJson(response.toString()); - // final String model = response.toString(); + return right(productCategory); } on DioException catch (e) { @@ -103,8 +103,7 @@ class ProductRepo { } } - FutureResult> getSubcategory( - data, BuildContext context) async { + FutureResult> getSubcategory( data, BuildContext context) async { try { var response = await _productService.getSubcategory(data); diff --git a/lib/src/logic/services/home_locator.dart b/lib/src/logic/services/home_locator.dart index 0e2e2f9..9340530 100644 --- a/lib/src/logic/services/home_locator.dart +++ b/lib/src/logic/services/home_locator.dart @@ -19,7 +19,6 @@ class ProductService extends ApiService { return response; } - Future updateDeviceToken(data) async { var response = await api.post(APIURL.upDateDeviceToken, data: jsonEncode(data)); @@ -48,8 +47,6 @@ class ProductService extends ApiService { return response; } - - // Future getBestDealProduct(data) async { @@ -65,20 +62,20 @@ class ProductService extends ApiService { return response; } - Future getSubcategory(data) async { - var response = await api.get(APIURL.getSubcategory, data: jsonEncode(data),queryParameters: data); + Future getSubcategory(data) async { + + var response = await api.get(APIURL.getSubcategory, data: jsonEncode(data)); return response; } -Future getCategoryByLevel(data) async { - var response = await api.get(APIURL.getCategoryByLevel, data: jsonEncode(data)); + Future getCategoryByLevel(data) async { + var response = + await api.get(APIURL.getCategoryByLevel, data: jsonEncode(data)); return response; } - - Future paymentOrder(data) async { var response = await api.post(APIURL.paymentOrder, data: jsonEncode(data)); @@ -124,7 +121,7 @@ Future getCategoryByLevel(data) async { return response; } - Future checkAddress(data, id) async { + Future checkAddress(data, id) async { var response = await api.get(APIURL.checkAddress + id, data: jsonEncode(data)); return response; diff --git a/lib/src/ui/fruitvegidetail/category_product.dart b/lib/src/ui/fruitvegidetail/category_product.dart index 2d88d7b..0881177 100644 --- a/lib/src/ui/fruitvegidetail/category_product.dart +++ b/lib/src/ui/fruitvegidetail/category_product.dart @@ -9,7 +9,6 @@ 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'; import 'package:grocery_app/src/ui/data_notfound.dart'; import 'package:grocery_app/utils/constants/assets_constant.dart'; @@ -34,20 +33,12 @@ class _CtegoryProductState extends State { @override void initState() { super.initState(); - WidgetsBinding.instance.addPostFrameCallback((_) { final productProvider = Provider.of(context, listen: false); productProvider.page = 1; - - // productProvider.gettAllProduct(context, "", true, '', true); productProvider.gettAllProduct( context, "/category/${widget.categoryId}", true, '', false); - - // productProvider.getAllcategory(context); - // productProvider.getCategoryByLevel(); - - // productProvider.setActiveIndex(0); }); _scrollController.addListener(() { @@ -55,7 +46,6 @@ class _CtegoryProductState extends State { _scrollController.position.maxScrollExtent) { final productProvider = Provider.of(context, listen: false); - productProvider.gettAllProduct(context, "", false, '', false); } }); @@ -78,28 +68,31 @@ class _CtegoryProductState extends State { height: 20, width: 20, child: InkWell( - onTap: () { - Navigator.of(context).pop(); - }, - child: SvgPicture.asset( - APPASSETS.back, - height: 20, - width: 20, - )), + onTap: () { + Navigator.of(context).pop(); + }, + child: SvgPicture.asset( + APPASSETS.back, + height: 20, + width: 20, + ), + ), ), ), title: Text( - widget.name ?? "", - style: TextStyle( + widget.name, + style: const TextStyle( fontSize: 20, fontWeight: FontWeight.w700, ), ), actions: [], ), - body: Padding( - padding: const EdgeInsets.all(8.0), - child: productWidget(), + body: Column( + children: [ + const SizedBox(height: 8), + Expanded(child: productWidget()), + ], ), ); } @@ -108,20 +101,22 @@ class _CtegoryProductState extends State { return Consumer(builder: (context, provider, child) { if (provider.isLoadingg) { return Center( - child: Container( - width: 30, - height: 30, - decoration: BoxDecoration( + 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(), + ), + ), + child: const Center( + child: CupertinoActivityIndicator(), + ), ), - )); + ); } else if (provider.products.isEmpty) { return Center( child: DataNotFound( @@ -132,235 +127,200 @@ class _CtegoryProductState extends State { ), ); } else { - return Expanded( - child: Padding( - padding: const EdgeInsets.only(left: 10, right: 10), - child: LayoutBuilder( - builder: (context, constraints) { - final itemWidth = (constraints.maxWidth - 20) / 2; - final itemHeight = itemWidth * 1.7; + return Padding( + padding: const EdgeInsets.symmetric(horizontal: 10), + child: LayoutBuilder( + builder: (context, constraints) { + final itemWidth = (constraints.maxWidth - 20) / 2; + final itemHeight = itemWidth * 1.7; - return GridView.builder( - controller: _scrollController, - itemCount: - provider.products.length + (provider.hasMore ? 1 : 0), - gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( - crossAxisCount: 2, - childAspectRatio: itemWidth / itemHeight, - crossAxisSpacing: 10, - mainAxisSpacing: 10, - ), - itemBuilder: (context, index) { - if (index == provider.products.length) { - return SizedBox.shrink(); - } - var product = provider.products[index]; - return InkWell( - onTap: () async { - var status = await provider.getProduuctDetails( - context, product.id, 1, product.discountPrice); - if (status) { - context.push( - MyRoutes.PRODUCTDETAILS, - extra: { - "id": product.id, - "quantity": 1, - "price": product.discountPrice, - }, - ); - } - - // context.push( - // MyRoutes.PRODUCTDETAILS, - // extra: { - // "id": product.id, - // "quantity": 1, - // "price": product.discountPrice, - // }, - // ); - }, - child: Container( - height: itemHeight, - decoration: BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.circular(15), - // boxShadow: [ - // BoxShadow( - // color: Colors.grey.withOpacity(0.1), - // blurRadius: 1, - // offset: const Offset(5, 5), - // ), - // ], - ), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Container( - height: itemWidth * - 1.1, // Adjust height for image container - // width: itemWidth, - decoration: BoxDecoration( - color: APPCOLOR.bgGrey, - borderRadius: BorderRadius.circular(15), - ), - child: Stack( - alignment: Alignment.center, - children: [ - AppNetworkImage( - imageUrl: product - .productImages!.first.url ?? - "https://5.imimg.com/data5/SELLER/Default/2024/2/385126988/OL/DA/VW/8627346/1l-fortune-sunflower-oil.jpg", - backGroundColor: Colors.transparent, - radius: 10, - boxFit: BoxFit.fill), - Positioned( - right: 1, - bottom: 0, - child: Container( - height: 35, - width: 35, - padding: EdgeInsets.symmetric( - horizontal: 1, vertical: 1), - decoration: BoxDecoration( - color: Colors.red, - borderRadius: - BorderRadius.circular(100), - ), - child: Center( - child: Text( - "${calculateDiscountPercentage(double.parse(product.basePrice), double.parse(product!.discountPrice))}%\nOFF", - textAlign: TextAlign.center, - style: TextStyle( - color: Colors.white, - fontWeight: FontWeight.bold, - fontSize: 10)), - ), - ), - ) - ], - ), + return GridView.builder( + physics: BouncingScrollPhysics(), + controller: _scrollController, + itemCount: + provider.products.length + (provider.hasMore ? 1 : 0), + gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( + crossAxisCount: 2, + childAspectRatio: itemWidth / itemHeight, + crossAxisSpacing: 10, + mainAxisSpacing: 10, + ), + itemBuilder: (context, index) { + if (index == provider.products.length) { + return const SizedBox.shrink(); + } + var product = provider.products[index]; + return InkWell( + onTap: () async { + var status = await provider.getProduuctDetails( + context, product.id, 1, product.discountPrice); + if (status) { + context.push( + MyRoutes.PRODUCTDETAILS, + extra: { + "id": product.id, + "quantity": 1, + "price": product.discountPrice, + }, + ); + } + }, + child: Container( + height: itemHeight, + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(15), + ), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Container( + height: itemWidth * 1.1, + decoration: BoxDecoration( + color: APPCOLOR.bgGrey, + borderRadius: BorderRadius.circular(15), ), - const SizedBox(height: 5), - Text( - product.name ?? " ", - textAlign: TextAlign.left, - maxLines: 1, - overflow: TextOverflow.ellipsis, - style: context - .customMedium( - APPCOLOR.balck1A1A1A, - 15, - ) - .copyWith(fontWeight: FontWeight.bold), - ), - const SizedBox(height: 2), - Text( - product.unit ?? " ", - textAlign: TextAlign.left, - maxLines: 1, - overflow: TextOverflow.ellipsis, - style: context.customMedium( - Colors.grey.withOpacity(0.8), - 13, - ), - ), - const SizedBox(height: 1), - Spacer(), - Row( + child: Stack( + alignment: Alignment.center, children: [ - Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - "₹${product.discountPrice ?? " "}", - textAlign: TextAlign.left, - maxLines: 1, - overflow: TextOverflow.ellipsis, - style: context.customSemiBold( - Colors.black, 15), - ), - const SizedBox(width: 5), - Text( - "₹${product.basePrice ?? " "}", - textAlign: TextAlign.left, - maxLines: 1, - overflow: TextOverflow.ellipsis, - style: context - .customMedium( - Colors.grey.withOpacity(0.8), - 15, - ) - .copyWith( - decoration: - TextDecoration.lineThrough, - ), - ), - ], + AppNetworkImage( + imageUrl: product.productImages!.first.url ?? + "https://5.imimg.com/data5/SELLER/Default/2024/2/385126988/OL/DA/VW/8627346/1l-fortune-sunflower-oil.jpg", + backGroundColor: Colors.transparent, + radius: 10, + boxFit: BoxFit.fill, ), - Spacer(), - Align( - alignment: Alignment.centerRight, - child: GestureDetector( - onTap: () async { - print( - "Add to Cart Pressed for ${product.id}"); - - if (await SharedPrefUtils.getToken() != - null) { - await provider.addToCart( - context, product.id!, 1); - } else { - context.push(MyRoutes.SIGNUP); - } - }, - child: Container( - height: - MediaQuery.of(context).size.height * - 0.038, - width: MediaQuery.of(context).size.width * - 0.1, - decoration: BoxDecoration( - color: APPCOLOR.lightGreen, - borderRadius: BorderRadius.circular(5), - ), - child: Center( - child: provider.isLoading[product.id] ?? - false - ? Padding( - padding: - const EdgeInsets.all(8.0), - child: Container( - height: 10, - width: 10, - child: - CircularProgressIndicator( - color: Colors.white, - strokeWidth: 2), - ), - ) - : Text( - // provider.cartItems - // .contains(bestdealproduct.id) - // ? 'Added' - // : - 'Add', - style: context.customRegular( - Colors.white, 12), - ), + Positioned( + right: 1, + bottom: 0, + child: Container( + height: 35, + width: 35, + padding: const EdgeInsets.all(1), + decoration: BoxDecoration( + color: Colors.red, + borderRadius: BorderRadius.circular(100), + ), + child: Center( + child: Text( + "${calculateDiscountPercentage(double.parse(product.basePrice), double.parse(product.discountPrice))}%\nOFF", + textAlign: TextAlign.center, + style: const TextStyle( + color: Colors.white, + fontWeight: FontWeight.bold, + fontSize: 10, + ), ), ), ), ), ], ), - ], - ), + ), + const SizedBox(height: 5), + Text( + product.name ?? " ", + maxLines: 1, + overflow: TextOverflow.ellipsis, + style: context + .customMedium( + APPCOLOR.balck1A1A1A, + 15, + ) + .copyWith(fontWeight: FontWeight.bold), + ), + const SizedBox(height: 2), + Text( + product.unit ?? " ", + maxLines: 1, + overflow: TextOverflow.ellipsis, + style: context.customMedium( + Colors.grey.withOpacity(0.8), + 13, + ), + ), + const SizedBox(height: 1), + const Spacer(), + Row( + children: [ + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + "₹${product.discountPrice ?? " "}", + style: context.customSemiBold( + Colors.black, 15), + ), + const SizedBox(width: 5), + Text( + "₹${product.basePrice ?? " "}", + style: context + .customMedium( + Colors.grey.withOpacity(0.8), + 15, + ) + .copyWith( + decoration: + TextDecoration.lineThrough, + ), + ), + ], + ), + const Spacer(), + Align( + alignment: Alignment.centerRight, + child: GestureDetector( + onTap: () async { + if (await SharedPrefUtils.getToken() != + null) { + await provider.addToCart( + context, product.id!, 1); + } else { + context.push(MyRoutes.SIGNUP); + } + }, + child: Container( + height: MediaQuery.of(context).size.height * + 0.038, + width: + MediaQuery.of(context).size.width * 0.1, + decoration: BoxDecoration( + color: APPCOLOR.lightGreen, + borderRadius: BorderRadius.circular(5), + ), + child: Center( + child: provider.isLoading[product.id] ?? + false + ? const Padding( + padding: EdgeInsets.all(8.0), + child: SizedBox( + height: 10, + width: 10, + child: + CircularProgressIndicator( + color: Colors.white, + strokeWidth: 2, + ), + ), + ) + : Text( + 'Add', + style: context.customRegular( + Colors.white, 12), + ), + ), + ), + ), + ), + ], + ), + ], ), - ); - }, - ); - }, - ), + ), + ); + }, + ); + }, ), ); } diff --git a/lib/src/ui/fruitvegidetail/fruit_veggie_detail.dart b/lib/src/ui/fruitvegidetail/fruit_veggie_detail.dart index 3f5300a..e4cf410 100644 --- a/lib/src/ui/fruitvegidetail/fruit_veggie_detail.dart +++ b/lib/src/ui/fruitvegidetail/fruit_veggie_detail.dart @@ -32,31 +32,14 @@ class _FruitVeggieDetailState extends State { Provider.of(context, listen: false); productProvider.page = 1; - // productProvider.gettAllProduct(context, "", true, '', true); + productProvider.getCategoryByLevel(); productProvider.getAllcategory(context); - productProvider.getCategoryByLevel(); productProvider.setActiveIndex(0); }); - - // _scrollController.addListener(() { - // if (_scrollController.position.pixels == - // _scrollController.position.maxScrollExtent) { - // final productProvider = - // Provider.of(context, listen: false); - - // productProvider.gettAllProduct(context, "", false, '', false); - // } - // }); } - // @override - // void dispose() { - // _scrollController.dispose(); - // super.dispose(); - // } - @override Widget build(BuildContext context) { return Scaffold( @@ -103,7 +86,7 @@ class _FruitVeggieDetailState extends State { Widget expendablecategory() { return Consumer( builder: (context, provider, child) { - if (provider.iscategroyloading) { + if (provider.subCategoryloading) { return const Center(child: CupertinoActivityIndicator()); } @@ -180,6 +163,8 @@ class _FruitVeggieDetailState extends State { ), ), ); + } else if (provider.categoryList.isEmpty) { + return SizedBox.shrink(); } else { // final categories = [DatumCategory(id: "all", name: "ALL")]; // categories.addAll(provider.categoryList.cast()); diff --git a/lib/src/ui/home/home_screen.dart b/lib/src/ui/home/home_screen.dart index 426093a..85c1f35 100644 --- a/lib/src/ui/home/home_screen.dart +++ b/lib/src/ui/home/home_screen.dart @@ -37,7 +37,7 @@ class _HomeScreenState extends State { productProvider.getBanners(context); productProvider.getHomeProduct(context, "", '', '', '', ''); productProvider.getBestDealProduct(context, ''); - productProvider.getAllcategory(context); + // productProvider.getAllcategory(context); productProvider.updateDeviceToken(context); // productProvider.getCategoryByLevel();