Set search item by api

This commit is contained in:
hanie.khodkari
2025-05-10 20:13:37 +03:30
parent 14a6f06a43
commit ae6de355e7
5 changed files with 42 additions and 31 deletions
+4
View File
@@ -186,4 +186,8 @@ class Url {
static String searchCycles(String id) { static String searchCycles(String id) {
return '$baseUrl/Cycles?cycle_id=$id'; return '$baseUrl/Cycles?cycle_id=$id';
} }
static String searchItems(String value) {
return '$baseUrl/Items?name=$value';
}
} }
@@ -190,9 +190,6 @@ class _CycleResultScreenState extends State<CycleResultScreen> {
text: 'cycle', text: 'cycle',
onChanged: (value) { onChanged: (value) {
searchVal = value; searchVal = value;
// Provider.of<CyclesProvider>(context,
// listen: false)
// .search(value);
}, },
onTap: () async { onTap: () async {
var cycles = await Provider.of<CyclesProvider>( var cycles = await Provider.of<CyclesProvider>(
+9 -3
View File
@@ -98,6 +98,7 @@ class _ItemResultScreenState extends State<ItemResultScreen> {
final _media = MediaQuery.of(context); final _media = MediaQuery.of(context);
final double _deviceWidth = _media.size.width; final double _deviceWidth = _media.size.width;
final double _deviceBlockSize = _deviceWidth / 100; final double _deviceBlockSize = _deviceWidth / 100;
var searchVal;
return SafeArea( return SafeArea(
child: GestureDetector( child: GestureDetector(
onTap: () { onTap: () {
@@ -235,10 +236,15 @@ class _ItemResultScreenState extends State<ItemResultScreen> {
textInputType: TextInputType.visiblePassword, textInputType: TextInputType.visiblePassword,
text2: "Udi", text2: "Udi",
onChanged: (value) { onChanged: (value) {
Provider.of<ItemProvider>(context, listen: false) searchVal = value;
.search(value); },
onTap: () async {
var items = await Provider.of<ItemProvider>(
context,
listen: false);
items.setLoading();
await items.search(searchVal);
}, },
onTap: () {},
), ),
SizedBox( SizedBox(
height: 20, height: 20,
+1 -1
View File
@@ -121,7 +121,7 @@ class CyclesProvider extends ChangeNotifier {
void setLoading() { void setLoading() {
isloading = true; isloading = true;
// notifyListeners(); notifyListeners();
} }
bool isloadingButton = false; bool isloadingButton = false;
+28 -24
View File
@@ -51,7 +51,7 @@ class ItemProvider extends ChangeNotifier {
void setLoading() { void setLoading() {
isloading = true; isloading = true;
// notifyListeners(); notifyListeners();
} }
bool isloadingButton = false; bool isloadingButton = false;
@@ -244,29 +244,33 @@ class ItemProvider extends ChangeNotifier {
notifyListeners(); notifyListeners();
} }
void search(String value) { Future<void> search(String value) async {
items = []; items = [];
searchBoxValue = value; searchBoxValue = value;
originalItems!.forEach((result) { var response = await http.get(
if (result.udi Uri.parse(Url.searchItems(value)),
.toString() headers: {
.toLowerCase() 'Authorization': User.token,
.contains(searchBoxValue.toLowerCase()) || },
result.udi );
.toString()
.toUpperCase() var itemsData = json.decode(response.body);
.contains(searchBoxValue.toUpperCase()) ||
result.udi for (var item in itemsData['data']) {
.toString() items!.add(
.toLowerCase() ItemResultObject(
.contains(searchBoxValue.toUpperCase()) || name: item['name'],
result.udi id: item['id'].toString(),
.toString() size: item['size'].toString(),
.toUpperCase() userName: item['user'] != null ? item['user']['name'] : '',
.contains(searchBoxValue.toLowerCase())) { status: item['status'],
items!.add(result); udi: item['udi'],
} packageId:
}); item['package_id'] != null ? item['package_id'].toString() : "",
),
);
}
resetLoading();
notifyListeners(); notifyListeners();
} }
@@ -319,8 +323,8 @@ class ItemProvider extends ChangeNotifier {
); );
} }
pageNumber += 1; pageNumber += 1;
items = originalItems;
search(''); notifyListeners();
} }
Future<ItemDetailObject> showItemResult(String id) async { Future<ItemDetailObject> showItemResult(String id) async {