Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'dart:async';
- import 'dart:convert';
- import 'package:flutter/material.dart';
- import 'package:http/http.dart' as http;
- import 'package:PROJECT/util/Launch.dart';
- import 'package:PROJECT/myapp.dart';
- List<Object> jsonData;
- List<Launch> launchs = [];
- Future<List<Launch>> fetchLaunch() async {
- final http.Response response =
- await http.get('https://api.spacexdata.com/v2/launches');
- if (response.statusCode == 200) {
- jsonData = json.decode(response.body);
- jsonData.forEach((element) {
- launchs.add(Launch.fromJson(element));
- });
- return launchs;
- } else {
- throw Exception('Could not load data');
- }
- }
- void main() => runApp(MyApp());
Advertisement
Add Comment
Please, Sign In to add comment