搜索插件、代码仓与 APP 分类

插件详情v3.0.0

color

一个简单的 Dart 包,公开了一个 Color 类,可用于在多种色彩空间中创建、转换、修改和比较颜色。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
82.9万
喜欢数
36
Pub 分数
130

安装插件

flutter pub add color

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

color 包是一个轻量级的 Dart 库,提供了一个全面的 Color 类,用于在多个颜色空间中创建、操作和比较颜色。它支持颜色转换、混合和比较等操作,非常适合需要精确颜色处理的应用程序。该库设计简洁且性能优异,可无缝集成到所有主要平台上的 Flutter 项目中。该包在设计工具、主题系统和视觉应用中特别有用,这些场景下准确的颜色管理至关重要。

适合场景

  • 主题自定义
  • 配色方案生成
  • 视觉设计工具
  • 图像处理
  • UI 原型设计
  • 跨平台颜色一致性

主要特点

  • 支持多种色彩空间
  • 颜色转换工具
  • 颜色比较方法
  • 易于使用的 API
  • Platform-agnostic
  • 可扩展的颜色操作

适合对象

  • Flutter 开发者
  • 设计系统创建者
  • UI/UX 设计师
  • 颜色敏感的应用程序
  • 跨平台应用
  • 原型设计工具

使用建议

  • 仅限基本颜色操作
  • 无内置颜色选择器 UI
  • 需要手动管理色彩空间
  • 未针对复杂图像分析进行优化
  • 除了代码注释外,文档极少
  • 无运行时颜色验证

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Color

A simple Dart package exposing a Color class which can be used to create, convert, and compare colors.

Installation

  1. Add this to your package's pubspec.yaml file:
dependencies:
  color: any
  1. Get the package using your IDE's GUI or via command line with
$ pub get
  1. Import the color.dart file in your app
import 'package:color/color.dart';

Usage

Color objects can be constructed using any of a few available constructors.

To create a color from rgb values, call

Color rgbColor = new Color.rgb(192, 255, 238);
RgbColor rgbColor = new RgbColor(192, 255, 238);

Alternatively, a color can be created directly in a number of other color spaces.

RgbColor rgb = new RgbColor(192, 255, 238);
HexColor hex = new HexColor('c0ffee');
HslColor hsl = new HslColor(163.8, 100, 87.6);
XyzColor xyz = new XyzColor(72.931, 88.9, 94.204);
CielabColor cielab = new CielabColor(95.538, -23.02, 1.732);

Colors are immutable, and can be created using const constructors.

RgbColor rgb = const RgbColor(192, 255, 238);

Colors can be created directly from CSS3 color names.

RgbColor black = new RgbColor.name('black'); //factory constructor that returns a const RgbColor
RgbColor white = RgbColor.namedColors['black']; //directly reference the const RgbColor without the factory

Colors implementing the CssColorSpace interface can output a css string representation.

RgbColor rgb = new RgbColor(192, 255, 238);
HexColor hex = new HexColor('c0ffee');
HslColor hsl = new HslColor(163.8, 100, 87.6);
assert(rgb is CssColorSpace, true);
assert(hex is CssColorSpace, true);
assert(hsl is CssColorSpace, true);
print(rgb.toCssString()); //rgb(192, 255, 238)
print(hex.toCssString()); //#c0ffee
print(hsl.toCssString()); //hsl(163.8, 100.0%, 87.6%)

Colors can be compared using the == operator, which will evaluate to true if the two colors share identical rgb values after being rounded to integers.

assert(new Color.hex('c0ffee') == new Color.hex('c0ffee'));
assert(new Color.rgb('192, 255, 238') == new Color.hex('c0ffee'));

Colors can be converted from one color space to another by calling the appropriate toXXXColor method on them.

HslColor hsl = new RgbColor(192, 255, 238).toHslColor();

Colors can be altered using a ColorFilter, which will return a new color in the same color space as the input color with that filter applied to it.

RgbColor grey = ColorFilter.greyscale(new RgbColor(192, 255, 238));
HslColor sepia = ColorFilter.sepia(new HslColor(163.8, 100, 87.6));

所属分类

源码仓库

使用此插件的项目