Added useMaterial3 parameters to the light, dark and fallback ThemeData constructors. (#105944)
This commit is contained in:
@@ -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].
|
||||
///
|
||||
@@ -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.
|
||||
///
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user