dynamic_color
v1.9.0A Flutter package to create Material color schemes based on a platform's implementation of dynamic color.
Архив пакета: https://pubdev.letsnova.ru/api/archives/dynamic_color/1.9.0.tar.gz
dart pub add dynamic_colorREADME
dynamic_color
A Flutter package to create Material color schemes based on a platform's implementation of dynamic color. Currently supported platforms are:
- Android S+: user wallpaper color
- For color schemes from content color, use
ColorScheme.fromImageProvider
- For color schemes from content color, use
- Linux: GTK+ theme's
@theme_selected_bg_color - macOS: app accent color
- Windows: accent color or window/glass color
This package also supports color and color scheme harmonization.
Getting started
flutter pub add dynamic_color
import 'package:dynamic_color/dynamic_color.dart';
Features
Builder widget
DynamicColorBuilder is a stateful widget
that provides the device's dynamic colors in a light and dark ColorScheme.
DynamicColorBuilder(
builder: (ColorScheme? lightDynamic, ColorScheme? darkDynamic) {
return ...;
}
),
Plugin
Under the hood, DynamicColorBuilder uses a plugin to talk to the OS.
Color and color scheme harmonization
Harmonization makes adding and introducing new colors to your app more seamless by automatically shifting hue and chroma slightly so that a product's colors feel more cohesive with user colors.
This package provides two extension methods to accomplish this:
Color color = Colors.red;
// Shift's [color]'s hue towards the (dynamic) color scheme's primary color. This leaves the color recognizable while harmonizing it with a user's dynamic color.
harmonizedColor = color.harmonizeWith(colorScheme.primary);
// Does the same thing, for ColorScheme built-in semantic colors
harmonizedColorScheme = colorScheme.harmonized();
See harmonization.dart for details. Learn more about custom colors and harmonization on the Material 3 site.
Examples
See example/lib/complete_example.dart for obtaining dynamic colors, creating harmonized color schemes, and harmonizing custom colors.
See example/lib/accent_color.dart for obtaining the accent color on desktop.
All examples are part of this example app (source). To run the example app:
cd example
flutter run
Testing
For ease of testing, a separate package provides test utilities to mock dynamic colors. This allows you to test your app's behavior with different dynamic colors without having to change the device's wallpaper or accent color.
flutter pub add --dev dynamic_color_testing
import 'package:dynamic_color_testing/dynamic_color_testing.dart';
void main() {
// Reset for every test
setUp(() => DynamicColorTestingUtils.setMockDynamicColors());
testWidgets('Verify dynamic core palette is used ',
(WidgetTester tester) async {
DynamicColorTestingUtils.setMockDynamicColors(
corePalette: SampleCorePalettes.green,
);
// ...
});
}
See example/test/widget_test.dart for an example.
Development
The example app is hosted via GitHub pages. To update it:
cd example
flutter build web
История изменений
Changelog
- Populate the missing
ColorSchemesurface roles so dynamic color schemes render correctly (#574, #582, #649)
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
1.9.0 - 2025-08-07
Fixed
- Populate the missing
ColorSchemesurface roles so dynamic color schemes render correctly (#574, #582, #649)
Added
- Add support for AGP 9
Changed
- Migrate to Kotlin DSL in Android
- Update
compileSdktoflutter.compileSdkVersion - Update
minSdkto24 - Update
targetSdktoflutter.targetSdkVersion - Break out test utils from dynamic_color package into a separate package,
dynamic_color_testing - Update testing docs and examples to use
package:dynamic_color_testing/dynamic_color_testing.dart
1.8.1 - 2025-08-01
Fixed
- Revert moving flutter_test to dev_dependencies
1.8.0 - 2025-08-01
Changed
- Update
material_color_utilitiesupper constraint to0.13.0 - Update other dependencies
- Update
compileSdkVersionto34 - Fix lints
- Add Swift Package Manager compatibility #633.
Fixed
- Move flutter_test to dev_dependencies
1.7.0 - 2024-03-01
Changed
- Update
material_color_utilitiesto0.8.0
1.6.9 - 2023-12-16
Changed
- Use
DynamicColors.isDynamicColorAvailablefromcom.google.android.material:materialto verify if dynamic colors are available on Android
1.6.8 - 2023-10-17
Changed
- Broaden constraint for
material_color_utilitiesto support it until its1.0.0release
1.6.7 - 2023-09-15
Fixed
- Upgraded dependencies
1.6.6 - 2023-07-04
Changed
- Improved documentation for content-based color schemes
1.6.5 - 2023-05-15
Changed
- Broaden constraint for
material_color_utilitiesto support multiple Flutter SDK versions
1.6.4 - 2023-05-05
Changed
- Update constraint for
material_color_utilitiesto0.5.0
1.6.3 - 2023-04-04
Changed
- Update constraint for
material_color_utilitiesto0.3.0
1.6.2 - 2023-02-03
Added
- Added screenshots
1.6.1 - 2023-02-03
Changed
- Update pubspec
repository
1.6.0 - 2023-01-31
Added
- Add support for
outlineVariantandscrimcolors
Changed
- Update constraint for
material_color_utilitiesto0.2.0 - Update Flutter constraint
- Make return value of toColorScheme extension method non-nullable (#55)
1.5.4 - 2022-09-02
Changed
- Update constraint for Flutter SDK
1.5.3 - 2022-08-09
Changed
- Update constraint for
material_color_utilities
1.5.2 - 2022-08-02
Added
- Add support for DWM/Windows Aero's color (#50)
- Add support for GTK's accent color on Linux (#47)
- Add example tests
Changed
- Expand and improve README
- Rename
DynamicColorTestingUtils.setMockDynamicColors's argumentcolorPalettetocorePalette - Improve
DynamicColorBuildershort-circuiting logic if dynamic color is detected - Tweak debugging messages
1.4.0 - 2022-05-31
Added
- Add support for Windows' accent color (#43)
Changed
- Rename
DynamicColorPlugin.getControlAccentColortoDynamicColorPlugin.getAccentColor - Rename
DynamicColorTestingUtils.setMockDynamicColors's argumentcontrolAccentColortoaccentColor
1.3.0 - 2022-05-25
Added
- Add support for macOS' control accent color (#42)
- Rename
DynamicColorTestingUtils.setMockDynamicColors's argumentcolorstocolorPalette
- Rename
1.2.3 - 2022-05-23
Changed
- Tweak pubspec description
1.2.2 - 2022-04-25
Changed
- Update lower Flutter SDK bound
1.2.0 - 2022-03-24
Changed
- Improve examples: show how to create dynamic and fallback color schemes, and use harmonization for color schemes and custom colors
1.1.2 - 2022-02-15
Changed
- Move samples to their own library
1.1.1 - 2022-02-14
Changed
- Provide sample
CorePalettes and correspondingColorSchemes to test utils - Make the extension method which converts a
CorePaletteto aColorSchemepublic
1.1.0 - 2022-02-08
Changed
- Qualify builder parameters (
light=>lightDynamic,dark=>darkDynamic) for clarity
1.0.1 - 2022-02-02
Changed
- Polish README and examples
1.0.0 - 2022-02-02
Added
- Add missing semantic colors to harmonization from updated m3 color scheme
Changed
DynamicColorBuilder'sbuildernow provides a light and darkColorSchemerather than aCorePalette- Advanced users can still obtain the palette with
DynamicColorPlugin.getCorePalette()
- Advanced users can still obtain the palette with
0.1.0 - 2021-10-29
Added
- Create
CorePaletteandTonalPaletteclasses - Create
DynamicColorPluginplugin - Create convenience
DynamicColorBuilderwidget - Create
ColorHarmonizationandColorSchemeHarmonizationextensions
