搜尋套件、儲存庫與 APP 分類

套件詳情v1.0.3

tinycolor

Flutter 顏色操作與轉換,來自 JS tinycolor2

近 30 天下載
580
喜歡數
51
Pub 分數
25

安裝套件

flutter pub add tinycolor

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

一個用於色彩操作與轉換的 Flutter 套件,源自流行的 JavaScript 庫 tinycolor2。它提供一整套工具,可解析、修改並在各種格式(如 HEX、RGB、HSL 和 HSV)之間轉換色彩。非常適合需要動態調整亮度、飽和度或色相的 UI,例如動態介面。此套件輕巧且設計為可無縫整合至需要進階色彩處理而無需外部依賴的 Flutter 應用中。

適用情境

  • 動態主題生成
  • 顏色對比度檢查
  • 色相/飽和度/亮度調整
  • 配色方案建立
  • UI 組件樣式

主要特色

  • 支援多種顏色格式
  • 亮度和飽和度調整
  • 顏色混合工具
  • HSL/HSV/RGB/HEX 轉換
  • 易用的顏色轉換API

適合對象

  • UI 設計師建構可自訂的主題
  • 需要即時顏色編輯的開發人員
  • 具有動態配色方案的應用程式
  • 注重可存取性的應用程式
  • 帶有色彩互動的創意工具

使用建議

  • 未提及特定於平台的優化
  • 除了基本用法外,文件有限
  • 不適用於大量圖像處理
  • 在複雜的工作流程中需要手動處理色彩空間
  • 無內建色彩選擇器元件

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

tinycolor

TinyColor is a small library for Flutter color manipulation and conversion

A port of tinycolor2 by Brian Grinstead

Getting Started

A tinycolor receives a Color as parameter.

import 'package:tinycolor/tinycolor.dart';

final TinyColor = TinyColor(Colors.green);

Now you can also use the package to extend the native Color class with all the same features, but simpler. To use extension update, make sure to change envieronment sdk version in pubspec like this: sdk: ">=2.6.0 <3.0.0"

From a Hex String

The package uses Pigment by Bregy Malpartida Ramos to convert strings to Color

TinyColor.fromString('#FE5567');
From RGB int values
TinyColor.fromRGB(r: 255, g: 255, b:255);
From HSL color
HslColor color = HslColor(h: 250, s: 57, l: 30);
TinyColor.fromHSL(color);
From HSV color
HSVColor color = HSVColor(h: 250, s: 57, v: 30);
TinyColor.fromHSV(color);
From Flutter's Color
TinyColor tinyColor = Colors.blue.toTinyColor();

Properties

color

Returns the flutter Color after operations

final Color color = TinyColor(Colors.white).color;

Methods

getBrightness

Returns the perceived brightness of a color, from 0-255, as defined by Web Content Accessibility Guidelines (Version 1.0).

TinyColor.fromString("#ffffff").getBrightness(); // 255
TinyColor.fromString("#000000").getBrightness(); // 0
// or with Color extension
Colors.grey.brightness;  // 127
isLight

Return a boolean indicating whether the color's perceived brightness is light.

TinyColor.fromString("#ffffff").isLight(); // true
TinyColor.fromString("#000000").isLight(); // false
// or with Color extension
Colors.white.isLight;  // true
isDark

Return a boolean indicating whether the color's perceived brightness is dark.

TinyColor.fromString("#ffffff").isDark(); // false
TinyColor.fromString("#000000").isDark(); // true
// or with Color extension
Colors.white.isDark;  // false
getLuminance

Return the perceived luminance of a color, a shorthand for flutter Color.computeLuminance

TinyColor.fromString("#ffffff").getLuminance();
// or with Color extension
Colors.white.luminance;
setAlpha

Sets the alpha value on the current color.

final color = TinyColor(Colors.red).setAlpha(10);
setOpacity

Sets the opacity value on the current color.

final color = TinyColor(Colors.red).setOpacity(0.5);

Color Modification

These methods manipulate the current color, and return it for chaining. For instance:

TinyColor(Colors.red).lighten().desaturate().color;
// or with Color extension
Colors.red.lighten().desaturate();
lighten

lighten: function(amount = 10) -> TinyColor. Lighten the color a given amount, from 0 to 100. Providing 100 will always return white.

TinyColor(Colors.red).lighten().color;
TinyColor(Colors.red).lighten(100).color;
// or with Color extension
Colors.red.lighten(50);
brighten

brighten: function(amount = 10) -> TinyColor. Brighten the color a given amount, from 0 to 100.

TinyColor(Colors.black).brighten().color;
// or with Color extension
Colors.black.brighten(50);
darken

darken: function(amount = 10) -> TinyColor. Darken the color a given amount, from 0 to 100. Providing 100 will always return black.

TinyColor(Colors.red).darken().color;
TinyColor(Colors.red).darken(100).color;
// or with Color extension
Colors.red.darken(50);
tint

Mix the color with pure white, from 0 to 100. Providing 0 will do nothing, providing 100 will always return white.

TinyColor(Color.red).tint().color;
TinyColor(Color.red).tint(100).color;
// or with Color extension
Colors.red.tint(50);
shade

Mix the color with pure black, from 0 to 100. Providing 0 will do nothing, providing 100 will always return black.

TinyColor(Colors.red).shade().color;
TinyColor(Colors.red).shade(100).color;
// or with Color extension
Colors.red.shade(50);
desaturate

desaturate: function(amount = 10) -> TinyColor. Desaturate the color a given amount, from 0 to 100. Providing 100 will is the same as calling greyscale.

TinyColor(Colors.red).desaturate().color;
TinyColor(Colors.red).desaturate(100).color;
// or with Color extension
Colors.red.desaturate(50);
saturate

saturate: function(amount = 10) -> TinyColor. Saturate the color a given amount, from 0 to 100.

TinyColor(Colors.red).saturate().color;
// or with Color extension
Colors.red.saturate(50);
greyscale

greyscale: function() -> TinyColor. Completely desaturates a color into greyscale. Same as calling desaturate(100).

TinyColor(Colors.red).greyscale().color;
// or with Color extension
Colors.red.greyscale;
spin

spin: function(amount = 0) -> TinyColor. Spin the hue a given amount, from -360 to 360. Calling with 0, 360, or -360 will do nothing (since it sets the hue back to what it was before).

TinyColor(Colors.red).spin(180).color;
// or with Color extension
Colors.red.spin(180);

// spin(0) and spin(360) do nothing
TinyColor(Colors.red).spin(0).color;
TinyColor(Colors.red).spin(360).color;
compliment

compliment: function() -> TinyColor. Returns the Complimentary Color for dynamic matching.

TinyColor(Colors.red).compliment().color;
// or with Color extension
Colors.red.compliment;
mix

mix: function(toColor, amount = 10) -> TinyColor. Blends the color with another color a given amount, from 0 - 100, default 50.

TinyColor(Colors.red).mix(TinyColor(Colors.yellow, 20)).color;
// or with Color extension
Colors.red.mix(Colors.yellow, 20);

Common operations

clone

clone: function() -> TinyColor. Instantiate a new TinyColor object with the same color. Any changes to the new one won't affect the old one.

final color1 = new TinyColor(Colors.red);
final color2 = color1.clone();
color2.setAlpha(20);

所屬分類

依賴

依賴清單 2 項

原始碼儲存庫

使用此套件的專案