Skip to content

Conversation

@darrenaustin
Copy link
Contributor

@darrenaustin darrenaustin commented Aug 1, 2019

Description

In order to more easily provide themes based on a given Material color scheme, this PR adds a new ThemeData.from() method that will construct a ThemeData with values based on the passed ColorScheme and optional TextTheme parameters.

This will allow users to easily construct an app with the baseline Material light and dark themes with something like:

MaterialApp(
  theme: ThemeData.from(colorScheme: ColorScheme.light()),
  darkTheme: ThemeData.from(colorScheme: ColorScheme.dark()),
)
Light Dark
Light Dark

Tests

I added tests to theme_ data_test.dart that exercises this function with the default light and dark Material color schemes.

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require Flutter developers to manually update their apps to accommodate your change?

  • No, this is not a breaking change.

@fluttergithubbot fluttergithubbot added f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. labels Aug 1, 2019
@darrenaustin darrenaustin changed the title Added ThemeData.from() method to construct a Theme from a ColorSchemethat constructs a Theme based off WIP: Added ThemeData.from() method to construct a Theme from a ColorScheme Aug 1, 2019
@darrenaustin darrenaustin changed the title WIP: Added ThemeData.from() method to construct a Theme from a ColorScheme Added ThemeData.from() method to construct a Theme from a ColorScheme Aug 1, 2019
@darrenaustin darrenaustin requested a review from HansMuller August 1, 2019 01:17
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

@darrenaustin darrenaustin merged commit 4c8fc78 into flutter:master Aug 6, 2019
@darrenaustin darrenaustin deleted the theme_from_color_scheme branch August 6, 2019 21:25
@bernaferrari
Copy link
Contributor

bernaferrari commented Sep 16, 2019

I am really liking this, but I have a question. How do I use ThemeData.from() when custom theming a component?
image

If I use ThemeData.from(), I loose all the shapes, elevations, radius and etc. It is great in the main() class, but for the others..? In this case, I wish I could just apply the ColorScheme and it would automatically update everything, like the cardColor. Instead, I needed to enter ThemeData.from() to see what was theming what and manually copy it for my app.
Maybe an applyTo to ThemeData would help this.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 4, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

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.

5 participants