A Flutter weather application that allows users to search for current weather conditions in any city worldwide using the OpenWeatherMap API. Log in to OpenWeatherMap to access your API Key and add it to main.dart.
This app provides real-time weather information with a clean, modern UI featuring:
- City Search: Enter any city name to get current weather data
- Weather Display: View temperature, weather conditions, and descriptive icons
- Detailed Metrics: See feels-like temperature, humidity, and wind speed
- Visual Design: Gradient background with Material 3 design elements
- Real-time weather data from OpenWeatherMap API
- Temperature display in Celsius
- Weather condition icons (sun, clouds, rain, snow, etc.)
- Humidity and wind speed information
- Error handling for invalid cities and network issues
- Flutter SDK ^3.9.2
- Dart SDK ^3.9.2
- Clone the repository
- Install dependencies:
flutter pub get
- Run the app:
flutter run
lib/
├── main.dart # Main app and UI components
├── services/
│ └── weather_service.dart # API service with HTTP client
└── utils/
└── weather_icon_helper.dart # Weather icon mapping utility
test/
├── services/
│ └── weather_service_test.dart # WeatherService unit tests
├── utils/
│ └── weather_icon_helper_test.dart # Icon helper unit tests
└── widgets/
└── weather_home_page_test.dart # Widget tests
The app includes comprehensive unit and widget tests using Flutter's testing framework and mocktail for mocking.
flutter test| Test Suite | Tests | Description |
|---|---|---|
| WeatherService | 11 | API calls, error handling, URL construction |
| WeatherIconHelper | 12 | Icon mapping for all weather conditions |
| WeatherHomePage | 13 | Widget rendering and user interactions |
| Total | 36 |
- Empty city validation
- Successful API response (200 status)
- City not found handling (404 status)
- Server error handling (500 status)
- Network exception handling
- Correct API URL construction
- City names with spaces
- All weather conditions (clear, clouds, rain, drizzle, thunderstorm, snow, mist, fog)
- Null and empty input handling
- Case-insensitive matching
- App renders correctly
- Search field displays and accepts input
- Initial prompt message shown
- AppBar configuration
- Gradient background rendering
- Layout structure verification
Production:
http: ^1.6.0- HTTP client for API requestscupertino_icons: ^1.0.8- iOS style icons
Development:
flutter_test- Flutter testing frameworkmocktail: ^1.0.4- Mocking library for testsflutter_lints: ^5.0.0- Linting rules
This app uses the OpenWeatherMap API to fetch weather data.