searchbarstatus
This commit is contained in:
@@ -998,7 +998,7 @@
|
||||
"languageVersion": "3.4"
|
||||
}
|
||||
],
|
||||
"generated": "2025-02-24T13:23:19.491834Z",
|
||||
"generated": "2025-02-25T13:35:16.100085Z",
|
||||
"generator": "pub",
|
||||
"generatorVersion": "3.4.4",
|
||||
"flutterRoot": "file:///Users/rajeevsingh/Documents/allSoftwares/flutter",
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1,3 +1,4 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -109,13 +110,20 @@ class ProductProvider extends ChangeNotifier {
|
||||
isHomeLoadingg = true;
|
||||
|
||||
notifyListeners();
|
||||
var data = {
|
||||
var data;
|
||||
|
||||
if (maxprice.isNotEmpty) {
|
||||
data = {
|
||||
"minPrice": "${minPrice}",
|
||||
"minPrice": "${maxprice}",
|
||||
"maxPrice": maxprice,
|
||||
"search": search,
|
||||
"sortBy": orderby
|
||||
};
|
||||
} else {
|
||||
data = {"minPrice": "${minPrice}", "search": search, "sortBy": orderby};
|
||||
}
|
||||
var result = await _homeRepo.getAllProduct(data, context, id);
|
||||
|
||||
return result.fold(
|
||||
(error) {
|
||||
isLoadingg = false;
|
||||
@@ -765,4 +773,54 @@ class ProductProvider extends ChangeNotifier {
|
||||
print("Error fetching address: $e");
|
||||
}
|
||||
}
|
||||
|
||||
List<Product> _suggestions = [];
|
||||
Timer? _debounce;
|
||||
|
||||
List<Product> 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<void> _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<Product>);
|
||||
|
||||
notifyListeners();
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
void clearSuggestions() {
|
||||
_suggestions.clear();
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,13 +127,14 @@ class _BestDealScreenState extends State<BestDealScreen> {
|
||||
),
|
||||
floatingActionButton: floatingAction(),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.only(bottom: 100),
|
||||
padding: const EdgeInsets.only(bottom: 10),
|
||||
child: itemBestdeal(),
|
||||
));
|
||||
}
|
||||
|
||||
Widget floatingAction() {
|
||||
return Consumer<ProductProvider>(builder: (context, provider, child) {
|
||||
return Consumer<ProductProvider>(builder: (context, provider, child)
|
||||
{
|
||||
if (provider.countList.isEmpty) {
|
||||
return Center();
|
||||
} else {
|
||||
@@ -309,8 +310,8 @@ class _BestDealScreenState extends State<BestDealScreen> {
|
||||
MyRoutes.PRODUCTDETAILS,
|
||||
extra: {
|
||||
"id": bestdealproduct.id,
|
||||
"quantity": 0,
|
||||
"price": '0',
|
||||
"quantity": 1,
|
||||
"price": bestdealproduct.discountPrice,
|
||||
},
|
||||
);
|
||||
},
|
||||
|
||||
@@ -116,8 +116,8 @@ class _MycartState extends State<Mycart> {
|
||||
MyRoutes.PRODUCTDETAILS,
|
||||
extra: {
|
||||
"id": bestdealproduct.id,
|
||||
"quantity": 0,
|
||||
"price": "0",
|
||||
"quantity": 1,
|
||||
"price": bestdealproduct.discountPrice,
|
||||
},
|
||||
);
|
||||
},
|
||||
|
||||
@@ -170,13 +170,14 @@ class _FavouriteScreenState extends State<FavouriteScreen>
|
||||
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
context.push(MyRoutes.PRODUCTDETAILS,
|
||||
context.push(
|
||||
MyRoutes.PRODUCTDETAILS,
|
||||
// extra: productId
|
||||
|
||||
extra: {
|
||||
"id": productId,
|
||||
"quantity": 0,
|
||||
"price": "0",
|
||||
"quantity": 1,
|
||||
"price": product.discountPrice,
|
||||
},
|
||||
);
|
||||
},
|
||||
|
||||
@@ -187,8 +187,8 @@ class _FruitVeggieDetailState extends State<FruitVeggieDetail> {
|
||||
|
||||
extra: {
|
||||
"id": product.id,
|
||||
"quantity": 0,
|
||||
"price": "0",
|
||||
"quantity": 1,
|
||||
"price": product.discountPrice,
|
||||
},
|
||||
);
|
||||
},
|
||||
|
||||
@@ -54,6 +54,73 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
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<ProductProvider>(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,11 +136,15 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
const SizedBox(
|
||||
height: 15,
|
||||
),
|
||||
|
||||
Row(
|
||||
children: [
|
||||
Consumer<ProductProvider>(
|
||||
Expanded(
|
||||
// ✅ Move Expanded Here
|
||||
child: Consumer<ProductProvider>(
|
||||
builder: (context, provider, child) {
|
||||
return Expanded(
|
||||
return CompositedTransformTarget(
|
||||
link: _layerLink,
|
||||
child: Container(
|
||||
height: 50,
|
||||
decoration: BoxDecoration(
|
||||
@@ -81,32 +152,44 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
borderRadius: BorderRadius.circular(5),
|
||||
),
|
||||
child: TextFormField(
|
||||
controller: _searchController,
|
||||
onChanged: (value) {
|
||||
provider.searchValue = 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)),
|
||||
child: Icon(MdiIcons.magnify),
|
||||
),
|
||||
hintText: 'Search',
|
||||
hintStyle: context.customRegular(
|
||||
APPCOLOR.grey666666, 18),
|
||||
isCollapsed: true,
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
vertical: 10, horizontal: 10),
|
||||
vertical: 10,
|
||||
horizontal: 10,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}),
|
||||
const SizedBox(
|
||||
width: 10,
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
InkWell(
|
||||
onTap: () {
|
||||
showSortBottomSheet(context);
|
||||
@@ -128,6 +211,83 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
// Row(
|
||||
// children: [
|
||||
// Consumer<ProductProvider>(
|
||||
// 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<HomeScreen> {
|
||||
|
||||
extra: {
|
||||
"id": bestdealproduct.id,
|
||||
"quantity": 0,
|
||||
"price": "0",
|
||||
"quantity": 1,
|
||||
"price": bestdealproduct.discountPrice,
|
||||
},
|
||||
);
|
||||
},
|
||||
@@ -694,12 +854,10 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
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<HomeScreen> {
|
||||
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:
|
||||
|
||||
@@ -113,11 +113,7 @@ class _ProductDetailsState extends State<ProductDetails> {
|
||||
}
|
||||
|
||||
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<ProductDetails> {
|
||||
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,6 +359,8 @@ class _ProductDetailsState extends State<ProductDetails> {
|
||||
)
|
||||
],
|
||||
),
|
||||
if (provider.productDetails.data!.productHighlight!
|
||||
.isNotEmpty)
|
||||
AnimatedSize(
|
||||
duration: Duration(milliseconds: 300),
|
||||
curve: Curves.easeInOut,
|
||||
@@ -367,7 +372,7 @@ class _ProductDetailsState extends State<ProductDetails> {
|
||||
itemCount: isHilightsExpanded
|
||||
? provider.productDetails.data!
|
||||
.productHighlight!.length
|
||||
: 2,
|
||||
: 1,
|
||||
itemBuilder: (context, index) {
|
||||
final item = provider.productDetails.data!
|
||||
.productHighlight![index];
|
||||
@@ -553,16 +558,16 @@ class _ProductDetailsState extends State<ProductDetails> {
|
||||
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<ProductDetails> {
|
||||
: Text(
|
||||
'Add to Cart',
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.white),
|
||||
),
|
||||
@@ -1264,7 +1269,7 @@ class _ProductDetailsState extends State<ProductDetails> {
|
||||
Text(
|
||||
"₹${cartProvider.totalPrice}",
|
||||
style: TextStyle(
|
||||
fontSize: 25,
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.white),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user