Set search cycle by api

This commit is contained in:
hanie.khodkari
2025-05-10 19:18:12 +03:30
parent b43d5c90fd
commit 14a6f06a43
11 changed files with 76 additions and 17 deletions
+30 -6
View File
@@ -271,14 +271,37 @@ class CyclesProvider extends ChangeNotifier {
notifyListeners();
}
void search(String value) {
Future<void> search(String value) async {
print(value);
items = [];
searchBoxValue = value;
originalItems!.forEach((result) {
if (result.id.toString().contains(searchBoxValue)) {
items!.add(result);
var response = await http.get(
Uri.parse(Url.searchCycles(value)),
headers: {
'Authorization': User.token,
},
);
var testResultData = json.decode(response.body);
List<String> labels = [];
if (pageNumber == 1) {
originalItems = [];
items = [];
}
for (var item in testResultData['data']) {
labels = [];
for (var label in item['labels']) {
labels.add(label['id'].toString());
}
});
items!.add(
CycleResultObject(
createdAt: item['date'],
id: item['id'].toString(),
label: labels,
),
);
}
resetLoading();
notifyListeners();
}
@@ -332,8 +355,9 @@ class CyclesProvider extends ChangeNotifier {
),
);
}
items = originalItems;
pageNumber += 1;
search('');
notifyListeners();
}
Future<CycleDetailObject> showCycleResult(String id) async {