From b43d5c90fd8e9d1fed160a018e78c8d9abed26b0 Mon Sep 17 00:00:00 2001 From: "hanie.khodkari" Date: Sat, 10 May 2025 18:27:37 +0330 Subject: [PATCH] Set search test result by api --- lib/config/urls.dart | 4 ++ lib/providers/test_results.dart | 50 ++++++++++--------- .../TestResultScreens/Main/search_box.dart | 25 +++++++++- 3 files changed, 54 insertions(+), 25 deletions(-) diff --git a/lib/config/urls.dart b/lib/config/urls.dart index a6e5f98..fe898e3 100755 --- a/lib/config/urls.dart +++ b/lib/config/urls.dart @@ -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'; + } } diff --git a/lib/providers/test_results.dart b/lib/providers/test_results.dart index 7b9ea10..c8a9404 100755 --- a/lib/providers/test_results.dart +++ b/lib/providers/test_results.dart @@ -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 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(); } diff --git a/lib/widgets/TestResultScreens/Main/search_box.dart b/lib/widgets/TestResultScreens/Main/search_box.dart index 0113011..f612a8e 100755 --- a/lib/widgets/TestResultScreens/Main/search_box.dart +++ b/lib/widgets/TestResultScreens/Main/search_box.dart @@ -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(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(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,