Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Future< SomeJsonResponse > fetchLinks() async {
- http.Response uriResponse = await client.get("google.com");
- if (uriResponse.statusCode == 200) {
- return parseRes(uriResponse.body);
- } else {
- throw Exception("Что-то пошло не так");
- }
- FutureBuilder<SomeJsonResponse>(
- future: ApiService.instance.fetchLinks(),
- builder: (context, snapshot) {
- switch (snapshot.connectionState) {
- case ConnectionState.none:
- return Text('Press button to start.');
- case ConnectionState.active:
- case ConnectionState.waiting:
- return Text('Awaiting result...');
- case ConnectionState.done:
- if (snapshot.hasError) return Text('Error: ${snapshot.error}');
- return Text(snapshot.data.title);
- }
- return Container(); // unreachable
- },
- ),
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement