Files
wetterApp/lib/main.dart
T
2022-08-31 10:53:36 +02:00

59 lines
1.6 KiB
Dart

import 'package:flutter/material.dart';
import 'package:wetter/components/compact_weather_data.dart';
import 'package:wetter/models/daily_weather_model.dart';
import 'package:wetter/services/brightsky_api_service.dart';
void main() => runApp(const MyApp());
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
late Future<DailyWeatherModel> futureAlbum;
@override
void initState() {
super.initState();
futureAlbum = BrightSkyAPI.fetchForecast(DateTime.now());
}
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Fetch Data Example',
theme: ThemeData(
primarySwatch: Colors.blue,
textTheme: const TextTheme(
headline1: TextStyle(fontSize: 72.0, fontWeight: FontWeight.bold),
headline6: TextStyle(fontSize: 36.0, fontStyle: FontStyle.italic),
bodyText2: TextStyle(fontSize: 14.0, fontFamily: 'Hind'),
),
),
home: Scaffold(
appBar: AppBar(
title: const Text('Wetter heute in Harburg'),
),
body: Center(
child: FutureBuilder<DailyWeatherModel>(
future: futureAlbum,
builder: (context, snapshot) {
if (snapshot.hasData) {
return CompactWeatherData(snapshot.data!);
} else if (snapshot.hasError) {
return Text('${snapshot.error}');
}
// By default, show a loading spinner.
return const CircularProgressIndicator();
},
),
),
),
);
}
}