google_weather_flutter 0.1.2 copy "google_weather_flutter: ^0.1.2" to clipboard
google_weather_flutter: ^0.1.2 copied to clipboard

A comprehensive Flutter plugin for the Google Weather API. Easily fetch current conditions, hourly and daily forecasts, and historical weather data for your apps.

Google Weather Flutter #

A Flutter plugin to fetch weather data from the Google Weather API.

pub package

Features #

  • Get current weather conditions.
  • Get hourly weather forecasts.
  • Get daily weather forecasts.
  • Get historical weather data.

Installation #

  1. Get an API Key:

  2. Add the dependency:

    dependencies:
      google_weather_flutter: ^0.1.0 # Replace with the latest version
    
  3. Install the package:

    flutter pub get
    

Usage #

Import the package and create an instance of WeatherService:

import 'package:google_weather_flutter/google_weather_flutter.dart';

final weatherService = WeatherService('YOUR_API_KEY');

Get Current Conditions #

try {
  final currentConditions = await weatherService.getCurrentConditions(
    latitude: 37.7749,
    longitude: -122.4194,
  );
  print('Temperature: ${currentConditions.temperature.value} ${currentConditions.temperature.units}');
  print('Condition: ${currentConditions.condition.text}');
} catch (e) {
  print('Error: $e');
}

Get Hourly Forecast #

try {
  final hourlyForecast = await weatherService.getHourlyForecast(
    latitude: 37.7749,
    longitude: -122.4194,
  );
  for (final forecast in hourlyForecast) {
    print('${forecast.time}: ${forecast.temperature.value}°${forecast.temperature.units}, ${forecast.condition.text}');
  }
} catch (e) {
  print('Error: $e');
}

Get Daily Forecast #

try {
  final dailyForecast = await weatherService.getDailyForecast(
    latitude: 37.7749,
    longitude: -122.4194,
  );
  for (final forecast in dailyForecast) {
    print('${forecast.date}: ${forecast.temperature.value}°${forecast.temperature.units}, ${forecast.condition.text}');
  }
} catch (e) {
  print('Error: $e');
}

Get Historical Data #

try {
  final history = await weatherService.getHourlyHistory(
    latitude: 37.7749,
    longitude: -122.4194,
    date: DateTime(2023, 10, 26),
  );
  for (final entry in history) {
    print('${entry.time}: ${entry.temperature.value}°${entry.temperature.units}');
  }
} catch (e) {
  print('Error: $e');
}

Documentation #

For more details on the available data and models, please refer to the Google Weather API documentation.

Contributing #

Contributions are welcome! Please feel free to submit a pull request or open an issue.

License #

This project is licensed under the MIT License - see the LICENSE file for details.

1
likes
160
points
86
downloads

Publisher

unverified uploader

Weekly Downloads

A comprehensive Flutter plugin for the Google Weather API. Easily fetch current conditions, hourly and daily forecasts, and historical weather data for your apps.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

dio, flutter, freezed_annotation, json_annotation

More

Packages that depend on google_weather_flutter