weather_icons 2.0.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 89

weather_icons #

A Flutter library for using Weather Icons.

CircleCI branch GitHub Coverage Status

Pub GitHub release GitHub commits since latest release

Note: All of the icon data is auto-generated based on the latest release of Weather Icons.

Installation #

Add the dependency to your pubspec.yaml

dependencies:
  weather_icons: 1.0.x # Use the latest version

Usage #

The library exposes all of the Weather Icons as IconData. The naming convention is the same as the CSS names, minus the wi-, and all dashes replaced with underscores. It was named this way to match the default Icons class.

If you know which icon you need, you can use the provided constant icons. If you need a dynamic icon see below.

import 'package:flutter/material.dart';
import 'package:weather_icons/weather_icons.dart';

class MyWidget extends StatelessWidget {
  Widget build(BuildContext context) {
    return Icon(
      icon: BoxedIcon(WeatherIcons.day_sunny),
      onPressed: () {
          print("Foo");
      }
     );
  }
}

Note #

Because of how the icons exist in the font file, there will be some display issues when using a standard Icon widget. The icon will draw outside of its boundaries causing issues with layouts and padding, etc.

You can see an example of this in the example/ application.

In order to overcome this, the library exposes a widget called BoxedIcon. Which puts the icon into a 'box' which properly sets its height, and width. Preventing any of the out of boundary drawing.

Anywhere you can use Icon, you can swap it out for BoxedIcon.

class MyWidget extends StatelessWidget {
  Widget build(BuildContext context) {
    return Icon(
      icon: BoxedIcon(WeatherIcons.day_sunny),
      onPressed: () {}
     );
  }
}

See weather_icons_g.dart for all of the icons.

Dynamic #

If you need a dynamic icon at run-time, then you can use the included helper function for converting from the CSS style name to a IconData.

import 'package:flutter/material.dart';
import 'package:weather_icons/weather_icons.dart';

class WeatherDisplay extends StatelessWidget {
  final String weatherCode;

  WeatherDisplay(this.weatherCode);

  Widget build(BuildContext context) {
    return Container(
      child: Column(
        children: [
          BoxedIcon(
            WeatherIcons.fromString(
                weatherCode,
                // Fallback is optional, throws if not found, and not supplied.
                fallback: WeatherIcons.na
            ),
          ),
          Text("Icon for '$weatherCode'"),
        ],
      ),
    );
  }
}

Wind Direction #

The wind icon is a special icon, as it is one single icon value that is then rotated using CSS. To achieve a similar functionality you can use the WindIcon class.

The WindIcon's always use BoxedIcon.

Note: This means that WeatherIcons.wind will always be the North facing icon.

import 'package:flutter/material.dart';
import 'package:weather_icons/weather_icons.dart';

class EastlyWindWidget extends StatelessWidget {
  Widget build(BuildContext context) {
    return IconButton(
      // Display a Wind icon facing towards east
      icon: WindIcon.towards_e,
      onPressed: () { ... }
     );
  }
}

Since the Weather Icons support both 'towards' and 'from' wind directions, this library does as well.

Dynamic Wind Direction #

Just like the weather above, if your wind direction is dynamic you can create your own WindIcon.

import 'package:flutter/material.dart';
import 'package:weather_icons/weather_icons.dart';

class WindDirectionDisplay extends StatelessWidget {
  final double windDirectionDegree;

  WindDirectionDisplay(this.windDirectionDegree);

  Widget build(BuildContext context) {
    return Container(
      child: Column(
        children: [
          WindIcon(degree: windDirectionDegree),
          Text("Icon for wind @ $windDirectionDegree┬░"),
        ],
      ),
    );
  }
}

Note: The degree must be within the degrees of a compass/circle, so 0-360.

Time icons #

weather_icons also includes a helper for displaying the time icons.

// Manual hour
IconButton(
  icon: BoxedIcon(TimeIcon.iconFromHour(3)),
  onPressed: () { print("Displaying the third hour!"); }
);

// Using a DateTime instance
IconButton(
  icon: BoxedIcon(TimeIcon.iconFromDate(DateTime.now())),
  onPressed: () { print("Current hour"); }
);

// Creating your own Icon
BoxedIcon(
  icon: TimeIcon.fromHour(3),
  size: 60,
)

// Also using a DateTime
BoxedIcon(
  icon: TimeIcon.fromDate(DateTime.now()),
  size: 60,
)

Example #

A full example can be found in the example folder.

TODO #

  • Add support for the weather service mappings here

Contributing #

See CONTRIBUTING

License #

MIT License

Copyright (c) 2019 WorldTurtleMedia

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

2.0.0 (2019-07-20)

Bug Fixes #

  • timeicon: remove iconFromHour and iconFromDate (c19f4cb)
  • windicon: fix the rotation of the wind icons (3acacee)

Features #

  • boxedicon: add a widget for boxing the font icon (abb773d)
  • icons: add hidden directional icons (2766775)

BREAKING CHANGES #

  • timeicon: Remove two Time icon helper functions. In favour of creating a class instead of a function, so you can properly customize the icons.

example/README.md

Example for weather_icons #

An example showcasing the weather_icons package.

Getting Started #

# Download the repository
git clone https://github.com/worldturtlemedia/weather_icons

# Change into example folder
cd weather_icons/example

# Get the dependencies
flutter pub get

# Run the example
flutter run

TODO #

  • Showcase
    • Wind direction
  • Add to play store

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  weather_icons: ^2.0.0

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:weather_icons/weather_icons.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
78
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
89
Learn more about scoring.

We analyzed this package on Oct 18, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.1
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.4

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test