material-foundation / flutter-packages

A collection of useful Material Design packages
https://pub.dev/publishers/material.io
Apache License 2.0
841 stars 158 forks source link

[dynamic_color] Add new colors #589

Closed MahanRahmati closed 4 months ago

MahanRahmati commented 6 months ago

Description

Add new material colors introduced in Flutter 3.22.

Issues

Fixes #582

Checklist

MahanRahmati commented 6 months ago

We need to bump material_color_utilities, and it is an SDK dependency.

boredcodebyk commented 6 months ago

new colors doesn't seem to be added in Scheme and they apparently moved to DynamicScheme as Scheme is deprecated (see this)

this package seem to direct take CorePalette from android. I tried to make following changes locally according to their migration guide

// corepalette_to_colorscheme.dart
final SchemeTonalSpot scheme;

    switch (brightness) {
      case Brightness.light:
        scheme = SchemeTonalSpot(
            sourceColorHct: Hct.fromInt(primary.keyColor.toInt()),
            isDark: false,
            contrastLevel: 0.0);
        break;
      case Brightness.dark:
        scheme = SchemeTonalSpot(
            sourceColorHct: Hct.fromInt(primary.keyColor.toInt()),
            isDark: true,
            contrastLevel: 0.0);
        break;
    }
...
return ColorScheme(
      primary: Color(MaterialDynamicColors.primary.getArgb(scheme)),
      onPrimary: Color(MaterialDynamicColors.onPrimary.getArgb(scheme)),
...

but the unit test fails

dynamic_color: Core palette detected.
══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
The following TestFailure was thrown running a test:
Expected: Color:<Color(0xff286c2a)>
  Actual: Color:<Color(0xff8c4a60)>

for reference I used code from ColorScheme.fromSeed() from Flutter SDK

ghost commented 6 months ago

@boredcodebyk

but the unit test fails

dynamic_color: Core palette detected.
══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
The following TestFailure was thrown running a test:
Expected: Color:<Color(0xff286c2a)>
  Actual: Color:<Color(0xff8c4a60)>

for reference I used code from ColorScheme.fromSeed() from Flutter SDK

Shouldn't just correcting expecting colors in test file enough if everything else works perfectly? (not based on this error but checking what's the real output of given colorscheme in test on md3 colorscheme generator, as colorscheme colors changed, now we need to change test file too)

boredcodebyk commented 6 months ago

@andr202 you have a valid point but theoretical the test doesn't needs to be changed. in the test file a container is given primary color and tested with the expected color which passes. in this case, the primary color gets way off from expected color for some reason. I'm still looking into it (and now I'm clueless)

resucutie commented 5 months ago

Is there still any goals to be met with this PR? The merge request is very waited due to the changes on 3.22

hasali19 commented 5 months ago

Hi @MahanRahmati, how do I use this branch? It seems to fail as the new properties do not exist in the Scheme class in material_color_utilities. https://github.com/material-foundation/material-color-utilities/blob/main/dart/lib/scheme/scheme.dart

MahanRahmati commented 5 months ago

Hi @MahanRahmati, how do I use this branch? It seems to fail as the new properties do not exist in the Scheme class in material_color_utilities. https://github.com/material-foundation/material-color-utilities/blob/main/dart/lib/scheme/scheme.dart

You can't use it yet. The branch is broken. I'm waiting for flutter to bump material_color_utilities and update the branch later.

Henry-Hiles commented 5 months ago

This is quite urgent, has flutter bumped that yet?

guidezpl commented 4 months ago

Closing as the approach here will necessitate something like https://github.com/material-foundation/flutter-packages/compare/main...hasali19:material-foundation-flutter-packages:main (with fixes as the color mappings aren't accurate) to construct the color scheme