A more flexible version of Flutter's ColorScheme.fromSeed

Overview

Pub Version codecov License

FlexSeedScheme

A more flexible version of Flutter's ColorScheme.fromSeed.

Use this package like ColorScheme.fromSeed with the following additional capabilities:

  • Use separate key colors to generate seed based tonal palettes for primary, secondary and tertiary colors in ColorScheme.
  • Change the chroma limits and values used in the Material 3 default strategy for tonal palette generation in the Google HCT color space.
  • Change which tones in the generated core tonal palettes are used by which ColorScheme color. Changes are limited to the tones from correct core palette for each ColorScheme color, but any tone from it can be used. Going up or down one tone is often usable, in some cases even two.
  • Use two additional tonal palettes tones, 5 and tone 98. They can be used to offer more fidelity in the dark and light end of the tonal palettes and mapped to ColorScheme colors when using custom tone mapping. Tone 98 is also available in web based Material 3 Theme Builder, but not included in Material 3 design guide, that explicitly mentions thirteen tones and excludes tone 98. With FlexSeedScheme you can use fifteen tones, including 98 and 5.

Background

This package was extracted from the customizable color scheme seeding engine in the FlexColorScheme package to its own package.

This allows developers to use the same customizable ColorScheme seeding algorithms used by FlexColorScheme, without using the FlexColorScheme package. Starting with FlexColorScheme version 6 and later, it depends on this package instead.

If you use FlexColorScheme version 6 or later, you do not need to add FlexSeedScheme to use its features, FlexColorScheme exports its API as well. If you use FlexColorScheme you typically do not need to use FlexSeedScheme directly, its usage is baked in and used based on how you configure FlexColorScheme.

Getting started

Add the flex_seed_scheme package to pubspec.yaml:

dart pub add flex_seed_scheme or flutter pub add flex_seed_scheme

Usage

Import the package to use it:

import 'package:flex_seed_scheme/flex_seed_scheme.dart';

Define seed colors that will be used to generate your seed generated ColorScheme.

// Define your seed colors.
const Color primarySeedColor = Color(0xFF6750A4);
const Color secondarySeedColor = Color(0xFF3871BB);
const Color tertiarySeedColor = Color(0xFF6CA450);

Make a more flexible seed generated ColorScheme using SeedColorScheme.fromSeeds. It works like ColorScheme.fromSeed, but instead of only accepting a single seed color, it can use three key colors as seed colors, one for each main color group in ColorScheme.

Chroma limits that differs from Material 3 defaults for its tonal palette generation can also be defined. Additionally, tone mapping, that defines which tone is used by what ColorScheme color can be customized, both are done via FlexTones passed in to tones.

Typically, you should use the same key colors and tones setup to produce the ColorScheme for light and dark theme mode. This guarantees that the light and dark theme use identical generated tonal palettes, and only vary based on which tones are used for what color in light and dark mode. This results in matching light and dark theme colors. This is just the norm though, feel free to experiment.

    // Make a light ColorScheme from the seeds.
    final ColorScheme schemeLight = SeedColorScheme.fromSeeds(
      brightness: Brightness.light,
      // Primary key color is required, like seed color ColorScheme.fromSeed.
      primaryKey: primarySeedColor,
      // You can add optional own seeds for secondary and tertiary key colors.
      secondaryKey: secondarySeedColor,
      tertiaryKey: tertiarySeedColor,
      // Tone chroma config and tone mapping is optional, if you do not add it
      // you get the config matching Flutter's Material 3 ColorScheme.fromSeed.
      tones: FlexTones.vivid(Brightness.light),
    );

    // Make a dark ColorScheme from the seeds.
    final ColorScheme schemeDark = SeedColorScheme.fromSeeds(
      brightness: Brightness.dark,
      primaryKey: primarySeedColor,
      secondaryKey: secondarySeedColor,
      tertiaryKey: tertiarySeedColor,
      tones: FlexTones.vivid(Brightness.dark),
    );

