Skip to content

Commit

Permalink
Added useMaterial3 parameters to the light, dark and fallback ThemeDa…
Browse files Browse the repository at this point in the history
…ta constructors. (#105944)
  • Loading branch information
darrenaustin authored Jun 14, 2022
1 parent f1c637e commit 32981c4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
12 changes: 9 additions & 3 deletions packages/flutter/lib/src/material/theme_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -961,13 +961,19 @@ class ThemeData with Diagnosticable {
///
/// This theme does not contain text geometry. Instead, it is expected that
/// this theme is localized using text geometry using [ThemeData.localize].
factory ThemeData.light() => ThemeData(brightness: Brightness.light);
factory ThemeData.light({bool? useMaterial3}) => ThemeData(
brightness: Brightness.light,
useMaterial3: useMaterial3,
);

/// A default dark theme with a teal secondary [ColorScheme] color.
///
/// This theme does not contain text geometry. Instead, it is expected that
/// this theme is localized using text geometry using [ThemeData.localize].
factory ThemeData.dark() => ThemeData(brightness: Brightness.dark);
factory ThemeData.dark({bool? useMaterial3}) => ThemeData(
brightness: Brightness.dark,
useMaterial3: useMaterial3,
);

/// The default color theme. Same as [ThemeData.light].
///
Expand All @@ -978,7 +984,7 @@ class ThemeData with Diagnosticable {
///
/// Most applications would use [Theme.of], which provides correct localized
/// text geometry.
factory ThemeData.fallback() => ThemeData.light();
factory ThemeData.fallback({bool? useMaterial3}) => ThemeData.light(useMaterial3: useMaterial3);

/// The overall theme brightness.
///
Expand Down
14 changes: 14 additions & 0 deletions packages/flutter/test/material/theme_data_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,20 @@ void main() {
expect(darkTheme.primaryTextTheme.headline6!.color, typography.white.headline6!.color);
});

test('light, dark and fallback constructors support useMaterial3', () {
final ThemeData lightTheme = ThemeData.light(useMaterial3: true);
expect(lightTheme.useMaterial3, true);
expect(lightTheme.typography, Typography.material2021());

final ThemeData darkTheme = ThemeData.dark(useMaterial3: true);
expect(darkTheme.useMaterial3, true);
expect(darkTheme.typography, Typography.material2021());

final ThemeData fallbackTheme = ThemeData.light(useMaterial3: true);
expect(fallbackTheme.useMaterial3, true);
expect(fallbackTheme.typography, Typography.material2021());
});

testWidgets('Defaults to MaterialTapTargetBehavior.padded on mobile platforms and MaterialTapTargetBehavior.shrinkWrap on desktop', (WidgetTester tester) async {
final ThemeData themeData = ThemeData(platform: defaultTargetPlatform);
switch (defaultTargetPlatform) {
Expand Down

0 comments on commit 32981c4

Please sign in to comment.