Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 5 additions & 36 deletions packages/material_ui/lib/src/typography.dart
Original file line number Diff line number Diff line change
Expand Up @@ -164,52 +164,21 @@ class Typography with Diagnosticable {

/// Creates a typography instance using Material Design 3 2021 defaults.
///
/// Text colors are derived from [colorScheme]. For a light [colorScheme],
/// every style in the resulting [Typography.black] uses
/// [ColorScheme.onSurface] and every style in [Typography.white] uses
/// [ColorScheme.surface]. For a dark [colorScheme], these are reversed. The
/// same colors are used for [TextStyle.decorationColor].
///
/// The default values for [black] and [white] depend on [platform]:
/// [blackCupertino] and [whiteCupertino] on iOS, [blackRedwoodCity] and
/// [whiteRedwoodCity] on macOS, [blackRedmond] and [whiteRedmond] on
/// Windows, [blackHelsinki] and [whiteHelsinki] on Linux, and
/// [blackMountainView] and [whiteMountainView] otherwise. If [platform] is
/// null then both [black] and [white] must be specified.
/// If [platform] is [TargetPlatform.iOS] or [TargetPlatform.macOS], the
/// default values for [black] and [white] are [blackCupertino] and
/// [whiteCupertino] respectively. Otherwise they are [blackMountainView] and
/// [whiteMountainView]. If [platform] is null then both [black] and [white]
/// must be specified.
Comment on lines +167 to +171

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The reverted documentation states that macOS defaults to blackCupertino and whiteCupertino, and that other platforms (like Windows and Linux) default to blackMountainView and whiteMountainView. However, looking at Typography._withPlatform, macOS actually defaults to blackRedwoodCity/whiteRedwoodCity, Windows to blackRedmond/whiteRedmond, and Linux to blackHelsinki/whiteHelsinki.

Please keep the more accurate platform-dependent documentation that was introduced in the original PR, rather than reverting to this outdated and incorrect description.

  /// The default values for [black] and [white] depend on [platform]:
  /// [blackCupertino] and [whiteCupertino] on iOS, [blackRedwoodCity] and
  /// [whiteRedwoodCity] on macOS, [blackRedmond] and [whiteRedmond] on
  /// Windows, [blackHelsinki] and [whiteHelsinki] on Linux, and
  /// [blackMountainView] and [whiteMountainView] otherwise. If [platform] is
  /// null then both [black] and [white] must be specified.

///
/// The default values for [englishLike], [dense], and [tall] are
/// [englishLike2021], [dense2021], and [tall2021].
///
/// The [black] and [white] parameters are deprecated. Only their non-color
/// properties (such as font family) are used. Any [TextStyle.color] or
/// [TextStyle.decorationColor] they specify is replaced with a color from
/// [colorScheme] as described above. To customize the text theme's colors,
/// call [copyWith] on the result:
///
/// ```dart
/// final Typography base = Typography.material2021(colorScheme: colorScheme);
/// final Typography typography = base.copyWith(
/// black: base.black.merge(myBlack),
/// white: base.white.merge(myWhite),
/// );
/// ```
///
/// See also:
/// * <https://m3.material.io/styles/typography>
factory Typography.material2021({
TargetPlatform? platform = TargetPlatform.android,
ColorScheme colorScheme = const ColorScheme.light(),
@Deprecated(
'Text colors are derived from colorScheme, so colors in this text theme are ignored. '
'Use copyWith on the result to customize the black text theme. '
'This feature was deprecated after material_ui v1.8.0.',
)
TextTheme? black,
@Deprecated(
'Text colors are derived from colorScheme, so colors in this text theme are ignored. '
'Use copyWith on the result to customize the white text theme. '
'This feature was deprecated after material_ui v1.8.0.',
)
TextTheme? white,
TextTheme? englishLike,
TextTheme? dense,
Expand Down

This file was deleted.

41 changes: 0 additions & 41 deletions packages/material_ui/test/typography_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -445,47 +445,6 @@ void main() {
expect(textTheme.labelSmall!.color, light);
});

group('Typography.material2021 deprecated black and white', () {
const lightScheme = ColorScheme.light(onSurface: Color(0xFF000001), surface: Color(0xFFFFFFF1));
const custom = TextTheme(
bodyMedium: TextStyle(
fontFamily: 'Custom',
color: Color(0xFFFF0000),
decorationColor: Color(0xFF00FF00),
),
);

test('keep non-color properties but replace colors from the color scheme', () {
final typography = Typography.material2021(
colorScheme: lightScheme,
// ignore: deprecated_member_use_from_same_package
black: custom,
// ignore: deprecated_member_use_from_same_package
white: custom,
);
expect(typography.black.bodyMedium!.fontFamily, 'Custom');
expect(typography.black.bodyMedium!.color, lightScheme.onSurface);
expect(typography.black.bodyMedium!.decorationColor, lightScheme.onSurface);
expect(typography.white.bodyMedium!.fontFamily, 'Custom');
expect(typography.white.bodyMedium!.color, lightScheme.surface);
expect(typography.white.bodyMedium!.decorationColor, lightScheme.surface);
});

test('copyWith can be used to customize colors instead', () {
final base = Typography.material2021(colorScheme: lightScheme);
final Typography typography = base.copyWith(
black: base.black.merge(custom),
white: base.white.merge(custom),
);
expect(typography.black.bodyMedium!.fontFamily, 'Custom');
expect(typography.black.bodyMedium!.color, const Color(0xFFFF0000));
expect(typography.white.bodyMedium!.color, const Color(0xFFFF0000));
// Styles that are not overridden keep the generated values.
expect(typography.black.bodyLarge!.fontFamily, 'Roboto');
expect(typography.black.bodyLarge!.color, lightScheme.onSurface);
});
});

test('Typography.material2021 colors black and white text themes from the colorScheme', () {
const lightScheme = ColorScheme.light(onSurface: Color(0xFF000001), surface: Color(0xFFFFFFF1));
const darkScheme = ColorScheme.dark(onSurface: Color(0xFFFFFFF2), surface: Color(0xFF000002));
Expand Down
Loading