Separate key colors as seeds for the primary, secondary and tertiary colors in ColorScheme can be provided to seed them from different key colors. If no key color for secondaryKey and/or tertiaryKey are provided, they use primaryKey color as their seed color value.

If you only specify primaryKey color as seed, and no custom tones configuration, identical ColorScheme result to ColorScheme.fromSeed is produced.

The default chroma limits in the HCT color space used for seed generated colors for secondary and tertiary colors in ColorScheme.fromSeed have quite low chroma values. This makes the colors fairly muted or pastel like. This is especially the case with secondary colors. This is by design in the standard Material 3 color palette. You can tune this behavior by passing in a custom FlexTones configuration to tones. There are pre-made configuration you can use, above FlexTones.vivid was used. It is also easy to make completely custom configuration. Look in FlexTones and use the pre-made definitions as inspiration for your own configs.

Using the above configuration the following core palettes are generated, in order from top to bottom:

  • Primary tonal palette
  • Secondary tonal palette
  • Tertiary tonal palette
  • Error tonal palette
  • Neutral tonal palette
  • Neutral variant tonal palette

palettes

With the example FlexTones.vivid setup, the light ColorScheme is mapped as shown below:

colorscheme

And the dark ColorScheme as:

colorscheme_dark

Define ThemeData

In your MaterialApp you then define you light and dark mode themes using the seed generated ColorSchemes just as you would with any other ColorScheme. For example:

  @override
    Widget build(BuildContext context) {
      return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'SeedColorScheme.fromSeeds Demo',
      themeMode: ThemeMode.system,  
      theme: ThemeData.from(
        colorScheme: schemeLight,
        useMaterial3: true,
      ),
      darkTheme: ThemeData.from(
        colorScheme: schemeDark,
        useMaterial3: true,
      ),
      home: HomePage(),
    );
  }

Override Color Values

All colors in the seed produced ColorScheme can be overridden by providing each ColorScheme color property in SeedColorScheme.fromSeeds a given color value. This feature is equivalent to ColorScheme.fromSeed.

This is typically used to assign a given color value to primary color, which is often used as app brand color. When the brand color is used as primaryKey, and as a seed color, it typically does not end up as the primary color in the seed generated ColorScheme. Having a given brand color as primary color is often desired. To get the seed color as your primary brand color, assign the color used as primaryKey to primary color as well.

    // Make a light ColorScheme from the seeds.
    final ColorScheme schemeLight = SeedColorScheme.fromSeeds(
      brightness: Brightness.light,
      // Use a "brand" seed color as primary color in the result.
      primary: primarySeedColor,
      primaryKey: primarySeedColor,
      //
      secondaryKey: secondarySeedColor,
      tertiaryKey: tertiarySeedColor,
      tones: FlexTones.vivid(Brightness.light),
    );

This strategy works well for the light mode ColorScheme, since the prominent brand color a company has defined is typically intended to be printed on white paper. If you have secondary brand colors that are to be used, using them as seeds for secondaryKey and tertiaryKey will work too. How well they will fit and match the Material 3 color system needs, if assigned to secondary and tertiary directly as colors in SeedColorScheme.fromSeeds, will vary depending on what colors they are.

Companies rarely have brand colors suited for good contrast in dark theme mode. In that case prefer only using the same light mode brand colors as key colors to seed the dark mode ColorScheme. If they do have dark mode specifications, and the colors are of same hue as light mode, consider still using the light mode colors as seed source and only applying the appropriate dark mode colors to primary, secondary and tertiary as needed.

If there is a spec that calls for completely different main colors in dark mode, using different hues, then seeding from them and also setting primary, secondary and tertiary to these color values is appropriate.

Customize Tones and Chroma

