From 299a96c2bf050478ecc79c36adbfc522dbb7b0cd Mon Sep 17 00:00:00 2001 From: bestonemitRam Date: Tue, 25 Feb 2025 19:06:01 +0530 Subject: [PATCH] searchbarstatus --- .DS_Store | Bin 10244 -> 10244 bytes .dart_tool/package_config.json | 2 +- .flutter-plugins-dependencies | 2 +- lib/src/logic/provider/home_provider.dart | 70 +++++- lib/src/ui/bestdeal/bestdeal_screen.dart | 9 +- lib/src/ui/cart/cartview_screen.dart | 4 +- lib/src/ui/favourite/favourite_screen.dart | 17 +- .../fruitvegidetail/fruit_veggie_detail.dart | 4 +- lib/src/ui/home/home_screen.dart | 232 +++++++++++++++--- .../ui/productdetails/product_details.dart | 79 +++--- 10 files changed, 322 insertions(+), 97 deletions(-) diff --git a/.DS_Store b/.DS_Store index 35f6687ea2e9491cb6bfd7f65cddc77e555c3b75..2d69e8ddab40db173ef79607b2df128c52649396 100644 GIT binary patch delta 58 zcmZn(XbISGSddxQf7aw _suggestions = []; + Timer? _debounce; + + List get suggestions => _suggestions; + + /// Debounced Search API Call + void searchProducts(String query, BuildContext context) { + if (_debounce?.isActive ?? false) _debounce!.cancel(); + + _debounce = Timer(const Duration(milliseconds: 500), () async { + if (query.isNotEmpty) { + _fetchSuggestions(query, context); + } else { + _suggestions.clear(); + notifyListeners(); + } + }); + } + + /// Simulated API Call (Replace with real API) + Future _fetchSuggestions(String query, context) async { + _suggestions.clear(); + notifyListeners(); + var data = { + "search": query, + "page": 1, + "limit": 10, + }; + + var result = await _homeRepo.getAllProduct(data, context, ''); + + return result.fold( + (error) { + notifyListeners(); + }, + (response) + { + print("lkdfjglkfdglkh ${response.data}"); + _suggestions.addAll(response.data as Iterable); + + notifyListeners(); + }, + ); + } + + void clearSuggestions() { + _suggestions.clear(); + notifyListeners(); + } } diff --git a/lib/src/ui/bestdeal/bestdeal_screen.dart b/lib/src/ui/bestdeal/bestdeal_screen.dart index d367bd3..1cbe92c 100644 --- a/lib/src/ui/bestdeal/bestdeal_screen.dart +++ b/lib/src/ui/bestdeal/bestdeal_screen.dart @@ -127,13 +127,14 @@ class _BestDealScreenState extends State { ), floatingActionButton: floatingAction(), body: Padding( - padding: const EdgeInsets.only(bottom: 100), + padding: const EdgeInsets.only(bottom: 10), child: itemBestdeal(), )); } Widget floatingAction() { - return Consumer(builder: (context, provider, child) { + return Consumer(builder: (context, provider, child) + { if (provider.countList.isEmpty) { return Center(); } else { @@ -309,8 +310,8 @@ class _BestDealScreenState extends State { MyRoutes.PRODUCTDETAILS, extra: { "id": bestdealproduct.id, - "quantity": 0, - "price": '0', + "quantity": 1, + "price": bestdealproduct.discountPrice, }, ); }, diff --git a/lib/src/ui/cart/cartview_screen.dart b/lib/src/ui/cart/cartview_screen.dart index 4ba5e6a..ce3347e 100644 --- a/lib/src/ui/cart/cartview_screen.dart +++ b/lib/src/ui/cart/cartview_screen.dart @@ -116,8 +116,8 @@ class _MycartState extends State { MyRoutes.PRODUCTDETAILS, extra: { "id": bestdealproduct.id, - "quantity": 0, - "price": "0", + "quantity": 1, + "price": bestdealproduct.discountPrice, }, ); }, diff --git a/lib/src/ui/favourite/favourite_screen.dart b/lib/src/ui/favourite/favourite_screen.dart index 527fb10..f013ad9 100644 --- a/lib/src/ui/favourite/favourite_screen.dart +++ b/lib/src/ui/favourite/favourite_screen.dart @@ -170,15 +170,16 @@ class _FavouriteScreenState extends State return GestureDetector( onTap: () { - context.push(MyRoutes.PRODUCTDETAILS, - // extra: productId + context.push( + MyRoutes.PRODUCTDETAILS, + // extra: productId - extra: { - "id":productId, - "quantity": 0, - "price": "0", - }, - ); + extra: { + "id": productId, + "quantity": 1, + "price": product.discountPrice, + }, + ); }, child: Container( padding: EdgeInsets.all(8), diff --git a/lib/src/ui/fruitvegidetail/fruit_veggie_detail.dart b/lib/src/ui/fruitvegidetail/fruit_veggie_detail.dart index b083f8e..2b37765 100644 --- a/lib/src/ui/fruitvegidetail/fruit_veggie_detail.dart +++ b/lib/src/ui/fruitvegidetail/fruit_veggie_detail.dart @@ -187,8 +187,8 @@ class _FruitVeggieDetailState extends State { extra: { "id": product.id, - "quantity": 0, - "price": "0", + "quantity": 1, + "price": product.discountPrice, }, ); }, diff --git a/lib/src/ui/home/home_screen.dart b/lib/src/ui/home/home_screen.dart index 2f05503..3623c95 100644 --- a/lib/src/ui/home/home_screen.dart +++ b/lib/src/ui/home/home_screen.dart @@ -54,6 +54,73 @@ class _HomeScreenState extends State { APPSTRING.userLastName = (await SharedPrefUtils.getLastName())!; } + final TextEditingController _searchController = TextEditingController(); + OverlayEntry? _overlayEntry; + final LayerLink _layerLink = LayerLink(); + + @override + void dispose() { + _searchController.dispose(); + super.dispose(); + } + + void _showOverlay(BuildContext context) { + _clearOverlay(); + _overlayEntry = _createOverlayEntry(context); + Overlay.of(context).insert(_overlayEntry!); + } + + OverlayEntry _createOverlayEntry(BuildContext context) { + final searchProvider = Provider.of(context, listen: false); + RenderBox renderBox = context.findRenderObject() as RenderBox; + Size size = renderBox.size; + + return OverlayEntry( + builder: (context) => Positioned( + width: size.width, + child: CompositedTransformFollower( + link: _layerLink, + offset: Offset(0, size.height + 5), + child: Material( + elevation: 4.0, + borderRadius: BorderRadius.circular(8), + child: ListView( + padding: EdgeInsets.zero, + shrinkWrap: true, + children: searchProvider.suggestions.map((suggestion) { + return ListTile( + title: Row( + children: [ + AppNetworkImage( + height: 25, + width: 25, + imageUrl: suggestion.productImages!.first.url, + backGroundColor: APPCOLOR.bgGrey, + radius: 10, + ), + Text(suggestion.name), + ], + ), + onTap: () { + _searchController.text = suggestion.name; + searchProvider.getHomeProduct( + context, "", suggestion.name, '', '', ''); + _clearOverlay(); + }, + ); + }).toList(), + ), + ), + ), + ), + ); + } + + void _clearOverlay() { + _overlayEntry?.remove(); + _overlayEntry = null; + } + @override Widget build(BuildContext context) { return SafeArea( @@ -69,44 +136,60 @@ class _HomeScreenState extends State { const SizedBox( height: 15, ), + Row( children: [ - Consumer( - builder: (context, provider, child) { - return Expanded( - child: Container( - height: 50, - decoration: BoxDecoration( - color: APPCOLOR.bgGrey, - borderRadius: BorderRadius.circular(5), - ), - child: TextFormField( - onChanged: (value) { - provider.searchValue = value; - }, - decoration: InputDecoration( - border: InputBorder.none, - fillColor: Colors.transparent, - suffixIcon: InkWell( + Expanded( + // ✅ Move Expanded Here + child: Consumer( + builder: (context, provider, child) { + return CompositedTransformTarget( + link: _layerLink, + child: Container( + height: 50, + decoration: BoxDecoration( + color: APPCOLOR.bgGrey, + borderRadius: BorderRadius.circular(5), + ), + child: TextFormField( + controller: _searchController, + onChanged: (value) { + provider.searchProducts(value, context); + + if (value.isNotEmpty) { + _showOverlay(context); + } else { + _clearOverlay(); + } + }, + decoration: InputDecoration( + border: InputBorder.none, + fillColor: Colors.transparent, + suffixIcon: InkWell( onTap: () { + print( + "klfklhjklfklhg ${_searchController.text}"); + provider.getHomeProduct(context, "", - provider.searchValue, '', '', ''); + _searchController.text, '', '', ''); }, - child: Icon(MdiIcons.magnify)), - hintText: 'Search', - hintStyle: context.customRegular( - APPCOLOR.grey666666, 18), - isCollapsed: true, - contentPadding: const EdgeInsets.symmetric( - vertical: 10, horizontal: 10), + child: Icon(MdiIcons.magnify), + ), + hintText: 'Search', + hintStyle: context.customRegular( + APPCOLOR.grey666666, 18), + isCollapsed: true, + contentPadding: const EdgeInsets.symmetric( + vertical: 10, + horizontal: 10, + ), + ), ), ), - ), - ); - }), - const SizedBox( - width: 10, + ); + }), ), + const SizedBox(width: 10), InkWell( onTap: () { showSortBottomSheet(context); @@ -128,6 +211,83 @@ class _HomeScreenState extends State { ), ], ), + + // Row( + // children: [ + // Consumer( + // builder: (context, provider, child) + // { + // return + // CompositedTransformTarget( + // link: _layerLink, + // child: Expanded( + // child: Container( + // height: 50, + // decoration: BoxDecoration( + // color: APPCOLOR.bgGrey, + // borderRadius: BorderRadius.circular(5), + // ), + // child: TextFormField( + // controller: _searchController, + // onChanged: (value) { + + // provider.searchProducts(value); + // if (value.isNotEmpty) { + // _showOverlay(context); + // } else { + // _clearOverlay(); + // } + + // // provider.searchValue = value; + + // }, + // decoration: InputDecoration( + // border: InputBorder.none, + // fillColor: Colors.transparent, + // suffixIcon: InkWell( + // onTap: () { + // provider.getHomeProduct(context, "", + // provider.searchValue, '', '', ''); + // }, + // child: Icon(MdiIcons.magnify)), + // hintText: 'Search', + // hintStyle: context.customRegular( + // APPCOLOR.grey666666, 18), + // isCollapsed: true, + // contentPadding: const EdgeInsets.symmetric( + // vertical: 10, horizontal: 10), + // ), + // ), + // ), + // ), + // ); + // }), + + // const SizedBox( + // width: 10, + // ), + // InkWell( + // onTap: () { + // showSortBottomSheet(context); + // }, + // child: Container( + // height: 50, + // width: 50, + // decoration: BoxDecoration( + // color: APPCOLOR.lightGreen, + // borderRadius: BorderRadius.circular(5), + // ), + // child: Center( + // child: Icon( + // MdiIcons.tuneVariant, + // color: Colors.white, + // ), + // ), + // ), + // ), + // ], + // ), + const SizedBox( height: 15, ), @@ -311,8 +471,8 @@ class _HomeScreenState extends State { extra: { "id": bestdealproduct.id, - "quantity": 0, - "price": "0", + "quantity": 1, + "price": bestdealproduct.discountPrice, }, ); }, @@ -694,12 +854,10 @@ class _HomeScreenState extends State { onTap: () { context.push( MyRoutes.PRODUCTDETAILS, - // extra: product.id - extra: { "id": product.id, - "quantity": 0, - "price": "0", + "quantity": 1, + "price": product.discountPrice, }, ); }, @@ -795,6 +953,8 @@ class _HomeScreenState extends State { provider.getHomeProduct(context, '', '', "", "", "popularity"); break; case 3: + // t(BuildContext context, String id, String search, + // String minPrice, String maxprice, orderby) provider.getHomeProduct(context, '', '', "100", "100000000", ''); break; default: diff --git a/lib/src/ui/productdetails/product_details.dart b/lib/src/ui/productdetails/product_details.dart index f3d862d..fdce20c 100644 --- a/lib/src/ui/productdetails/product_details.dart +++ b/lib/src/ui/productdetails/product_details.dart @@ -113,11 +113,7 @@ class _ProductDetailsState extends State { } int calculateDiscountPercentage(double basePrice, double discountPrice) { - print( - "Base Price (Before Discount): $basePrice, Discount Price (After Discount): $discountPrice"); - if (basePrice <= 0 || discountPrice <= 0 || discountPrice > basePrice) { - print("Error: Invalid price values."); return 0; } @@ -151,8 +147,15 @@ class _ProductDetailsState extends State { itemBuilder: (context, index, realIndex) { var productImage = provider.productDetails.data!.productImages![index]; - return Image.network(productImage.url ?? - 'https://i.pinimg.com/originals/a5/f3/5f/a5f35fb23e942809da3df91b23718e8d.png'); + return AppNetworkImage( + height: MediaQuery.of(context).size.height * 0.08, + width: 2000, + imageUrl: productImage.url, + backGroundColor: Colors.transparent, + ); + + // Image.network(productImage.url ?? + // 'https://i.pinimg.com/originals/a5/f3/5f/a5f35fb23e942809da3df91b23718e8d.png'); }, options: CarouselOptions( height: 300, @@ -356,27 +359,29 @@ class _ProductDetailsState extends State { ) ], ), - AnimatedSize( - duration: Duration(milliseconds: 300), - curve: Curves.easeInOut, - child: Padding( - padding: const EdgeInsets.all(8.0), - child: ListView.builder( - shrinkWrap: true, - physics: NeverScrollableScrollPhysics(), - itemCount: isHilightsExpanded - ? provider.productDetails.data! - .productHighlight!.length - : 2, - itemBuilder: (context, index) { - final item = provider.productDetails.data! - .productHighlight![index]; - return _buildText( - item.key ?? '', item.value ?? ''); - }, + if (provider.productDetails.data!.productHighlight! + .isNotEmpty) + AnimatedSize( + duration: Duration(milliseconds: 300), + curve: Curves.easeInOut, + child: Padding( + padding: const EdgeInsets.all(8.0), + child: ListView.builder( + shrinkWrap: true, + physics: NeverScrollableScrollPhysics(), + itemCount: isHilightsExpanded + ? provider.productDetails.data! + .productHighlight!.length + : 1, + itemBuilder: (context, index) { + final item = provider.productDetails.data! + .productHighlight![index]; + return _buildText( + item.key ?? '', item.value ?? ''); + }, + ), ), ), - ), Center( child: TextButton( onPressed: () { @@ -553,16 +558,16 @@ class _ProductDetailsState extends State { SizedBox(height: 20), // Know More Link - InkWell( - onTap: () { - // Handle navigation to more details - }, - child: Text( - "Know More", - style: TextStyle( - color: Colors.blue, fontWeight: FontWeight.bold), - ), - ), + // InkWell( + // onTap: () { + // // Handle navigation to more details + // }, + // child: Text( + // "Know More", + // style: TextStyle( + // color: Colors.blue, fontWeight: FontWeight.bold), + // ), + // ), ], ), ); @@ -1252,7 +1257,7 @@ class _ProductDetailsState extends State { : Text( 'Add to Cart', style: TextStyle( - fontSize: 20, + fontSize: 18, fontWeight: FontWeight.bold, color: Colors.white), ), @@ -1264,7 +1269,7 @@ class _ProductDetailsState extends State { Text( "₹${cartProvider.totalPrice}", style: TextStyle( - fontSize: 25, + fontSize: 18, fontWeight: FontWeight.bold, color: Colors.white), ),