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

Skip to content

Migrate TextTheme to 2018 APIs #48547

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 9 commits into from
Jan 25, 2020

Conversation

HansMuller
Copy link
Contributor

@HansMuller HansMuller commented Jan 10, 2020

This PR is a breaking change. It's described in additional detail here: flutter.dev/go/update-text-theme-api. It's based on an earlier version - #45745.

The TextTheme's styles now have names that match the 2018 Material Design spec. Getters and parameters with the original names are still supported, but they are deprecated.

OLD NAME      NEW NAME
----------------------
display4      headline1
display3      headline2
display2      headline3
display1      headline4
headline      headline5
title         headline6
subhead       subtitle1
body2         bodyText1
body1         bodyText2
caption       caption
button        button
subtitle      subtitle2
overline      overline

The text styles called "bodyText1" and "bodyText2" are called body1 and body2 in the spec, H1-H6 are called headline1-headline6 in the TextTheme API:

image

Note that this PR only changes the names of the TextTheme TextStyles, it does not change the default text style configurations. By default, the text style configurations (the font size, font weight, letter spacing, etc), still match their original 2014 values. Apps can choose to use the 2018 text style configurations instead, by specifying Typography.material2018() as the value for their Theme's typography.

@HansMuller HansMuller added framework flutter/packages/flutter repository. See also f: labels. f: material design flutter/packages/flutter/material repository. work in progress; do not review labels Jan 10, 2020
@fluttergithubbot fluttergithubbot added d: examples Sample code and demos c: contributor-productivity Team-specific productivity, code health, technical debt. customer: gallery Relating to flutter/gallery repository. Please transfer non-framework issues there. labels Jan 10, 2020
@HansMuller HansMuller force-pushed the migrate_text_theme_2018 branch from 59d3fa0 to abca319 Compare January 10, 2020 21:09
@fluttergithubbot fluttergithubbot added the tool Affects the "flutter" command-line tool. See also t: labels. label Jan 13, 2020
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.

 __    ___  ____  __  __ 
