Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Reland "ChipThemeData is now conventional" #94179

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

Merged
merged 1 commit into from
Dec 1, 2021

Conversation

HansMuller
Copy link
Contributor

@HansMuller HansMuller commented Nov 24, 2021

Relands #93452.

ChipThemeData is now conventional: all of its properties are default null and they define overrides of the defaults defined by the Chip widgets. Default overrides in priority order are (as usual):

  • Chip widget constructor parameters
  • A local ChipTheme
  • The Theme's chipTheme

All of the ChipThemeData constructor parameters and properties are now nullable. Other than that and the change to the default value of ThemeData.chipTheme, this change is intended to be backwards compatible.

Addresses the "theme normalization" sub project within #91772

G3 Fix

This PR requires two small (Google internal) changes: cl/412111154

Breaking Change

There is a small chance that this PR will break existing apps which depend on the default value of the overall Theme's chipTheme.

The default value of Theme.of(context).chipTheme had been a ChipThemeData constructed like this:

chipTheme ??= ChipThemeData.fromDefaults(
  secondaryColor: isDark ? Colors.tealAccent[200]! : primaryColor,
  brightness: colorScheme.brightness,
  labelStyle: textTheme.bodyText1!,
);

This ensured that all of the properties of the chip theme returned by Theme.of(context).chipTheme were non-null. This rarely matters in application code and the defaults for all chip properties have not changed.

To remedy an app that has such a dependency, one can initialize the theme with the original default chipTheme value. For example:

MaterialApp(
  theme: ThemeData(
    primarySwatch: Colors.blue,
    chipTheme: ChipThemeData.fromDefaults(
      secondaryColor: Colors.blue,
      brightness: Brightness.light,
      labelStyle: Typography.material2014(
        platform: defaultTargetPlatform,
      ).white.bodyText1!
    ),
  ),
  ...
)

Generally speaking, it's preferable to use the theme's colorScheme and textTheme to lookup colors and text styles.

@flutter-dashboard flutter-dashboard bot added f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. labels Nov 24, 2021
@google-cla google-cla bot added the cla: yes label Nov 24, 2021
Copy link
Contributor

@darrenaustin darrenaustin left a comment

Choose a reason for hiding this comment

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

LGTM. Nice.

@HansMuller HansMuller merged commit bb3b45a into flutter:master Dec 1, 2021
@HansMuller HansMuller deleted the reland_update_chip_theme branch December 1, 2021 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants