searchbarstatus
This commit is contained in:
@@ -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 = {
|
||||
"minPrice": "${minPrice}",
|
||||
"minPrice": "${maxprice}",
|
||||
"search": search,
|
||||
"sortBy": orderby
|
||||
};
|
||||
var data;
|
||||
|
||||
if (maxprice.isNotEmpty) {
|
||||
data = {
|
||||
"minPrice": "${minPrice}",
|
||||
"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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user