(  )  / __)(_  _)(  \/  )
 )(__( (_-.  )(   )    ( 
(____)\___/ (__) (_/\/\_)

This is awesome!

TextStyleItem(name: 'Subheading', style: textTheme.subhead, text: 'Regular 16sp'),
TextStyleItem(name: 'Body 2', style: textTheme.body2, text: 'Medium 14sp'),
TextStyleItem(name: 'Body 1', style: textTheme.body1, text: 'Regular 14sp'),
TextStyleItem(name: 'Headline 1', style: textTheme.headline1, text: 'Light 112sp'),
Copy link
Contributor

Choose a reason for hiding this comment

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

Should the typography demo use the 2018 values for font weight and size instead now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good idea although an update to the typography demo would be probably be best as separate PR

@@ -256,7 +320,7 @@ class Typography extends Diagnosticable {
@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
final Typography defaultTypography = Typography();
final Typography defaultTypography = Typography.material2018();
Copy link
Contributor

Choose a reason for hiding this comment

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

Does making the default 2018 here change anything?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch! Currently the default value for is the 2014 text theme.

@HansMuller HansMuller force-pushed the migrate_text_theme_2018 branch from f2e7f25 to 677d3d0 Compare January 15, 2020 17:36
TextStyleItem(name: 'Headline 4', style: textTheme.headline4, text: 'Regular 34sp'),
TextStyleItem(name: 'Headline 5', style: textTheme.headline5, text: 'Regular 24sp'),
TextStyleItem(name: 'Headline 6', style: textTheme.headline6, text: 'Medium 20sp'),
TextStyleItem(name: 'Subtitle 1', style: textTheme.subtitle1, text: 'Regular 16sp'),
Copy link
Contributor

Choose a reason for hiding this comment

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

Is Subtitle 2 missing here? I don't know if it is necessary, I noticed overline is also omitted.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, both of those styles are missing. This is just a simple translation of the existing demo - only the names have changed - I'm going to update to the demo to show the complete set of 2018 text styles in a separate PR.

#48547 (comment)

body1,
body2,
Copy link
Contributor

Choose a reason for hiding this comment

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

Would this be bodyText1 and bodyText2?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes!

properties.add(DiagnosticsProperty<TextStyle>('body1', body1, defaultValue: defaultTheme.body1));
properties.add(DiagnosticsProperty<TextStyle>('body2', body2, defaultValue: defaultTheme.body2));
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment here for bodyText1 and bodyText2

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes!

subtitle1 : TextStyle(debugLabel: 'blackMountainView subtitle1', fontFamily: 'Roboto', inherit: true, color: Colors.black87, decoration: TextDecoration.none),
bodyText1 : TextStyle(debugLabel: 'blackMountainView bodyText1', fontFamily: 'Roboto', inherit: true, color: Colors.black87, decoration: TextDecoration.none),
bodyText2 : TextStyle(debugLabel: 'blackMountainView bodyText2', fontFamily: 'Roboto', inherit: true, color: Colors.black87, decoration: TextDecoration.none),
caption : TextStyle(debugLabel: 'blackMountainView caption', fontFamily: 'Roboto', inherit: true, color: Colors.black54, decoration: TextDecoration.none),
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
caption : TextStyle(debugLabel: 'blackMountainView caption', fontFamily: 'Roboto', inherit: true, color: Colors.black54, decoration: TextDecoration.none),
caption: TextStyle(debugLabel: 'blackMountainView caption', fontFamily: 'Roboto', inherit: true, color: Colors.black54, decoration: TextDecoration.none),

Nit: It looks like there is some extra white space on this and a several of the following lines, is this intentional?

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 intentional, thanks for pointing that out.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, it looks like the whitespace is meant to make this a whole lot more readable. I guess it just depends where you are viewing it from. :)
(image not from this change)
Screen Shot 2020-01-24 at 11 04 54 AM

bodyText2 : TextStyle(debugLabel: 'dense body1 2014', inherit: false, fontSize: 15.0, fontWeight: FontWeight.w400, textBaseline: TextBaseline.ideographic),
caption : TextStyle(debugLabel: 'dense caption 2014', inherit: false, fontSize: 13.0, fontWeight: FontWeight.w400, textBaseline: TextBaseline.ideographic),
button : TextStyle(debugLabel: 'dense button 2014', inherit: false, fontSize: 15.0, fontWeight: FontWeight.w500, textBaseline: TextBaseline.ideographic),
subtitle2 : TextStyle(debugLabel: 'dense subtitle 2014', inherit: false, fontSize: 15.0, fontWeight: FontWeight.w500, textBaseline: TextBaseline.ideographic),
Copy link
Contributor

Choose a reason for hiding this comment

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

Uber nit: I noticed on some of these subtitle2 was moved up below subtitle1 and on others not.

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 reordered the typography styles; now they match.

textTheme.headline6,
textTheme.subtitle1,
textTheme.bodyText1,
textTheme.bodyText2,
Copy link
Contributor

Choose a reason for hiding this comment

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

Is subtitle(14)/subtitle2(18) missing 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.

This test just checks the original 2014 text styles (still the default). It's now a regression test. Will add a comment to that effect.

@HansMuller HansMuller force-pushed the migrate_text_theme_2018 branch from 677d3d0 to cb9eb51 Compare January 24, 2020 18:50
Copy link
Contributor

@Piinks Piinks left a comment

Choose a reason for hiding this comment

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

Flutter_LGTM
Well done! This is a behemoth! :)

subtitle1 : TextStyle(debugLabel: 'blackMountainView subtitle1', fontFamily: 'Roboto', inherit: true, color: Colors.black87, decoration: TextDecoration.none),
bodyText1 : TextStyle(debugLabel: 'blackMountainView bodyText1', fontFamily: 'Roboto', inherit: true, color: Colors.black87, decoration: TextDecoration.none),
bodyText2 : TextStyle(debugLabel: 'blackMountainView bodyText2', fontFamily: 'Roboto', inherit: true, color: Colors.black87, decoration: TextDecoration.none),
caption : TextStyle(debugLabel: 'blackMountainView caption', fontFamily: 'Roboto', inherit: true, color: Colors.black54, decoration: TextDecoration.none),
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, it looks like the whitespace is meant to make this a whole lot more readable. I guess it just depends where you are viewing it from. :)
(image not from this change)
Screen Shot 2020-01-24 at 11 04 54 AM

TextStyle body2,
@Deprecated(
'This is the term used in the 2014 version of material design. The modern term is bodyText2. '
Copy link
Contributor

Choose a reason for hiding this comment

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

The "bodyText2" here should be "bodyText1" and vice versa.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
c: contributor-productivity Team-specific productivity, code health, technical debt. customer: gallery Relating to flutter/gallery repository. Please transfer non-framework issues there. d: examples Sample code and demos f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. tool Affects the "flutter" command-line tool. See also t: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants