mirror of
https://github.com/nisrulz/flutter-examples.git
synced 2025-05-20 22:46:24 +08:00
edit http status to catch and print any error belongs to the statusCode (#84)
This commit is contained in:

committed by
GitHub

parent
d409e4a19c
commit
510d27d1e7
@ -35,8 +35,15 @@ class MyGetHttpDataState extends State<MyGetHttpData> {
|
||||
setState(() {
|
||||
// Get the JSON data
|
||||
var dataConvertedToJSON = json.decode(response.body);
|
||||
try{
|
||||
if(dataConvertedToJSON.statusCode == 200){
|
||||
data = dataConvertedToJSON['results'];
|
||||
}
|
||||
}
|
||||
catch(e){
|
||||
print(dataConvertedToJSON.statusCode);
|
||||
}
|
||||
// Extract the required part and assign it to the global variable named data
|
||||
data = dataConvertedToJSON['results'];
|
||||
});
|
||||
|
||||
return "Successfull";
|
||||
|
Reference in New Issue
Block a user