A Flutter app that fetches real-time weather data using RESTful APIs, implements Cubit state management, and dynamically adapts UI themes based on weather conditions. Built as part of Tharwat Samy's Flutter & Dart Development Course.
-
Dynamic UI:
-
Adaptive themes using
LinearGradientbased on weather conditions (e.g., sunny, rainy). -
Custom splash screen and app icons via
flutter_native_splashandflutter_launcher_icons.
-
-
API Integration:
-
RESTful API workflows using Dio (auto-JSON parsing).
-
Secure API key management and parameterized endpoints.
-
Model classes with null-safety and dual constructors (normal/named).
-
-
State Management:
-
Cubit for isolated business logic and UI separation.
-
States:
NoWeatherState,WeatherLoadedState,WeatherFailureState. -
BlocProviderandBlocBuilderfor reactive UI updates.
-
-
Error Handling:
-
try/catchblocks with custom exception messages. -
UI feedback for invalid cities or network errors.
-
-
Android Config:
- Internet permission and cleartext traffic enabled in
AndroidManifest.xml.
- Internet permission and cleartext traffic enabled in
| Home Screen | Search Screen | Weather Display |
|---|---|---|
![]() |
![]() |
![]() |
- Clone the repository:
git clone https://github.com/yourusername/Weather-App.git
- Install dependencies:
flutter pub get
- Run the app:
flutter run
- Endpoint: Base URL and API Key are defined as variables for easier maintenance.
final baseUrl = "https://api.weatherapi.com/v1"; final apiKey = "YOUR_API_KEY";
- Example Fetch:
// Inside Cubit try { final response = await Dio().get("$baseUrl/current.json?key=$apiKey&q=$city"); emit(WeatherLoadedState(weather: WeatherModel.fromJson(response.data))); } catch (e) { emit(WeatherFailureState(errorMsg: "City not found!")); }
- Model Class:
factory WeatherModel.fromJson(Map<String, dynamic> json) { return WeatherModel( temp: json['current']['temp_c'], condition: json['current']['condition']['text'], ); }
lib/
├── cubits/ # State management (e.g., weather_cubit.dart)
├── models/ # Data classes (e.g., weather_model.dart)
├── services/ # API services (e.g., weather_service.dart)
├── views/ # Screens (e.g., home_view.dart, search_view.dart)
└── main.dart # App entry point
-
Mastered dynamic UI construction in Flutter.
-
Explored multiple approaches to state management.
-
Gained insights into advanced API integration and error handling.
-
Improved debugging techniques and best practices for clean, maintainable code.
- Course Instructor: Tharwat Samy
- API Provider: WeatherAPI.com


