The Weather Forecast feature requires an OpenWeatherMap API key to function.
- Visit: OpenWeatherMap API
- Sign up: Create a free account (takes 30 seconds)
- Get key: Navigate to "API keys" section
- Copy: Your API key (starts with letters/numbers)
- Open file:
lib/services/weather_service.dart - Find line 7:
static const String _apiKey = 'YOUR_API_KEY_HERE';
- Replace with your key:
static const String _apiKey = 'your_actual_api_key_here';
- Save file and restart the app
- Run the app:
flutter run - Go to Farmer Dashboard
- Tap "Weather Forecast" in Quick Actions
- You should see real weather data! 🌤️
- Run the app:
flutter run - Navigate to Farmer Dashboard
- Tap on "Weather Forecast" in Quick Actions
- The app should now display real weather data
- Real-time Weather Data: Current temperature, humidity, wind speed, and pressure
- City Selection: Choose from popular farming cities in India
- Weather Icons: Visual weather representation
- Farming Recommendations: AI-powered suggestions based on weather conditions
- Error Handling: Graceful handling of network issues and API errors
The app includes these popular farming cities:
- Delhi, Mumbai, Bangalore, Chennai, Kolkata
- Hyderabad, Pune, Ahmedabad, Jaipur, Lucknow
- And many more...
- Free tier: 1,000 calls per day
- 60 calls per minute
- Perfect for development and small-scale usage
Error: "Invalid API key"
- Double-check your API key in
weather_service.dart - Ensure there are no extra spaces or characters
Error: "City not found"
- Try using the format: "City,Country" (e.g., "Delhi,IN")
- Check the city name spelling
Error: "No internet connection"
- Check your device's internet connection
- Ensure the app has network permissions
You can easily customize:
- Default city by changing
_defaultCityinWeatherService - Add more cities to
getPopularFarmingCities() - Modify farming recommendations in the modal