What builder widget is best for loading weather data?
FutureBuilder handles the async API call and different states (loading, error, data).
Build a weather app with API integration
You can read this lesson publicly. Sign in to unlock exercises, quiz, and FX progress tracking.
Having trouble? AI is here to help
Ask context-aware questions about this lesson. Free plan: 5 questions/day. Upgrade to Premium for higher daily limits.
Use the AI button at the bottom of the screen
This project teaches you how to work with real APIs and display live data in a beautiful layout. You will build a weather application that fetches current weather conditions from the OpenWeatherMap API, displays temperature, humidity, and wind speed, handles loading and error states gracefully, and lets users search for any city. This covers HTTP requests, JSON parsing, model classes, FutureBuilder, error handling, and polished UI design all in one project.
Features to build:
1// Weather model2class Weather {3final String city;4final double temperature;5final String condition;6final String icon;7final double humidity;8final double windSpeed;910Weather({11required this.city,12required this.temperature,13required this.condition,14required this.icon,15required this.humidity,16required this.windSpeed,17});1819factory Weather.fromJson(Map<String, dynamic> json) {20return Weather(21city: json['name'],22temperature: json['main']['temp'].toDouble(),23condition: json['weather'][0]['main'],24icon: json['weather'][0]['icon'],25humidity: json['main']['humidity'].toDouble(),26windSpeed: json['wind']['speed'].toDouble(),27);28}29}3031// Weather service32class WeatherService {33static const apiKey = 'YOUR_API_KEY';34static const baseUrl = 'https://api.openweathermap.org/data/2.5';3536Future<Weather> getWeather(String city) async {37final url = '$baseUrl/weather?q=$city&appid=$apiKey&units=metric';38final response = await http.get(Uri.parse(url));3940if (response.statusCode == 200) {41return Weather.fromJson(jsonDecode(response.body));42} else {43throw Exception('Failed to load weather');44}45}46}
The WeatherCard widget takes a Weather model and displays it in a clean card layout. The city name goes at the top, followed by the weather icon from the API alongside a large temperature reading. Below that, a row of secondary info shows humidity and wind speed. This kind of structured layout makes the data easy to read at a glance.
1class WeatherCard extends StatelessWidget {2final Weather weather;34const WeatherCard({required this.weather});56@override7Widget build(BuildContext context) {8return Card(9margin: EdgeInsets.all(16),10child: Padding(11padding: EdgeInsets.all(24),12child: Column(13children: [14Text(15weather.city,16style: Theme.of(context).textTheme.headlineMedium,17),18SizedBox(height: 16),19Row(20mainAxisAlignment: MainAxisAlignment.center,21children: [22Image.network(23'https://openweathermap.org/img/wn/${weather.icon}@2x.png',24width: 80,25),26Text(27'${weather.temperature.round()}°C',28style: TextStyle(fontSize: 48, fontWeight: FontWeight.bold),29),30],31),32Text(weather.condition, style: TextStyle(fontSize: 20)),33SizedBox(height: 24),34Row(35mainAxisAlignment: MainAxisAlignment.spaceAround,36children: [37_buildInfoItem(Icons.water_drop, '${weather.humidity}%', 'Humidity'),38_buildInfoItem(Icons.air, '${weather.windSpeed} m/s', 'Wind'),39],40),41],42),43),44);45}46}
Real weather apps fail more often from network and API issues than UI bugs. Build a reliability plan first:
When reliability is explicit in your architecture, your app feels professional even when the network is unstable.
Build a weather app with API integration. Networking lessons teach your app how to request, store, and display remote data safely.
Connect each concept to real app features you can build.
Always model loading, success, empty, and error states before hooking the UI.
Most production bugs happen at data boundaries: slow networks, bad payloads, and error states.
Repository and service boundaries keep networking logic testable and replaceable.
As your app grows, keep UI, state, and data responsibilities separate so each part stays testable and easier to modify.
FutureBuilder handles the async API call and different states (loading, error, data).
The http package (or dio for advanced features) is the standard way to make HTTP requests in Flutter.
jsonDecode from dart:convert parses a JSON string into a Dart Map or List.
Always check response.statusCode == 200 before parsing data. Handle errors for other status codes.
Something seems incorrect, unclear, or missing? Let us know.
FlutterCraft editorial lessons are reviewed by experienced Flutter developers and updated to stay aligned with modern Flutter and Dart best practices.
Reference docs: Flutter Documentation, Dart Language Tour, and official package documentation where relevant.
Sign in to continue with exercises and quiz for this lesson.
Sign In to Continue