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) { static String getUsers(String id) {
return '$baseUrl/Users?medical_center_id=$id'; return '$baseUrl/Users?medical_center_id=$id';
} }
static String searchTestResults(String value) {
return '$baseUrl/TestResults?test_type_name=$value';
}
} }
+26 -22
View File
@@ -99,7 +99,7 @@ class TestResultsProvider with ChangeNotifier {
void setLoading() { void setLoading() {
isloading = true; isloading = true;
// notifyListeners(); notifyListeners();
} }
// bool isChangeVerify = false; // bool isChangeVerify = false;
@@ -140,30 +140,33 @@ class TestResultsProvider with ChangeNotifier {
return _filters; return _filters;
} }
void search(String value) { Future<void> search(String value) async {
print(value); print(value);
items = []; items = [];
searchBoxValue = value; searchBoxValue = value;
originalItems!.forEach((result) { var response = await http.get(
if (result.name Uri.parse(Url.searchTestResults(value)),
.toString() headers: {
.toLowerCase() 'Authorization': User.token,
.contains(searchBoxValue.toLowerCase()) || },
result.name );
.toString() print(response.body);
.toUpperCase() var testResultData = json.decode(response.body);
.contains(searchBoxValue.toUpperCase()) || for (var item in testResultData['data']) {
result.name items!.add(
.toString() TestResultObject(
.toLowerCase() id: item['id'].toString(),
.contains(searchBoxValue.toUpperCase()) || name: item['test_type'] != null ? item['test_type']['name'] : '',
result.name deviceId:
.toString() item['device_id'] != null ? item['device_id'].toString() : '',
.toUpperCase() result: item['result'] == 'Accept' ? 'Accepted' : 'Not Accepted',
.contains(searchBoxValue.toLowerCase())) { date: item['created_at'].toString().substring(0, 10),
items!.add(result); hospital: item['user']['medical_center']['name'],
verified: item['verified'].toString(),
),
);
} }
}); resetLoading();
notifyListeners(); notifyListeners();
} }
@@ -270,8 +273,9 @@ class TestResultsProvider with ChangeNotifier {
), ),
); );
} }
items = originalItems;
pageNumber += 1; pageNumber += 1;
search(''); // search('');
notifyListeners(); notifyListeners();
} }
@@ -17,12 +17,13 @@ class TestResultSearchBox extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
var textVal;
return TextField( return TextField(
onEditingComplete: () { onEditingComplete: () {
FocusScope.of(context).unfocus(); FocusScope.of(context).unfocus();
}, },
onChanged: (value) { onChanged: (value) async {
Provider.of<TestResultsProvider>(context, listen: false).search(value); textVal = value;
}, },
controller: searchCTRL, controller: searchCTRL,
decoration: InputDecoration( decoration: InputDecoration(
@@ -37,6 +38,26 @@ class TestResultSearchBox extends StatelessWidget {
labelText: 'Search by test name', labelText: 'Search by test name',
isDense: true, isDense: true,
contentPadding: EdgeInsets.symmetric(vertical: 2, horizontal: 3), 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( style: TextStyle(
fontWeight: FontWeight.w700, fontWeight: FontWeight.w700,