In the above example, we used a predefined tone mapping and chroma setup called FlexTones.vivid. There are currently seven predefined configurations available:

  • FlexTones.material, default and same as Flutter SDK M3 setup.
  • FlexTones.soft, softer and earthier tones than M3 FlexTones.material.
  • FlexTones.vivid, more vivid colors, uses chroma as given from all key colors.
  • FlexTones.vividSurfaces, like vivid, but with more colors in surfaces.
  • FlexTones.highContrast, can be used for more color accessible themes.
  • FlexTones.ultraContrast, for a very high contrast theme version.
  • FlexTones.jolly, for a more "jolly" and colorful theme.

You can define custom tones mapping and chroma limitation setups with FlexTones. Using the FlexTones.light and FlexTones.dark constructors as base for custom definitions are preferred. By using them you only need to override defaults that you want to change.

// Example definition of light custom tones config.
const FlexTones myLightTones = FlexTones.light(
  primaryTone: 30, // Default is 40.
  onPrimaryTone: 95, // Default is 100
  onSecondaryTone: 95, // Default is 100
  onTertiaryTone: 95, // Default is 100
  onErrorTone: 95, // Default is 100
  primaryMinChroma: 55, // Default is 48
  secondaryChroma: 25, // Default is 16
  tertiaryChroma: 40, // Default is 24
  neutralChroma: 7, // Default is 4,
  neutralVariantChroma: 14, // Default is 8
);

// Example definition of dark custom tones config.
const FlexTones myDarkTones = FlexTones.dark(
  primaryTone: 70, // Default is 80.
  onPrimaryTone: 10, // Default is 20
  onSecondaryTone: 10, // Default is 20
  onTertiaryTone: 10, // Default is 20
  onErrorTone: 10, // Default is 20
  primaryMinChroma: 55, // Default is 48
  secondaryChroma: 25, // Default is 16
  tertiaryChroma: 40, // Default is 24
  neutralChroma: 7, // Default is 4,
  neutralVariantChroma: 14, // Default is 8
);

Accessibility

You can use FlexTones to create a seed generated ColorScheme, that is based on same colors as your standard theme's light and dark scheme colors, but uses a chroma configuration and tone mapping setup that increases contrast further from standard light and dark theme setup.

There are two high contrast FlexTones configuration pre-made for this. They are called FlexTones.highContrast, a colorful high contrast version, and FlexTones.ultraContrast, a less colorful version with more pure dark on light in light theme mode, and light on dark in dark mode.

// Make a high contrast light ColorScheme from the seeds.
final ColorScheme schemeLightHc = SeedColorScheme.fromSeeds(
  brightness: Brightness.light,
  primaryKey: primarySeedColor,
  secondaryKey: secondarySeedColor,
  tertiaryKey: tertiarySeedColor,
tones: FlexTones.highContrast(Brightness.light),
);

// Make a ultra contrast dark ColorScheme from the seeds.
final ColorScheme schemeDarkHc = SeedColorScheme.fromSeeds(
  brightness: Brightness.dark,
  primaryKey: primarySeedColor,
  secondaryKey: secondarySeedColor,
  tertiaryKey: tertiarySeedColor,
  tones: FlexTones.ultraContrast(Brightness.dark),
);

If you then define equivalent ThemeData based on those schemes as your standard MaterialApp, theme and darkTheme definitions, but assign them to highContrastTheme and highContrastDarkTheme, you get more accessible themed colors that are based on same colors, but with higher contrast, that are activated when users select high contrast theme in device accessibility system settings.

      // Define accessibility high contrast versions using same color base.
      //
      highContrastTheme: ThemeData.from(
        colorScheme: schemeLightHc,
        useMaterial3: true,
      ),
      highContrastDarkTheme: ThemeData.from(
        colorScheme: schemeDarkHc,
        useMaterial3: true,
      ),

Example App

The included example app in light and dark theme mode using above color seeding and custom tone mapping.

Below also comparing it to only single color ColorScheme.fromSeed generated default Material 3 seed algorithm available in Flutter. Both are using same key color as primary seed color, but as ColorScheme.fromSeed can only use a single seed color, we cannot customize the hues of its seed generated secondary and tertiary colors. The secondary and tertiary colors are also more muted, earthy and pastel color tones.

Light from seeds - Custom tones Dark from seeds - Custom tones
light_app dark_app
Light from seed - Material 3 tones Dark from seed - Material 3 tones
light_app_m3 dark_app_m3

You can try a web version of this example here.

You might also like...

An atomic state management library for dart (and Flutter). Simple, fast and flexible.

nucleus An atomic dependency and state management toolkit. Design goals Simplicity - simple API with no surprises Performance - allow for millions of

Jan 2, 2023

Access app version and git informations from auto-generated and configurable widgets

This is a proof of concept and WIP Feedback and ideas welcome !! Access your pubspec and git commit informations like versions and commit status from

Jul 7, 2021

A builder for extracting a package version into code

Include the version of your package in our source code. Add build_version to pubspec.yaml. Also make sure there is a version field. name: my_pkg versi

Dec 7, 2022

A dart-lang version of the SIP UA stack.

dart-sip-ua A dart-lang version of the SIP UA stack, ported from JsSIP. Overview Use pure dart-lang SIP over WebSocket (use real SIP in your flutter m

Dec 26, 2022

Cupertino version of the Material Stepper in Flutter

Cupertino version of the Material Stepper in Flutter

Cupertino Stepper for Flutter Cupertino version of the stock Material Stepper in Flutter. NOTE: This is not the same as the UIStepper control on iOS.

Oct 13, 2022

Extract pubspec details (such as package version, author and description) into Dart code.

build_pubspec This package helps you convert fields from your pubspec.yaml file into Dart code. Based on the fields in your pubspec, this package will

Jul 15, 2021

Replaces Flutter's bundled Dart SDK with the macOS arm64 version

This script replaces Flutter's bundled Dart SDK with the macOS arm64 version Get

Oct 9, 2022

A Flutter widget that checks and displays the version status of application and you can easily guide user to update your app

A Flutter widget that checks and displays the version status of application and you can easily guide user to update your app

A most easily usable Flutter widget about application version check! 1. About 1.

Dec 16, 2021

Mobile version of web todoie app.

flutter_todoie Todoie App Getting Started This project is a starting point for a Flutter application. A few resources to get you started if this is yo

Dec 26, 2021
Releases(1.2.0-dev.1)
  • 1.2.0-dev.1(Dec 22, 2022)

    1.2.0-dev.1

    Dec 23, 2022

    Requires minimum Flutter 3.7.0-1.2.pre (beta channel). This is a development pre-release to support outlineVariant and scrim colors in ColorScheme. It is used for development and testing against new Material 3 features in Flutter 3.7 beta and master channel. It will be released as a stable version when the new color properties land in the Flutter stable channel, most likely after January 25, 2023.

    The release also adds new features to allow customization of seed generation of error, neutral and neutral variant tonal palettes.

    NEW

    • Adds support for outlineVariant and scrim colors in ColorScheme.

    • Added support for customizing seed generation for error, neutral and neutral variant tonal palettes.

    • To support the new features the SeedColorScheme.fromSeeds got the following new Color properties errorKey, neutralKey and neutralVariantKey.

    • The FlexTones class got the following new double properties errorChroma, errorMinChroma, neutralMinChroma and neutralVariantMinChroma

    • The FlexCorePalette.fromSeeds factory got the following new int properties error, neutral, neutralVariant and neutralVariantMinChroma. As well as new double properties errorChroma, errorMinChroma, neutralChroma, neutralMinChroma, neutralVariantChroma and neutralVariantMinChroma.

    • The demo application got an About dialog. The demo app also shows the ColorScheme applied on common Material components.

    Source code(tar.gz)
    Source code(zip)
  • 1.1.0(Nov 17, 2022)

    Version 1.1.0

    Nov 17, 2022

    NEW

    • Added new FlexTones method onMainsUseBW, that can return a new instance of its configurations with tone mapping for its main *on colors set to tone, 0 (black) or 100 (white), depending on what is appropriate for its main color tones. The main colors are primary, secondary, tertiary, error and their containers. The method works on any configured FlexTones, also custom ones, not only the built-in ones.

    • Added new FlexTones method onSurfacesUseBW, that can return a new instance of its configurations with tone mapping for its surface *on colors set to tone, 0 (black) or 100 (white), depending on what is appropriate for its surface color tones. Surface colors are background, surface, surfaceVariant and inverseSurface. The method works on any configured FlexTones, also custom ones, not only the built-in ones.

    • To be able to support creating mono-hue seeded color schemes, the FlexCorePalette.fromSeeds got a new property tertiaryHueRotation. It controls the used hue rotation degrees from primary key color, that is used when a tertiary seed key color is not provided. The tertiaryHueRotation defaults 60 degrees, same as previously from Material 3 color system hard-coded value.

    • Added two new FlexTones.

      • FlexTones.oneHue that set tertiaryHueRotation to 0, so we can create a mono hue palette if we only provide primary key color as seed.
      • FlexTones.vividBackground that is a copy of FlexTones.vividSurfaces but with tone mapping for background and surface swapped.

    CHANGE

    Tone mappings for some pre-configured FlexTones were slightly modified. They now produce improved and more usable color schemes. Most significantly, the mappings for FlexTones.vividSurfaces were modified to provide a more usable and improved vivid surfaces tinted color schemes, while still offering a slightly more tinted surface design than FlexTones.vivid. Tone mapping changes are as follows:

    • The FlexTones.vivid, brightness light:
      • Tone surfaceTone was changed from 99 to 98.
    • The FlexTones.vivid, brightness dark:
      • Tone onErrorContainerTone was changed from 90 to 80 (dark M3 default).
      • Tone backgroundTone was changed from 10 to 5.
    • The FlexTones.vividSurfaces brightness light:
      • Tone onPrimaryTone was changed from 95 to 98.
      • Tone onSecondaryTone was changed from 95 to 98.
      • Tone onTertiaryTone was changed from 95 to 98.
      • Tone onErrorTone was changed from 95 to 98.
      • Tone primaryContainerTone was changed from 80 to 90 (light M3 default).
      • Tone secondaryContainerTone was changed from 80 to 90 (light M3 default).
      • Tone tertiaryContainerTone was changed from 80 to 90 (light M3 default).
      • Tone errorContainerTone was changed from 80 to 90 (light M3 default).
      • Tone surfaceVariantTone was changed from 80 to 90 (light M3 default).
      • Tone backgroundTone was changed from 90 to 98.
      • neutralChroma was changed from 8 to 5.
      • neutralVariantChroma was changed from 16 to 10.
    • The FlexTones.vividSurfaces brightness dark:
      • Tone primaryContainerTone was changed from 40 to 20.
      • Tone tertiaryContainerTone was changed from 40 to 30 (dark M3 default).
      • Tone primaryContainerTone was changed from 40 to 30 (dark M3 default).
      • Tone onErrorTone was changed from 20 to 30 (dark M3 default).
      • Tone onErrorContainerTone was changed from 90 to 80 (dark M3 default).
      • Tone surfaceTone was changed from 10 to 20.
      • Tone surfaceVariantTone was changed from 40 to 30 (dark M3 default).
      • Tone backgroundTone was changed from 20 to 10.
      • Tone onSurfaceVariantTone was changed from 90 to 95.
      • Tone onInverseSurfaceTone was changed from 30 to 20 (dark M3 default).
      • neutralChroma was changed from 8 to 5.
      • neutralVariantChroma was changed from 16 to 10.
    • The FlexTones.ultraContrast brightness light:
      • Tone primaryTone was changed from 30 to 20.
    • The FlexTones.ultraContrast brightness dark:
      • Tone surfaceTone was changed from 10 to 5.
      • Tone backgroundTone was changed from 10 to 5.
    Source code(tar.gz)
    Source code(zip)
  • 1.0.1(Sep 2, 2022)

    1.0.1

    Sep 2, 2022

    DOCS

    • Readme: Removed old notice about package being a beta release and using Flutter 3.3 beta.
    • Readme: Described custom FlexTones config with an example.
    • API doc improvements.

    EXAMPLE

    • Allow selection of example custom tones example and all built-in FlexTones options.
    • Publish example app as a live web demo.
    Source code(tar.gz)
    Source code(zip)
  • 1.0.0(Aug 30, 2022)

  • 0.2.0-dev.2(Aug 28, 2022)

  • 0.1.0-dev.3(Aug 26, 2022)

  • 0.1.0-dev.2(Aug 26, 2022)

    0.1.0-dev.2

    Aug 27, 2022

    • Relax version constraint to make it work on beta 3.3.0-0.3.pre and later.
    • Remove in Flutter beta 3.3.0 unsupported ColorScheme colors scrim and outlineVariant.
    Source code(tar.gz)
    Source code(zip)
  • 0.1.0-dev.1(Aug 26, 2022)

Owner
Rydmike
Works with software for building management and energy efficiency. Flutter rocks!
Rydmike
Weather app using Bloc architecture pattern & generic HTTP client with interface implementation and much more for more detail read Readme

weather Weather application for current weather, hourly forecast for 48 hours, Daily forecast for 7 days and national weather alerts. How to Run Insta

Jibran Ahmed SiddiQui 9 Oct 29, 2022
More than 130+ pages in this beautiful app and more than 45 developers has contributed to it.

flutter-ui-nice ❤️ Star ❤️ the repo to support the project or ?? Follow Me.Thanks! Facebook Page Twitter Medium QQ Group Flutter Open NieBin Flutter O

Flutter开源社区 3.4k Jan 3, 2023
More than 130+ pages in this beautiful app and more than 45 developers has contributed to it.

flutter-ui-nice ❤️ Star ❤️ the repo to support the project or ?? Follow Me.Thanks! Facebook Page Twitter Medium QQ Group Flutter Open NieBin Flutter O

Flutter开源社区 3.4k Jan 5, 2023
An easy-to-use flutter http network requests handler with more functionality than http but more simpler than dio.

network_requests An easy-to-use flutter http network requests handler with more functionality than http but more simpler than dio. Platform Supported

Coder_Manuel 3 Dec 15, 2022
Fluro is a Flutter routing library that adds flexible routing options like wildcards, named parameters and clear route definitions.

English | Português The brightest, hippest, coolest router for Flutter. Features Simple route navigation Function handlers (map to a function instead

Luke Pighetti 3.5k Jan 4, 2023
FLUTTER API: Video Editor allows trim, crop, rotate and scale video with a super flexible UI Design

video_editor My other APIs Scroll Navigation Video Viewer Helpers Features Super flexible UI Design. Support actions: Crop Trim Scale Rotate Cover sel

Luis Felipe Murguia Ramos 214 Dec 26, 2022
A Very Flexible Widget that can Implement Material Sheets on all Directions, both modal and persistent, and consequently a Material Navigation Drawer

Flutter_MaterialSheetAndNavigationDrawer If this project helped you reduce developement time or you just want to help me continue making useful tools

Bryan Cancel 30 Dec 4, 2021
A Dart dependency injection library aimed to be flexible, predictable and easy to use.

dino Dino is a Dart dependency injection library with optional code generation. It was inspired by DI in .NET and aimed to be flexible, predictable an

null 3 Dec 20, 2022
A fast, flexible, IoC library for Dart and Flutter

Qinject A fast, flexible, IoC library for Dart and Flutter Qinject helps you easily develop applications using DI (Dependency Injection) and Service L

null 4 Sep 9, 2022