Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'dart:async';
- import 'package:flutter/material.dart';
- import 'package:obligatorisk_opgave/util/Launch.dart';
- import 'package:obligatorisk_opgave/Services.dart';
- import 'package:obligatorisk_opgave/main.dart';
- class MyApp extends StatefulWidget {
- MyApp({Key key}) : super(key: key);
- @override
- _MyAppState createState() => _MyAppState();
- }
- class _MyAppState extends State<MyApp> {
- Future<Launch> futureLaunch;
- List<Launch> launches = List<Launch>();
- bool isLoading = false;
- @override
- void initState() {
- super.initState();
- futureLaunch = fetchLaunch() as Future<Launch>;
- isLoading = true;
- Services.getLaunches().then((list) {
- setState(() {
- launches = list;
- isLoading = false;
- });
- });
- }
- @override
- Widget build(BuildContext context) {
- return MaterialApp(
- title: 'SpaceX',
- theme: ThemeData(
- primarySwatch: Colors.blue,
- ),
- home: Scaffold(
- appBar: AppBar(
- title: Text(isLoading ? 'Loading...' : 'SpaceX Launches'),
- centerTitle: true,
- ),
- body: Center(
- child: FutureBuilder<Launch>(
- future: futureLaunch,
- builder: (context, snapshot) {
- if (snapshot.hasData) {
- return Text(snapshot.data.missionName);
- } else if (snapshot.hasError) {
- return Text('${snapshot.error}');
- }
- return CircularProgressIndicator();
- },
- ))
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment