PaletteGenerator class

A class to extract prominent colors from an image for use as user interface colors.

To create a new PaletteGenerator, use the asynchronous PaletteGenerator.fromImage static function.

A number of color paletteColors with different profiles are chosen from the image:

You may add your own target palette color types by supplying them to the targets parameter for PaletteGenerator.fromImage.

In addition, the population-sorted list of discovered colors is available, and a paletteColors list providing contrasting title text and body text colors for each palette color.

The palette is created using a color quantizer based on the Median-cut algorithm, but optimized for picking out distinct colors rather than representative colors.

The color space is represented as a 3-dimensional cube with each dimension being one component of an RGB image. The cube is then repeatedly divided until the color space is reduced to the requested number of colors. An average color is then generated from each cube.

What makes this different from a median-cut algorithm is that median-cut divides cubes so that all of the cubes have roughly the same population, where the quantizer that is used to create the palette divides cubes based on their color volume. This means that the color space is divided into distinct colors, rather than representative colors.

See also:

  • PaletteColor, to contain various pieces of metadata about a chosen palette color.
  • PaletteTarget, to be able to create your own target color types.
  • PaletteFilter, a function signature for filtering the allowed colors in the palette.

Constructors

PaletteGenerator.fromColors(List<PaletteColor> paletteColors, { List<PaletteTarget> targets })
Create a PaletteGenerator from a set of paletteColors and targets. [...]

Properties

colors → Iterable<Color>
Returns a list of colors in the paletteColors, sorted from most dominant to least dominant color.
read-only
darkMutedColor PaletteColor
Returns a muted and dark color from the palette. Might be null if an appropriate target color could not be found.
read-only
darkVibrantColor PaletteColor
Returns a dark and vibrant color from the palette. Might be null if an appropriate target color could not be found.
read-only
dominantColor PaletteColor
The dominant color (the color with the largest population).
read-only
lightMutedColor PaletteColor
Returns a muted and light color from the palette. Might be null if an appropriate target color could not be found.
read-only
lightVibrantColor PaletteColor
Returns a light and vibrant color from the palette. Might be null if an appropriate target color could not be found.
read-only
mutedColor PaletteColor
Returns a muted color from the palette. Might be null if an appropriate target color could not be found.
read-only
paletteColors → List<PaletteColor>
The list of PaletteColors that make up the palette, sorted from most dominant color to least dominant color.
final
selectedSwatches → Map<PaletteTarget, PaletteColor>
Provides a map of the selected paletteColors for each target in targets.
final
targets → List<PaletteTarget>
The list of targets that the palette uses for custom color selection. [...]
final
vibrantColor PaletteColor
Returns a vibrant color from the palette. Might be null if an appropriate target color could not be found.
read-only
hashCode → int
The hash code for this object. [...]
read-only, inherited
runtimeType → Type
A representation of the runtime type of the object.
read-only, inherited

Methods

debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node. [...]
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
toDiagnosticsNode({String name, DiagnosticsTreeStyle style }) → DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep. [...]
inherited
toString({DiagnosticLevel minLevel: DiagnosticLevel.debug }) → String
Returns a string representation of this object.
inherited
toStringShort() → String
A brief description of this object, usually just the runtimeType and the hashCode. [...]
inherited

Operators

operator ==(dynamic other) → bool
The equality operator. [...]
inherited

Static Methods

fromImage(Image image, { Rect region, int maximumColorCount, List<PaletteFilter> filters, List<PaletteTarget> targets }) → Future<PaletteGenerator>
Create a PaletteGenerator from an dart:ui.Image asynchronously. [...]
fromImageProvider(ImageProvider imageProvider, { Size size, Rect region, int maximumColorCount, List<PaletteFilter> filters, List<PaletteTarget> targets, Duration timeout: const Duration(seconds: 15) }) → Future<PaletteGenerator>
Create a PaletteGenerator from an ImageProvider, like FileImage, or AssetImage, asynchronously. [...]
fromUint8List(Uint8List imageData, { Rect region, int maximumColorCount, List<PaletteFilter> filters, List<PaletteTarget> targets }) → Future<PaletteGenerator>
Creates a PaletteGenerator from Uint8List image data asynchronously. [...]