Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for generating a full ColorScheme from a single color #93463

Merged
merged 1 commit into from
Dec 3, 2021

Conversation

darrenaustin
Copy link
Contributor

@darrenaustin darrenaustin commented Nov 11, 2021

As part of the migration to Material 3, this PR adds a new APIs to make it easy to generate new Material 3 ColorSchemes from just a single color.

The design doc discusses this in more detail.

The new APIs are as follows:

ColorScheme.fromSeed()

You can construct a complete Material 3 ColorScheme derived from the tones of a single seed color with:

final lightScheme = ColorScheme.fromSeed(seedColor: Colors.green);
final darkScheme = ColorScheme.fromSeed(seedColor: Colors.green, brightness: Brightness.dark);

ThemeData(Color colorSchemeSeed, ...)

There is a new colorSchemeSeed parameter to the ThemeData factory constructor that will allow the app to generate the theme's color scheme from a seed color:

final lightTheme = ThemeData(colorSchemeSeed: Colors.orange, ...);
final darkTheme = ThemeData(colorSchemeSees: Colors.orange, brightness: Brightness.dark, ...);

Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement].
  • I signed the [CLA].
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is [test-exempt].
  • All existing and new tests are passing.

@flutter-dashboard flutter-dashboard bot added f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. f: integration_test The flutter/packages/integration_test plugin team Infra upgrades, team productivity, code health, technical debt. See also team: labels. labels Nov 11, 2021
@google-cla google-cla bot added the cla: yes label Nov 11, 2021
@darrenaustin darrenaustin force-pushed the colorscheme_seed branch 2 times, most recently from 2dfe964 to 478229b Compare November 18, 2021 18:59
@darrenaustin darrenaustin changed the title WIP: API to generate a ColorScheme from a single seed color. API to generate a ColorScheme from a single seed color. Nov 18, 2021
@darrenaustin
Copy link
Contributor Author

darrenaustin commented Nov 18, 2021

Note to reviewers, I broke this up into multiple commits to make it easier to review the addition of the dependency on material_color_utiltilies (7970178) and the new APIs (86c971b).

Updated so that the dependency changes went in with #94377, so this entire PR is just the new API changes.

Copy link
Contributor

@rami-a rami-a left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@darrenaustin darrenaustin force-pushed the colorscheme_seed branch 2 times, most recently from 4ad5ca3 to 87689e4 Compare November 23, 2021 08:35
Copy link
Contributor

@HansMuller HansMuller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This all looks generally good to me. We're going to need a really good migration guide.

packages/flutter/lib/fix_data.yaml Outdated Show resolved Hide resolved
packages/flutter/lib/src/material/color_scheme.dart Outdated Show resolved Hide resolved
packages/flutter/lib/src/material/color_scheme.dart Outdated Show resolved Hide resolved
packages/flutter/lib/src/material/color_scheme.dart Outdated Show resolved Hide resolved
/// If any of the optional color parameters are non-null they will be
/// used in place of the generated colors for that field in the resulting
/// color scheme.
///
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hopefully a fun interactive color-scheme generator example appears here...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is on my list, but it would be a lot easier if we had a built in color picker... 😄

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could always use 3 or 4 sliders for a rough and ready color picker. Adding an example in a separate PR would be fine.

brightness: brightness,
);
}
}

/// Create a ColorScheme based on a purple primary color that matches the
/// [baseline Material color scheme](https://material.io/design/color/the-color-system.html#color-theme-creation).
const ColorScheme.light({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As with the basic constructor, best to refer to ColorScheme.fromSeed() here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I get why here. If they are looking for a pre-built 'light' color scheme, why would they want to use fromSeed (other than to make sure they get a full color scheme), and what should they use for the seed color? This kind of points out the problem with not having a M3 version of this and dark.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking that it would be helpful to get apps off of ColorScheme.light(), since there isn't a perfect migration path that preserves the existing colors and adds new ones are comparable to what you'd get from ColorScheme.fromSeed(). Hopefully we can migrate developers that have used ColorScheme.light() to something like ColorScheme.fromSeed(seedColor: const Color(just the right purple seed color here). So for now we just remind them that the fromSeed factory is almost as trivial to write and so much more useful.

_onInverseSurface = onInverseSurface,
_inversePrimary = inversePrimary,
_primaryVariant = primaryVariant,
_secondaryVariant = secondaryVariant;

/// Create the recommended dark color scheme that matches the
/// [baseline Material color scheme](https://material.io/design/color/dark-theme.html#ui-application).
const ColorScheme.dark({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As with the basic constructor, best to refer to ColorScheme.fromSeed() here.


/// Generate a [ColorScheme] based around the given `seedColor`.
///
/// Using the seedColor as a starting point, a set of tonal palettes are
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to generate a high-contrast color scheme from a seed color? It would help to provide a path from all of the existing factories, to ColorScheme.fromSeed().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't see an obvious way to do this with material_color_utilities, but @guidezpl would know.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the late reply.. There isn't

@darrenaustin
Copy link
Contributor Author

darrenaustin commented Nov 24, 2021

This all looks generally good to me. We're going to need a really good migration guide.

Thanks for the feedback. I have addressed most of your comments with 86c971b, let me know what you think.

A migration guide is next on my list, so I took notes from your comments here. Thx.

Copy link
Contributor

@HansMuller HansMuller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

You proposed breaking this into the package dependency and then the ColorScheme changes. That sounds like a good idea.

/// If any of the optional color parameters are non-null they will be
/// used in place of the generated colors for that field in the resulting
/// color scheme.
///
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could always use 3 or 4 sliders for a rough and ready color picker. Adding an example in a separate PR would be fine.

brightness: brightness,
);
}
}

/// Create a ColorScheme based on a purple primary color that matches the
/// [baseline Material color scheme](https://material.io/design/color/the-color-system.html#color-theme-creation).
const ColorScheme.light({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking that it would be helpful to get apps off of ColorScheme.light(), since there isn't a perfect migration path that preserves the existing colors and adds new ones are comparable to what you'd get from ColorScheme.fromSeed(). Hopefully we can migrate developers that have used ColorScheme.light() to something like ColorScheme.fromSeed(seedColor: const Color(just the right purple seed color here). So for now we just remind them that the fromSeed factory is almost as trivial to write and so much more useful.

@darrenaustin darrenaustin marked this pull request as ready for review December 1, 2021 22:35
@guidezpl guidezpl changed the title API to generate a ColorScheme from a single seed color. Add support for generating a full ColorScheme from a single color Mar 30, 2022
@guidezpl guidezpl changed the title Add support for generating a full ColorScheme from a single color Add support for generating a full ColorScheme from a single color May 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
f: integration_test The flutter/packages/integration_test plugin f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. team Infra upgrades, team productivity, code health, technical debt. See also team: labels.
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

6 participants