Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Scaffold overrides DefaultTextStyle #120334

Copy link
Copy link
Open
@creativecreatorormaybenot

Description

Problem

When using a Scaffold widget, any parent DefaultTextStyle will subsequently be ignored:

DefaultTextStyle.merge(
  style: TextStyle(
    letterSpacing: -0.5,
  ),
  child: Scaffold(
    body: Center(
      // The default text style set above is ignored here.
      child: Text('Foo'),
    ),
  ),
)

Use case

This entirely prevents setting a global default text style (e.g. to adjust the letter spacing for all text widgets in an app) when using Scaffold at all (which is usually used on every page in a Flutter app).

Cause

The reason this happens is because every Scaffold inserts a Material widget and this in turn overrides the DefaultTextStyle with TextTheme.bodyMedium:

style: widget.textStyle ?? Theme.of(context).textTheme.bodyMedium!,

This is also not documented. Neither the Scaffold widget mentions this behavior, nor the Material widget itself. Material.textStyle only states the following (and not that omitting the parameter will override DefaultTextStyle):

The typographical style to use for text within this material.

The only mention of this in the docs I could find was in TextTheme.bodyMedium:

The default text style for Material.


This, however, does not help the problem at all as there is no way to prevent the Material widget from overriding the DefaultTextStyle when using a Scaffold. There is no parameter for passing this. And even if there was one, we would have to manually pass our default text style to every Scaffold or Material usage within the app.
To me, this seems to be a fundamental issue.

Proposal

I propose the following:

  1. The documentation should be fixed.

And any (or a combination) of the following should be implemented:

  1. A flag on the app's Theme/TextTheme passed to MaterialApp that disables defaulting to bodyMedium if the app does not use bodyMedium.
  2. A flag on the Scaffold widget to respect the DefaultTextStyle.
  3. A way to prevent Material from overriding the default text style.
gnprice, TiLogic, utamori, lavinov-mercury, VinhNgT and 3 more

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projectIssues that are less important to the Flutter projectc: new featureNothing broken; request for a new capabilityNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to FlutterA detailed proposal for a change to Flutterd: api docsIssues with https://api.flutter.dev/Issues with https://api.flutter.dev/f: material designflutter/packages/flutter/material repository.flutter/packages/flutter/material repository.frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.team-designOwned by Design Languages teamOwned by Design Languages teamtriaged-designTriaged by Design Languages teamTriaged by Design Languages team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.