Guest User

Services.dart

a guest
Nov 27th, 2020
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 0.57 KB | None | 0 0
  1. import 'package:http/http.dart' as http;
  2. import 'util/Launch.dart';
  3.  
  4. class Services {
  5.   static const String url = 'https://api.spacexdata.com/v2/launches';
  6.   final launch = launchFromJson(url);
  7.   static Future<List<Launch>> getLaunches() async {
  8.     try {
  9.       final response = await http.get(url);
  10.       if (response.statusCode == 200) {
  11.         final List<Launch> listOfLaunches = launchFromJson(response.body);
  12.         return listOfLaunches;
  13.       } else {
  14.         return List<Launch>();
  15.       }
  16.     } catch (e) {
  17.       return List<Launch>();
  18.     }
  19.   }
  20. }
  21.  
Advertisement
Add Comment
Please, Sign In to add comment