I am beginner coder and i dont understand how to resolve this error
Future<http.Response> fetchData(String query) async {
return http.post(
Uri.parse('https://laravelsyd-fypfinalver.herokuapp.com/getBusService'),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
},
body: {
jsonEncode({'bus_stop_id': busCode})
},
if (response.statusCode == 200) {
final List<dynamic> data = json.decode(response.body);
dataList = List<Map<String, dynamic>>.from(data);
setState(() {// Update the state to trigger a rebuild with the fetched data
dataList = List<Map<String, dynamic>>.from(data);
},);
} else {
print (response.statusCode);
}
);
}
error:
Expected an identifier.
Expected to find ‘)’
where should i put the if to check the status code? do i need to make new class?
i tried rearranging the code
2
Answers
try this code hope this will solve your problem.
Please try this code