Set search test result by api

This commit is contained in:
hanie.khodkari
2025-05-10 18:27:37 +03:30
parent 12758968c9
commit b43d5c90fd
3 changed files with 54 additions and 25 deletions
+4
View File
@@ -178,4 +178,8 @@ class Url {
static String getUsers(String id) {
return '$baseUrl/Users?medical_center_id=$id';
}
static String searchTestResults(String value) {
return '$baseUrl/TestResults?test_type_name=$value';
}
}
+27 -23
View File
@@ -99,7 +99,7 @@ class TestResultsProvider with ChangeNotifier {
void setLoading() {
isloading = true;
// notifyListeners();
notifyListeners();
}
// bool isChangeVerify = false;
@@ -140,30 +140,33 @@ class TestResultsProvider with ChangeNotifier {
return _filters;
}
void search(String value) {
Future<void> search(String value) async {
print(value);
items = [];
searchBoxValue = value;
originalItems!.forEach((result) {
if (result.name
.toString()
.toLowerCase()
.contains(searchBoxValue.toLowerCase()) ||
result.name
.toString()
.toUpperCase()
.contains(searchBoxValue.toUpperCase()) ||
result.name
.toString()
.toLowerCase()
.contains(searchBoxValue.toUpperCase()) ||
result.name
.toString()
.toUpperCase()
.contains(searchBoxValue.toLowerCase())) {
items!.add(result);
}
});
var response = await http.get(
Uri.parse(Url.searchTestResults(value)),
headers: {
'Authorization': User.token,
},
);
print(response.body);
var testResultData = json.decode(response.body);
for (var item in testResultData['data']) {
items!.add(
TestResultObject(
id: item['id'].toString(),
name: item['test_type'] != null ? item['test_type']['name'] : '',
deviceId:
item['device_id'] != null ? item['device_id'].toString() : '',
result: item['result'] == 'Accept' ? 'Accepted' : 'Not Accepted',
date: item['created_at'].toString().substring(0, 10),
hospital: item['user']['medical_center']['name'],
verified: item['verified'].toString(),
),
);
}
resetLoading();
notifyListeners();
}
@@ -270,8 +273,9 @@ class TestResultsProvider with ChangeNotifier {
),
);
}
items = originalItems;
pageNumber += 1;
search('');
// search('');
notifyListeners();
}
@@ -17,12 +17,13 @@ class TestResultSearchBox extends StatelessWidget {
@override
Widget build(BuildContext context) {
var textVal;
return TextField(
onEditingComplete: () {
FocusScope.of(context).unfocus();
},
onChanged: (value) {
Provider.of<TestResultsProvider>(context, listen: false).search(value);
onChanged: (value) async {
textVal = value;
},
controller: searchCTRL,
decoration: InputDecoration(
@@ -37,6 +38,26 @@ class TestResultSearchBox extends StatelessWidget {
labelText: 'Search by test name',
isDense: true,
contentPadding: EdgeInsets.symmetric(vertical: 2, horizontal: 3),
suffixIcon: InkWell(
onTap: () async {
var testResults =
await Provider.of<TestResultsProvider>(context, listen: false);
testResults.setLoading();
await testResults.search(textVal);
},
child: Container(
margin: EdgeInsets.all(5),
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.black,
),
child: Icon(
Icons.space_bar,
// size: 4 * _deviceBlockSize,
color: Colors.white,
),
),
),
),
style: TextStyle(
fontWeight: FontWeight.w700,