Viewing version 2.0.0. Open the latest package page.

from_css_color

2.0.0

Creates Color instance from CSS color string according to https://drafts.csswg.org/css-color-3

Download archive

Readme

From CSS Color

A package that creates Flutter Color instances from CSS color strings according to CSS Color Module Level 3. Hex, RGB(A), HSL(A) and X11 keywords are supported.

Backwards conversion from Color to CSS color string is also available with toCssColor() extention method.

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';

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

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

Container(
  color: fromCssColor('rgb(100, 5, 32)'),
  // ...
)

Convert Color back to CSS string:

final color = const Color(0xFFFBAFBA);

color.toCssString(); // '#fbafba'

Check CSS color string correctness:

isCssColor('#ff00aa'); // true

Visit examples for more details.

Changelog

2.0.0

  • Migrate to null-safety.
  • Remove fromCSSColor()/isCSSColor(), which was deprecated since 1.2.0 in favor of fromCssColor()/isCssColor() to meet the effective Dart style guide.

1.2.0

  • Add isCssColor() function to check color string format correctness.

1.1.0

  • Add toCssColor() extension method to convert Color instance to CSS color string.

1.0.0

  • Add support for 4 (#rgba) and 8 (#rrggbbaa) digit hex colors.
  • Update versioning to stable after 3 months of usage in production (no breaking changes expected).

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.

Installing

export PUB_HOSTED_URL=https://pub.mirror.p-hatan.com
flutter pub add 'from_css_color:2.0.0'
pubspec.yaml
name: from_css_color
description: Creates Color instance from CSS color string according to https://drafts.csswg.org/css-color-3
version: 2.0.0
homepage: https://github.com/alex-myznikov/from_css_color.git

environment:
  sdk: ">=2.12.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter

dev_dependencies:
  flutter_test:
    sdk: flutter

Version history

VersionPublishedArchiveSHA-256
0.0.1Cached · Upstream SHA-256 matchedDownloadc42d75c8…c64f56
0.1.0Cached · Upstream SHA-256 matchedDownload62c6a364…439af0
0.1.1Cached · Upstream SHA-256 matchedDownloaddc52f291…fdc86a
1.0.0Cached · Upstream SHA-256 matchedDownload9ba8cee9…7c94ee
1.1.0Cached · Upstream SHA-256 matchedDownloada018fa1a…4d5da5
1.2.0Cached · Upstream SHA-256 matchedDownloadb1aa1563…b27870
2.0.0Cached · Upstream SHA-256 matchedDownload5e4d1795…d20823

Dependencies

flutter { "sdk": "flutter" }