Set search for labels by api

This commit is contained in:
hanie.khodkari
2025-05-10 21:33:57 +03:30
parent 1352e36f87
commit f1ec0740e8
3 changed files with 55 additions and 10 deletions
+4
View File
@@ -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';
}
}
+27 -8
View File
@@ -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<void> 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<LabelDetailsObject> showLabelResult(String id) async {
@@ -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<LabelsProvider>(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<LabelsProvider>(
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,