Skip to content

Implemented M3 Typography letterSpacing for bodyLarge does not match M3 Guide Spec. #102121

Description

@rydmike

Discrepancy: M3 Guide Typescale versus Flutter Typography Implementation

In this #89853 (comment), I made an observation that the spec in supplied image did not match the M3 Web guide concerning the Typescale / Typography for TextStyle bodyLarge and its used letterSpacing.

The image in (#89853) has bodyLarge and its used letterSpacing defined as 0.5
The guide at 0.15

In this PR https://github.com/flutter/flutter/pull/97829/files#diff-a91306c958d84cfa7a9287e538e2c8f22bd7765d59ec1dadb2382bda832332adR751 it was implemented as 0.5, and was merged into master as such:

bodyLarge: TextStyle(debugLabel: 'englishLike bodyLarge 2021', inherit: false, fontSize: 16.0, fontWeight: FontWeight.w400, letterSpacing: 0.5, height: 1.50, textBaseline: TextBaseline.alphabetic, leadingDistribution: TextLeadingDistribution.even),

Question:

Is the M3 guide spec wrong?
Or is it an oversight that the correction observation did not make it into the Flutter implementation?

One or the other needs to be corrected, they can't both be right.

In issue https://github.com/flutter/flutter/issues/89853 @rami-a concluded that the image was wrong and the web M3 spec correct.

Which of course means that the current Flutter implementation is incorrect.

cc: @darrenaustin @TahaTesser

Activity

  1. maheshj01 commented on Apr 19, 2022

    @maheshj01
    Member

    Hi @rydmike, Thanks for filing the issue. I do see 0.5 letter-spacing being used for body large on flutter master

    bodyLarge: TextStyle(debugLabel: 'englishLike bodyLarge 2021', inherit: false, fontSize: 16.0, fontWeight: FontWeight.w400, letterSpacing: 0.5, height: 1.50, textBaseline: TextBaseline.alphabetic, leadingDistribution: TextLeadingDistribution.even),

    and the M3 Typography Specs seem to indicate it should be 0.15. Labeling this issue as a bug, since this is not aligned with the Material 3 Specs

    cc: @rami-a

  2. added
    frameworkflutter/packages/flutter repository. See also f: labels.
    p: material_uimaterial_ui package in flutter/packages
    a: typographyText rendering, possibly libtxt
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    and removed
    in triagePresently being triaged by the triage team
    on Apr 19, 2022
  3. TahaTesser commented on Apr 19, 2022

    @TahaTesser
    Contributor

    it makes sense looking at the M3 guide but this needs a tokens update:

    "md.sys.typescale.body-large.size": 16.0,
    "md.sys.typescale.body-large.tracking": 0.5,
    "md.sys.typescale.body-large.weight": "md.ref.typeface.weight-regular",

  4. darrenaustin commented on Apr 19, 2022

    @darrenaustin
    Contributor

    I just checked and the value coming back from the token DB is indeed 0.5. I have asked the design team about this and will follow up with either a fix or a bug against the spec if that needs to be updated.

  5. TahaTesser commented on Apr 19, 2022

    @TahaTesser
    Contributor

    I wrote a quick test based on these references

      testWidgets('bodyText1 is not equal to bodyLarge', (WidgetTester tester) async {
        final ThemeData theme =  ThemeData();
        final Key bodyText1Key = UniqueKey();
        final Key bodyLargeKey = UniqueKey();
        await tester.pumpWidget(
          MaterialApp(
            home: Scaffold(
              body: Center(
                child: Text('Dash', key: bodyText1Key, style: theme.textTheme.bodyText1),
              ),
            ),
          ),
        );
    
        RenderParagraph paragraph = tester.renderObject(find.text('Dash')) as RenderParagraph;
        // While `text_theme.dart` references `TextStyle? get bodyText1 => bodyLarge;`.
        // `theme.textTheme.bodyLarge` paragraph size is `const Size(56.0, 14.0)`.
        expect(paragraph.size, const Size(56.0, 14.0));
          await expectLater(
            find.byKey(bodyText1Key),
            matchesGoldenFile('bodyText1.png'),
          );
    
        await tester.pumpWidget(
          MaterialApp(
            theme: ThemeData(useMaterial3: true),
            home: Scaffold(
              body: Center(
                child: Text('Dash', key: bodyLargeKey, style: theme.textTheme.bodyLarge),
              ),
            ),
          ),
        );
        await tester.pumpAndSettle();
        paragraph = tester.renderObject(find.text('Dash')) as RenderParagraph;
        // While `text_theme.dart` references `TextStyle? get bodyText1 => bodyLarge;`.
        // `theme.textTheme.bodyLarge` paragraph size is not equal to `bodyText1`.
        expect(paragraph.size, const Size(57.0, 20.0));
          await expectLater(
            find.byKey(bodyLargeKey),
            matchesGoldenFile('bodyLarge.png'),
          );
      });

    bodyLarge = bodyLarge ?? bodyText1,

    https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/material/text_theme.dart#L262-L263

    and recent example where list_tile_test.dart font size test fails when updating bodyText1 to bodyLarge in list_tile.dart, so i resorted to bodyMedium in #101900

    https://github.com/flutter/flutter/pull/102167/files#diff-c4ef7c798c820ecda6cab38be1c2d619d5349dc478889f3a54ebbe07f60c11f2L657

  6. rydmike commented on Apr 19, 2022

    @rydmike
    ContributorAuthor

    Maybe the token DB is correct, and thus Flutter too, but in that case the spec shown in web guide is wrong. Both can't be right, was my main point with this observation too 😄 Curious to find out which one it is supposed to be. Perhaps the token DB is correct but web never got updated. I thought it was generated using same token db, but apparently not.

  7. darrenaustin commented on Apr 28, 2022

    @darrenaustin
    Contributor

    Just heard back from the design team and it is a bug in the spec, which will be fixed in the next major roll out of the site.

    The DB is correct with 0.5, so Flutter is using the right value.

  8. rydmike commented on Apr 29, 2022

    @rydmike
    ContributorAuthor

    @darrenaustin OK thanks, good to know. I will have to update the value I have used then, as I have been using the M3 published guide spec value, but no problem, as long as it is sorted what it should be. Took a surprising long time to get an answer to simple question 😉

    I won't even be needed it all once the Typography lands in stable channel. I'm guessing at version released at Google IO.

  9. added
    r: fixedIssue is closed as already fixed in a newer version
    on May 2, 2022
  10. github-actions commented on May 16, 2022

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  11. locked as resolved and limited conversation to collaborators on May 16, 2022
  12. moved this to ✅ Done in Material 3on May 23, 2022
  13. moved this from ✅ Done to Not Planned in Material 3on May 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

a: typographyText rendering, possibly libtxtfound in release: 2.13Found to occur in 2.13frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: material_uimaterial_ui package in flutter/packagesr: fixedIssue is closed as already fixed in a newer version

Type

No type

Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions