Created
November 22, 2022 04:06
-
-
Save LucasFebatis/b689210a38e3e1743c7466185c37c69c to your computer and use it in GitHub Desktop.
Realizando requisição em Flutter
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
FutureBuilder<List<SuperHero>>( | |
future: futureSuperHeros, | |
builder: (context, snapshot) { | |
if (snapshot.hasData) { | |
return buildList(snapshot.requireData); | |
} else if (snapshot.hasError) { | |
return Text('${snapshot.error}'); | |
} | |
return const CircularProgressIndicator(); | |
}, | |
), |
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
class SuperHeroApi { | |
Future<List<SuperHero>> fetchAllSuperHero() async { | |
final response = await http | |
.get(Uri.parse('https://olamundo.com')); | |
if (response.statusCode == 200) { | |
Iterable l = jsonDecode(response.body); | |
return List<SuperHero>.from(l.map((model)=> SuperHero.fromJson(model))); | |
// return SuperHero.fromJson(jsonDecode(response.body)); | |
} else { | |
throw Exception('Failed to load super hero'); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment