Created
June 26, 2022 18:12
-
-
Save ulisseshen/7320517b7ab080a3f64188908f2c27f2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Future<Album> fetchAlbum() async { | |
final response = await http | |
.get(Uri.parse('https://jsonplaceholder.typicode.com/albums/1')); | |
if (response.statusCode == 200) { | |
// Se o servidor retornou uma resposta 200 OK, | |
// então analisa o JSON. | |
return Album.fromJson(jsonDecode(response.body)); | |
} else { | |
// Se o servidor não retornou uma resposta 200 OK, | |
// então lança uma exceção. | |
throw Exception('Failed to load album'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment