diff --git a/lib/config/urls.dart b/lib/config/urls.dart index e4cd8dc..6513056 100755 --- a/lib/config/urls.dart +++ b/lib/config/urls.dart @@ -202,4 +202,8 @@ class Url { static String searchMyPackages(String value) { return '$baseUrl/MyPackages?name=$value'; } + + static String searchLabels(String value) { + return '$baseUrl/Labels?package_name=$value'; + } } diff --git a/lib/providers/labels.dart b/lib/providers/labels.dart index cb323e5..4522341 100755 --- a/lib/providers/labels.dart +++ b/lib/providers/labels.dart @@ -58,7 +58,7 @@ class LabelsProvider extends ChangeNotifier { void setLoading() { isloading = true; - // notifyListeners(); + notifyListeners(); } bool isloadingButton = false; @@ -223,14 +223,32 @@ class LabelsProvider extends ChangeNotifier { notifyListeners(); } - void search(String value) { + Future search(String value) async { items = []; searchBoxValue = value; - originalItems!.forEach((result) { - if (result.packageName.toString().contains(searchBoxValue)) { - items!.add(result); - } - }); + + var response = await http.get( + Uri.parse(Url.searchLabels(value)), + headers: { + 'Authorization': User.token, + }, + ); + + var testResultData = json.decode(response.body); + for (var item in testResultData['data']) { + items!.add( + LabelResultObject( + expireDate: item['expire_date'], + id: item['id'].toString(), + packageName: item['package'] != null + ? item['package']['name'].toString() + : ' ', + packageId: + item['package'] != null ? item['package']['id'].toString() : ' ', + ), + ); + } + resetLoading(); notifyListeners(); } @@ -281,7 +299,8 @@ class LabelsProvider extends ChangeNotifier { ); } pageNumber += 1; - search(''); + items = originalItems; + notifyListeners(); } Future showLabelResult(String id) async { diff --git a/lib/widgets/LabelScreens/Result/search_box.dart b/lib/widgets/LabelScreens/Result/search_box.dart index bdc018d..bdbc7da 100755 --- a/lib/widgets/LabelScreens/Result/search_box.dart +++ b/lib/widgets/LabelScreens/Result/search_box.dart @@ -17,12 +17,13 @@ class LabelSearchBox extends StatelessWidget { @override Widget build(BuildContext context) { + var searchVal; return TextField( onEditingComplete: () { FocusScope.of(context).unfocus(); }, - onChanged: (value) { - Provider.of(context, listen: false).search(value); + onChanged: (value) async { + searchVal = value; }, controller: searchCTRL, decoration: InputDecoration( @@ -37,6 +38,27 @@ class LabelSearchBox extends StatelessWidget { labelText: 'Search by package name', isDense: true, contentPadding: EdgeInsets.symmetric(vertical: 2, horizontal: 3), + suffixIcon: InkWell( + onTap: () async { + var labels = await Provider.of( + context, + listen: false); + labels.setLoading(); + await labels.search(searchVal); + + }, + child: Container( + margin: EdgeInsets.all(5), + decoration: BoxDecoration( + shape: BoxShape.circle, + color: Colors.black, + ), + child: Icon( + Icons.input, + color: Colors.white, + ), + ), + ), ), style: TextStyle( fontWeight: FontWeight.w700,