Set search item by api

This commit is contained in:
hanie.khodkari
2025-05-10 20:13:37 +03:30
parent 14a6f06a43
commit ae6de355e7
5 changed files with 42 additions and 31 deletions
+1 -1
View File
@@ -121,7 +121,7 @@ class CyclesProvider extends ChangeNotifier {
void setLoading() {
isloading = true;
// notifyListeners();
notifyListeners();
}
bool isloadingButton = false;
+28 -24
View File
@@ -51,7 +51,7 @@ class ItemProvider extends ChangeNotifier {
void setLoading() {
isloading = true;
// notifyListeners();
notifyListeners();
}
bool isloadingButton = false;
@@ -244,29 +244,33 @@ class ItemProvider extends ChangeNotifier {
notifyListeners();
}
void search(String value) {
Future<void> search(String value) async {
items = [];
searchBoxValue = value;
originalItems!.forEach((result) {
if (result.udi
.toString()
.toLowerCase()
.contains(searchBoxValue.toLowerCase()) ||
result.udi
.toString()
.toUpperCase()
.contains(searchBoxValue.toUpperCase()) ||
result.udi
.toString()
.toLowerCase()
.contains(searchBoxValue.toUpperCase()) ||
result.udi
.toString()
.toUpperCase()
.contains(searchBoxValue.toLowerCase())) {
items!.add(result);
}
});
var response = await http.get(
Uri.parse(Url.searchItems(value)),
headers: {
'Authorization': User.token,
},
);
var itemsData = json.decode(response.body);
for (var item in itemsData['data']) {
items!.add(
ItemResultObject(
name: item['name'],
id: item['id'].toString(),
size: item['size'].toString(),
userName: item['user'] != null ? item['user']['name'] : '',
status: item['status'],
udi: item['udi'],
packageId:
item['package_id'] != null ? item['package_id'].toString() : "",
),
);
}
resetLoading();
notifyListeners();
}
@@ -319,8 +323,8 @@ class ItemProvider extends ChangeNotifier {
);
}
pageNumber += 1;
search('');
items = originalItems;
notifyListeners();
}
Future<ItemDetailObject> showItemResult(String id) async {