dynamic_color_testing 0.1.0 copy "dynamic_color_testing: ^0.1.0" to clipboard
dynamic_color_testing: ^0.1.0 copied to clipboard

A Flutter package to support testing dynamic_color package.

dynamic_color_testing #

A Flutter package with test utilities for dynamic_color.

Use this package in widget tests to mock platform-provided dynamic color values without changing a device wallpaper or accent color.

Installation #

flutter pub add --dev dynamic_color_testing

Import #

import 'package:dynamic_color_testing/dynamic_color_testing.dart';

What this package provides #

  • DynamicColorTestingUtils.setMockDynamicColors(...)
    • Mocks dynamic color platform channel responses.
    • Supports corePalette and accentColor.
    • Automatically resets the mock with addTearDown.
  • SampleCorePalettes
    • Predefined core palettes for common test scenarios.
  • SampleColorSchemes
    • Color schemes derived from sample palettes.
  • generateCorePalette(...)
    • Helper to generate custom CorePalette values.

Example #

import 'package:dynamic_color/dynamic_color.dart';
import 'package:dynamic_color_testing/dynamic_color_testing.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
  // Reset mock values for every test.
  setUp(() => DynamicColorTestingUtils.setMockDynamicColors());

  testWidgets('uses mocked dynamic core palette', (WidgetTester tester) async {
    DynamicColorTestingUtils.setMockDynamicColors(
      corePalette: SampleCorePalettes.green,
    );

    await tester.pumpWidget(
      DynamicColorBuilder(
        builder: (lightDynamic, darkDynamic) => Container(
          color: lightDynamic?.primary ?? Colors.red,
        ),
      ),
    );

    await tester.pumpAndSettle();
  });
}

For a full example, see the dynamic_color example test: https://github.com/material-foundation/flutter-packages/blob/main/packages/dynamic_color/example/test/widget_test.dart

0
likes
140
points
84
downloads

Documentation

API reference

Publisher

verified publishermaterial.io

Weekly Downloads

A Flutter package to support testing dynamic_color package.

Repository (GitHub)
View/report issues
Contributing

License

Apache-2.0 (license)

Dependencies

dynamic_color, flutter, flutter_test, material_color_utilities

More

Packages that depend on dynamic_color_testing