Giter VIP home page Giter VIP logo

weatherapi's Introduction

WeatherAPI

This package uses the WeatherAPI.com API to get weather information.

You can retrieve the weather data by supplying either geographical coordinates or the name of a city.

pub package

Installation (Flutter)

Add the package to your Flutter project by following these steps:

  1. Open your project's pubspec.yaml file.
  2. Locate the dependencies section in the file.
  3. Add weatherapi as a dependency. You can specify the version, too.
dependencies:
  flutter:
    sdk: flutter
  weatherapi: ^1.1.0
  1. After adding the dependency, save the pubspec.yaml file.
  2. Run flutter pub get in your terminal or use the relevant option in your IDE to fetch the new dependency.

For help on adding dependencies, view the pubspec documenation.

Permissions

This package does not require any permissions. However, if you intend to retrieve the device's geolocation, it is recommended to use the geolocator plugin.

Usage

First you need an API key from WeatherAPI.com, which can be acquired for free here. Then, import the library.

import 'package:weatherapi/weatherapi.dart';

Next, an instance of a WeatherRequest must be created using the obtained API key.

WeatherRequest wr = WeatherRequest('YOUR_API_KEY');

Alternatively, you can also specify a language for the weather results.

WeatherRequest wr = WeatherRequest('YOUR_API_KEY', language: Language.italian);

For all the supported languages, see the Languages section.

Realtime API (current weather)

For specific documentation on the Realtime API, see the WeatherAPI docs.

Realtime weather API allows a user to get up to date current weather information. The data is returned as a RealtimeWeather object.

The current weather can be queried either through a city name or through a latitude and longitude.

WeatherRequest wr = WeatherRequest('YOUR_API_KEY');

String cityName = 'Parma';

RealtimeWeather rw = await wr.getRealtimeWeatherByCityName(cityName);
WeatherRequest wr = WeatherRequest('YOUR_API_KEY');

double latitude = 44.8;
double longitude = 10.33;

RealtimeWeather rw = await wr.getRealtimeWeatherByLocation(latitude, longitude);

Forecast API

For specific documentation on the Forecast API, see the WeatherAPI docs.

Forecast weather API allows a user to get up to date current weather forecast. The data is returned as a ForecastWeather object.

The forecast weather can be queried either through a city name or a through latitude and longitude.

WeatherRequest wr = WeatherRequest('YOUR_API_KEY');

String cityName = 'Parma';

ForecastWeather fw = await wr.getForecastWeatherByCityName(cityName);
WeatherRequest wr = WeatherRequest('YOUR_API_KEY');

double latitude = 44.8;
double longitude = 10.33;

ForecastWeather fw = await wr.getForecastWeatherByLocation(latitude, longitude);

Search/Autocomplete API

For specific documentation on the Search/Autocomplete API, see the WeatherAPI docs.

Search/Autocomplete API allows a user to get a list of locations matching a provided search query. The data is returned as a SearchResults object.

The results can be queried either through a city name or through a latitude and longitude.

WeatherRequest wr = WeatherRequest('YOUR_API_KEY');

String cityName = 'Parma';

SearchResults sr = await wr.getResultsByCityName(cityName);

for (LocationResultData location in sr.locations) { /* ... */ }
WeatherRequest wr = WeatherRequest('YOUR_API_KEY');

double latitude = 44.8;
double longitude = 10.33;

SearchResults sr = await wr.getResultsByLocation(latitude, longitude);

for (LocationResultData location in sr.locations) { /* ... */ }

Exceptions

An exception will be thrown in the following cases:

  • The provided WeatherAPI.com key is invalid.
  • A bad response was given by the API.

Languages

The supported languages are as follows:

  • arabic
  • bengali
  • bulgarian
  • chineseSimplified
  • chineseTraditional
  • czech
  • danish
  • dutch
  • finnish
  • french
  • german
  • greek
  • hindi
  • hungarian
  • italian
  • japanese
  • javanese
  • korean
  • mandarin
  • marathi
  • polish
  • portuguese
  • punjabi
  • romanian
  • russian
  • serbian
  • sinhalese
  • slovak
  • spanish
  • swedish
  • tamil
  • telugu
  • turkish
  • ukrainian
  • urdu
  • vietnamese
  • wuShanghainese
  • xiang
  • yueCantonese
  • zulu

The default language is English.

weatherapi's People

Contributors

lorenzocopelli avatar

Watchers

 avatar

Forkers

alalawy esdotdev

weatherapi's Issues

Feature Request: Add full support for API Data

The Hour data in this pkg support only tempC, time and condition, while the Weather API returns much more:

{
    "time_epoch": 1715209200,
    "time": "2024-05-09 00:00",
    "temp_c": 11.6,
    "temp_f": 52.9,
    "is_day": 0,
    "condition": {
        "text": "Cloudy ",
        "icon": "//cdn.weatherapi.com/weather/64x64/night/119.png",
        "code": 1006
    },
    "wind_mph": 3.6,
    "wind_kph": 5.8,
    "wind_degree": 187,
    "wind_dir": "S",
    "pressure_mb": 1029.0,
    "pressure_in": 30.4,
    "precip_mm": 0.0,
    "precip_in": 0.0,
    "snow_cm": 0.0,
    "humidity": 89,
    "cloud": 63,
    "feelslike_c": 11.4,
    "feelslike_f": 52.5,
    "windchill_c": 11.4,
    "windchill_f": 52.5,
    "heatindex_c": 11.6,
    "heatindex_f": 52.9,
    "dewpoint_c": 9.9,
    "dewpoint_f": 49.7,
    "will_it_rain": 0,
    "chance_of_rain": 0,
    "will_it_snow": 0,
    "chance_of_snow": 0,
    "vis_km": 10.0,
    "vis_miles": 6.0,
    "gust_mph": 6.0,
    "gust_kph": 9.7,
    "uv": 1.0
},

Could you add support for these additional fields?

Error parsing data

When a double field has a value of 0, we see the following error:
type 'int' is not a subtype of type 'double?'

In my case, I had Hour.UV coming in as a 0.

I think you can avoid the error by doing something like this for your double fields:

jsonHour['uv']?.toDouble()

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.