palette_generator_plus 1.0.0
palette_generator_plus: ^1.0.0 copied to clipboard
Extract prominent colors from images. A maintained palette_generator successor.
palette_generator_plus #
The maintained, modernized successor to Flutter's discontinued
palette_generator package
(officially discontinued in
flutter/flutter#162963, which
invited a sustainable community fork).
palette_generator_plus extracts the prominent colors โ dominant, vibrant,
muted, and their light/dark variants โ from any image, and adds the modern
capabilities the original never had:
- ๐งต Isolate-based extraction by default, with a transparent main-thread fallback on the web.
- ๐จ Pluggable quantizers โ a
material_color_utilities-backedCelebiQuantizer(default) and the original median-cutLegacyQuantizerfor byte-identical legacy output. - ๐งฉ One-call Material 3 bridge โ turn any image into a complete
ColorScheme. - โฟ WCAG-accessible text colors โ exact WCAG 2.1 contrast math and helpers.
- ๐ Drop-in compatible โ the entire original public API is preserved.
Migrating from palette_generator #
Migration is a single import-line change. Every existing class, method, parameter, and getter keeps the same name and a compatible signature:
- import 'package:palette_generator/palette_generator.dart';
+ import 'package:palette_generator_plus/palette_generator_plus.dart';
Your existing code compiles and runs unchanged. Everything else this package adds is strictly additive.
Note: colors are extracted with the modern
CelebiQuantizerby default. For output that is byte-identical topalette_generator 0.3.3+7, passquantizer: const LegacyQuantizer()to anyfrom*constructor.
Why this package? #
| Capability | palette_generator_plus |
palette_generator (discontinued) |
ColorScheme.fromImageProvider |
|---|---|---|---|
| Maintained | โ | โ | โ |
| Raw swatches + population counts | โ | โ | โ |
| Named targets (vibrant / muted / โฆ) | โ | โ | โ |
Drop-in API of palette_generator |
โ | โ | โ |
| Isolate extraction (off the UI thread) | โ | โ | โ |
| Pluggable quantizer | โ | โ | โ |
Material 3 ColorScheme in one call |
โ | โ | โ |
| WCAG contrast helpers | โ | โ | โ |
| Modern color API, zero deprecations | โ | โ | โ |
| All 6 platforms | โ | โ | โ |
Quickstart #
Add the dependency:
dependencies:
palette_generator_plus: ^1.0.0
Basic extraction #
import 'package:palette_generator_plus/palette_generator_plus.dart';
final PaletteGenerator palette = await PaletteGenerator.fromImageProvider(
const AssetImage('assets/landscape.png'),
);
final Color? dominant = palette.dominantColor?.color;
for (final PaletteColor swatch in palette.paletteColors) {
print('${swatch.color} occurs ${swatch.population} times');
}
Named swatches #
final Color? vibrant = palette.vibrantColor?.color;
final Color? darkMuted = palette.darkMutedColor?.color;
final Color? lightVibrant = palette.lightVibrantColor?.color;
Material 3 ColorScheme in one call #
final ColorScheme scheme = palette.toColorScheme(
brightness: Brightness.dark,
);
final ThemeData theme = ThemeData.from(colorScheme: scheme);
// Or just grab the seed for ThemeData(colorSchemeSeed: ...):
final Color seed = palette.seedColor;
WCAG-accessible text colors #
// A fully-opaque black or white that reads accessibly on the swatch:
final Color textColor = palette.dominantColor!.accessibleOnColor(
level: WcagLevel.aaa,
);
// Or use the standalone helpers on any color:
final double ratio = contrastRatio(Colors.black, Colors.white); // 21.0
final Color onSurface = wcagTextColor(scheme.surface);
Choose the quantizer / run on the main thread #
final PaletteGenerator legacy = await PaletteGenerator.fromImageProvider(
const AssetImage('assets/landscape.png'),
quantizer: const LegacyQuantizer(), // byte-identical to the original
runInIsolate: false, // opt out of the background isolate
);
See the example/ directory for a complete app (it also runs as a
live web demo via flutter build web).
API overview #
| Symbol | Description |
|---|---|
PaletteGenerator.fromImage / .fromImageProvider / .fromByteData |
Extract a palette from an image. |
PaletteColor |
A swatch: color, population, titleTextColor, bodyTextColor, accessibleOnColor. |
PaletteTarget |
A tunable target in HSL space; predefined vibrant, muted, etc. |
PaletteFilter / avoidRedBlackWhitePaletteFilter |
Filter which colors are eligible. |
Quantizer / CelebiQuantizer / LegacyQuantizer |
Pluggable color-reduction algorithms. |
PaletteGenerator.seedColor / .toColorScheme() |
Material 3 bridge. |
contrastRatio / wcagTextColor / WcagLevel |
WCAG 2.1 accessibility helpers. |
EncodedImage |
Raw RGBA pixel data for fromByteData. |
Compatibility #
Pure Dart/Flutter โ no platform channels or native code. Runs on Android, iOS,
web, Windows, macOS and Linux. On the web, where dart:isolate is
unavailable, runInIsolate transparently falls back to the main thread; the
result is identical regardless of where it runs.
Acknowledgements #
This package is a community-maintained fork and successor of the discontinued
palette_generator package, last
published as palette_generator 0.3.3+7, originally created by The Flutter
Authors / Google and distributed under the BSD-3-Clause license.
Files derived from the original retain their original copyright headers; see
LICENSE and NOTICE. The discontinuation and community
fork invitation are tracked in
flutter/flutter#162960 and
flutter/flutter#162963.
Color science is powered by
material_color_utilities,
the same library behind Flutter's dynamic color and Android's Material You.
Contributing #
Issues and pull requests are welcome at
https://github.com/KEREM-BAS/palette_generator_plus. Please run
dart format ., flutter analyze and flutter test before submitting.
License #
BSD-3-Clause. See LICENSE.