Guest User

main.dart

a guest
Nov 27th, 2020
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 0.69 KB | None | 0 0
  1. import 'dart:async';
  2. import 'dart:convert';
  3. import 'package:flutter/material.dart';
  4. import 'package:http/http.dart' as http;
  5. import 'package:PROJECT/util/Launch.dart';
  6. import 'package:PROJECT/myapp.dart';
  7.  
  8. List<Object> jsonData;
  9. List<Launch> launchs = [];
  10.  
  11. Future<List<Launch>> fetchLaunch() async {
  12.   final http.Response response =
  13.       await http.get('https://api.spacexdata.com/v2/launches');
  14.  
  15.   if (response.statusCode == 200) {
  16.     jsonData = json.decode(response.body);
  17.     jsonData.forEach((element) {
  18.       launchs.add(Launch.fromJson(element));
  19.     });
  20.     return launchs;
  21.   } else {
  22.     throw Exception('Could not load data');
  23.   }
  24. }
  25.  
  26. void main() => runApp(MyApp());
  27.  
Advertisement
Add Comment
Please, Sign In to add comment