from_css_color 0.1.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 74

From CSS Color #

A package that creates Color instances from CSS color strings according to https://drafts.csswg.org/css-color-3. Hex, RGB(A), HSL(A) and X11 keywords are supported.

Usage #

To use this plugin, add from_css_color as a dependency in your pubspec.yaml file.

Example #

Import the library.

import 'package:from_css_color/from_css_color.dart';

And use it anywhere you want to create a Color from CSS color definition format:

Container(
  color: fromCSSColor('#ff00aa'),
  // ...
)

Visit examples for more details.

0.1.1 #

  • Update readme and file formatting.

0.1.0 #

  • Support for 'transparent' color keyword.
  • Support for hsl/hsla colors.

0.0.1 #

  • Support for 3 and 6 digit hex colors.
  • Support for rgb/rgba colors.
  • Support for X11 keywords.

example/from_css_color.dart

import 'package:from_css_color/from_css_color.dart';

// create Color from hex
var hex = fromCSSColor('#fbafba'); // Color(0xFFFBAFBA)
var hexShort = fromCSSColor('#fba'); // Color(0xFFFFBBAA)

// or from rgb
var rgb = fromCSSColor('rgb(100, 5, 32)'); // Color(0xFF640520)
var rgbWithPercents = fromCSSColor('rgb(110%, 0%, 0%)'); //Color(0xFFFF0000)
var rgba = fromCSSColor('rgb(110%, 0%, 0%, 0.5)'); //Color(0x7FFF0000)

// or even from hsl
var hsl = fromCSSColor('hsl(100,50%,10%)'); // Color(0xFF15260C)
var hsla = fromCSSColor('hsla(-120,100%,50%, .5)'); // Color(0x7F0000FF)

// and a list of X11 keywords is supported
var navy = fromCSSColor('navy'); // Color(0xFF000080)
var violet = fromCSSColor('violet'); // Color(0xFFEE82EE)
var transparent = fromCSSColor('transparent'); // Color(0x00000000)

Use this package as a library

1. Depend on it

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


dependencies:
  from_css_color: ^0.1.1

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:from_css_color/from_css_color.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
48
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]
74
Learn more about scoring.

We analyzed this package on Jul 11, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.15
  • Flutter: 1.17.5

Analysis suggestions

Package not compatible with SDK dart

Because:

  • from_css_color that is a package requiring null.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8 1.2.2
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety
Dev dependencies
flutter_test