Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 0.92 KB | None | 0 0
  1.  
  2.   Future< SomeJsonResponse > fetchLinks() async {
  3.         http.Response uriResponse = await client.get("google.com");
  4.     if (uriResponse.statusCode == 200) {
  5.       return parseRes(uriResponse.body);
  6.     } else {
  7.       throw Exception("Что-то пошло не так");
  8.     }
  9.  
  10.  
  11. FutureBuilder<SomeJsonResponse>(
  12.         future: ApiService.instance.fetchLinks(),
  13.         builder: (context, snapshot) {
  14.           switch (snapshot.connectionState) {
  15.             case ConnectionState.none:
  16.               return Text('Press button to start.');
  17.             case ConnectionState.active:
  18.             case ConnectionState.waiting:
  19.               return Text('Awaiting result...');
  20.             case ConnectionState.done:
  21.               if (snapshot.hasError) return Text('Error: ${snapshot.error}');
  22.               return Text(snapshot.data.title);
  23.           }
  24.           return Container(); // unreachable
  25.         },
  26.       ),
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement