I wanna add some data or string to an array list strings in my rest api data, an it's not working. I don't know why. Here is my api data which i got from my api in my local server the json data is below here.
"hotels": [ {
"image": "http://0.0.0.0:8080/uploads/users/IWpEqUWxUxbWsmIoYfUX/95024057775943965869.jpg",
"bedPrice": "10",
"roomPrice": "30",
"rooms": "50",
"ac": "yes",
"address": "kaambo",
"latitude": "43.0890",
"laundry": "yes",
"name": "jaabir",
"location": "Bosaso",
"details": "Hosbitaalka Sixa Garoowe waxa ka howlgali doona 23/06/2022 Dr. Ahmed Bashe (abu-shafi) (FCPS MRCS-UK) oo ka socda Hosbitalka Shaafi Muqdisho kuna takhasusay qalliimada LAPAROSCOPY-ga sida Xameetida,Uur-kujirta,Eernada,Burooyinka IWM. Dr-ku wuxuu si joogta ah u imanayaa bil kasta insha allah. Wac: 7747373, 5065444, 5065333.Hosbitaalka Sixa Garoowe waxa ka howlgali doona 23/06/2022 Dr. Ahmed Bashe (abu-shafi) (FCPS MRCS-UK) oo ka socda Hosbitalka Shaafi Muqdisho kuna takhasusay qalliimada LAPAROSCOPY-ga sida Xameetida,Uur-kujirta,Eernada,Burooyinka IWM. Dr-ku wuxuu si joogta ah u imanayaa bil kasta insha allah. Wac: 7747373, 5065444, 5065333.Hosbitaalka Sixa Garoowe waxa ka howlgali doona 23/06/2022 Dr. Ahmed Bashe (abu-shafi) (FCPS MRCS-UK) oo ka socda Hosbitalka Shaafi Muqdisho kuna takhasusay qalliimada LAPAROSCOPY-ga sida Xameetida,Uur-kujirta,Eernada,Burooyinka IWM. Dr-ku wuxuu si joogta ah u imanayaa bil kasta insha allah. Wac: 7747373, 5065444, 5065333.",
"id": "456",
"beds": "100",
"internet": "yes",
"fastfood": "yes",
"longitude": "23.0890",
"images": [
"http://0.0.0.0:8080/uploads/users/IWpEqUWxUxbWsmIoYfUX/95024057775943965869.jpg",
"http://0.0.0.0:8080/uploads/users/IWpEqUWxUxbWsmIoYfUX/95024057775943965869.jpg",
"http://0.0.0.0:8080/uploads/users/IWpEqUWxUxbWsmIoYfUX/95024057775943965869.jpg"
],
"likedUsers": [
"HftAroebyiUhaKSmsyrc"
],
"adress": "laanta hawada"
}
]
And here is dart code.
_likeUser()async{
String api = "http://0.0.0.0:8080/path=hotels/456";
// this list from previous page _data['likedUsers'].toList();
List<String> likes = widget.likedUsers as List<String>;
if(widget.likedUser.contain(widget.currentUser){
setState((){ _isLiked = false;});
var likeRemoved = likes.remove(widget.currentUser);
await http.patch(Uri.parse(api), body: json.encode(<String, Object>{
"likedUsers": [likeRemoved]
});
}else{
var likeAdded = likes.add(widget.currentUser);
await http.patch(Uri.parse(api), body: json.encode(<String, Object>{
"likedUsers": [likeAdded]
});
setState((){
_isLiked = true;
});
}
}