Skip to content

Typography text styles aren't fully specified, yielding unexpected behavior #12550

@tvolkert

Description

@tvolkert

Use case:

  1. Create a shared constant app-wide theme, like so:
final appTheme = new ThemeData(
  // Define whatever styles you want, but leave the
  // text themes unspecified (and thus default).
  // In so doing, they'll get the default typography
  // values (e.g. blackMountainView), which as of
  // #12249, specify inherit:true
);
  1. Create a Text widget somewhere in your app, with styles like so:
  new Text(
    'sample text',
    style: appTheme.primaryTextTheme.button,
  ),
  1. The styling of the text widget will be appTheme.primaryTextTheme.button, merged with whatever DefaultTextStyle happens to live immediately above the widget in the tree. This is unexpected, since the user doesn't expect the default primaryTextTheme.button style to leave some properties ambiguously defined.

Potential solutions:

  1. Do nothing, and call this working as intended. If the user doesn't want to inherit properties this way, they can do the following:
  new DefaultTextStyle(
    style: appTheme.primaryTextTheme.button,
    child: new Text(
      'sample text',
    ),
  ),
  1. Add the ability to clone a TextStyle but change the inherit property, yielding user code like this:
  new Text(
    'sample text',
    style: appTheme.primaryTextTheme.button.copyWith(new TextStyle(inherit: false)),
  ),
  1. ???

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions