diff --git a/packages/material_ui/lib/src/app_bar.dart b/packages/material_ui/lib/src/app_bar.dart index cdbb452b5009..cb05c7ee90c2 100644 --- a/packages/material_ui/lib/src/app_bar.dart +++ b/packages/material_ui/lib/src/app_bar.dart @@ -906,6 +906,8 @@ class _AppBarState extends State { final ThemeData theme = Theme.of(context); final IconButtonThemeData iconButtonTheme = IconButtonTheme.of(context); final AppBarThemeData appBarTheme = AppBarTheme.of(context); + final StyleVariant effectiveVariant = appBarTheme.variant ?? theme.variant; + assert(effectiveVariant != .material3Expressive, kUnsupportedStyleVariantAssertionMessage); final AppBarThemeData defaults = theme.useMaterial3 ? _AppBarDefaultsM3(context) : _AppBarDefaultsM2(context); diff --git a/packages/material_ui/lib/src/app_bar_theme.dart b/packages/material_ui/lib/src/app_bar_theme.dart index 93f5ee74dbf4..877d3c8a416c 100644 --- a/packages/material_ui/lib/src/app_bar_theme.dart +++ b/packages/material_ui/lib/src/app_bar_theme.dart @@ -11,6 +11,7 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart'; import 'package:flutter/widgets.dart'; +import 'debug.dart'; import 'theme.dart'; // Examples can assume: @@ -410,10 +411,12 @@ class AppBarThemeData with Diagnosticable { this.titleTextStyle, this.systemOverlayStyle, this.actionsPadding, + this.variant, }) : assert( color == null || backgroundColor == null, 'The color and backgroundColor parameters mean the same thing. Only specify one.', - ); + ), + assert(variant != .material3Expressive, kUnsupportedStyleVariantAssertionMessage); /// Overrides the default value of [AppBar.backgroundColor]. final Color? backgroundColor; @@ -466,6 +469,9 @@ class AppBarThemeData with Diagnosticable { /// Overrides the default value of [AppBar.actionsPadding]. final EdgeInsetsGeometry? actionsPadding; + /// The style variant of Material Design used by [AppBar]. + final StyleVariant? variant; + /// Creates a copy of this object but with the given fields replaced with the /// new values. AppBarThemeData copyWith({ @@ -491,6 +497,7 @@ class AppBarThemeData with Diagnosticable { TextStyle? titleTextStyle, SystemUiOverlayStyle? systemOverlayStyle, EdgeInsetsGeometry? actionsPadding, + StyleVariant? variant, }) { return AppBarThemeData( backgroundColor: backgroundColor ?? color ?? this.backgroundColor, @@ -510,6 +517,7 @@ class AppBarThemeData with Diagnosticable { titleTextStyle: titleTextStyle ?? this.titleTextStyle, systemOverlayStyle: systemOverlayStyle ?? this.systemOverlayStyle, actionsPadding: actionsPadding ?? this.actionsPadding, + variant: variant ?? this.variant, ); } @@ -538,6 +546,7 @@ class AppBarThemeData with Diagnosticable { titleTextStyle: TextStyle.lerp(a.titleTextStyle, b.titleTextStyle, t), systemOverlayStyle: t < 0.5 ? a.systemOverlayStyle : b.systemOverlayStyle, actionsPadding: EdgeInsetsGeometry.lerp(a.actionsPadding, b.actionsPadding, t), + variant: t < 0.5 ? a.variant : b.variant, ); } @@ -560,6 +569,7 @@ class AppBarThemeData with Diagnosticable { titleTextStyle, systemOverlayStyle, actionsPadding, + variant, ); @override @@ -587,7 +597,8 @@ class AppBarThemeData with Diagnosticable { other.toolbarTextStyle == toolbarTextStyle && other.titleTextStyle == titleTextStyle && other.systemOverlayStyle == systemOverlayStyle && - other.actionsPadding == actionsPadding; + other.actionsPadding == actionsPadding && + other.variant == variant; } @override @@ -633,5 +644,6 @@ class AppBarThemeData with Diagnosticable { defaultValue: null, ), ); + properties.add(EnumProperty('variant', variant, defaultValue: null)); } } diff --git a/packages/material_ui/lib/src/debug.dart b/packages/material_ui/lib/src/debug.dart index d11299d43337..ab74005ebb4e 100644 --- a/packages/material_ui/lib/src/debug.dart +++ b/packages/material_ui/lib/src/debug.dart @@ -11,6 +11,11 @@ import 'scaffold.dart' show Scaffold, ScaffoldMessenger; // Examples can assume: // late BuildContext context; +/// The assertion message used while Material components do not yet support +/// Material 3 Expressive. +const String kUnsupportedStyleVariantAssertionMessage = + 'Only material3 is supported. See https://github.com/orgs/flutter/projects/250 to track support for material3Expressive.'; + /// Asserts that the given context has a [Material] ancestor within the closest /// [LookupBoundary]. /// diff --git a/packages/material_ui/lib/src/elevated_button.dart b/packages/material_ui/lib/src/elevated_button.dart index 25a0af018af3..3f02044c7562 100644 --- a/packages/material_ui/lib/src/elevated_button.dart +++ b/packages/material_ui/lib/src/elevated_button.dart @@ -18,6 +18,7 @@ import 'button_style_button.dart'; import 'color_scheme.dart'; import 'colors.dart'; import 'constants.dart'; +import 'debug.dart'; import 'elevated_button_theme.dart'; import 'ink_ripple.dart'; import 'ink_well.dart'; @@ -392,6 +393,8 @@ class ElevatedButton extends ButtonStyleButton { @override ButtonStyle defaultStyleOf(BuildContext context) { final ThemeData theme = Theme.of(context); + final StyleVariant effectiveVariant = ElevatedButtonTheme.of(context).variant ?? theme.variant; + assert(effectiveVariant != .material3Expressive, kUnsupportedStyleVariantAssertionMessage); final ColorScheme colorScheme = theme.colorScheme; final ButtonStyle buttonStyle = theme.useMaterial3 ? _ElevatedButtonDefaultsM3(context) diff --git a/packages/material_ui/lib/src/elevated_button_theme.dart b/packages/material_ui/lib/src/elevated_button_theme.dart index da92888243ed..8851720e9887 100644 --- a/packages/material_ui/lib/src/elevated_button_theme.dart +++ b/packages/material_ui/lib/src/elevated_button_theme.dart @@ -9,6 +9,7 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/widgets.dart'; import 'button_style.dart'; +import 'debug.dart'; import 'theme.dart'; // Examples can assume: @@ -39,7 +40,8 @@ class ElevatedButtonThemeData with Diagnosticable { /// Creates an [ElevatedButtonThemeData]. /// /// The [style] may be null. - const ElevatedButtonThemeData({this.style}); + const ElevatedButtonThemeData({this.style, this.variant}) + : assert(variant != .material3Expressive, kUnsupportedStyleVariantAssertionMessage); /// Overrides for [ElevatedButton]'s default style. /// @@ -50,6 +52,9 @@ class ElevatedButtonThemeData with Diagnosticable { /// If [style] is null, then this theme doesn't override anything. final ButtonStyle? style; + /// The style variant of Material Design used by [ElevatedButton]. + final StyleVariant? variant; + /// Linearly interpolate between two elevated button themes. static ElevatedButtonThemeData? lerp( ElevatedButtonThemeData? a, @@ -59,11 +64,14 @@ class ElevatedButtonThemeData with Diagnosticable { if (identical(a, b)) { return a; } - return ElevatedButtonThemeData(style: ButtonStyle.lerp(a?.style, b?.style, t)); + return ElevatedButtonThemeData( + style: ButtonStyle.lerp(a?.style, b?.style, t), + variant: t < 0.5 ? a?.variant : b?.variant, + ); } @override - int get hashCode => style.hashCode; + int get hashCode => Object.hash(style, variant); @override bool operator ==(Object other) { @@ -73,13 +81,14 @@ class ElevatedButtonThemeData with Diagnosticable { if (other.runtimeType != runtimeType) { return false; } - return other is ElevatedButtonThemeData && other.style == style; + return other is ElevatedButtonThemeData && other.style == style && other.variant == variant; } @override void debugFillProperties(DiagnosticPropertiesBuilder properties) { super.debugFillProperties(properties); properties.add(DiagnosticsProperty('style', style, defaultValue: null)); + properties.add(EnumProperty('variant', variant, defaultValue: null)); } } diff --git a/packages/material_ui/lib/src/filled_button.dart b/packages/material_ui/lib/src/filled_button.dart index 8e252ae39fc8..63d4d959c137 100644 --- a/packages/material_ui/lib/src/filled_button.dart +++ b/packages/material_ui/lib/src/filled_button.dart @@ -19,6 +19,7 @@ import 'button_style_button.dart'; import 'color_scheme.dart'; import 'colors.dart'; import 'constants.dart'; +import 'debug.dart'; import 'filled_button_theme.dart'; import 'ink_well.dart'; import 'material_state.dart'; @@ -430,13 +431,16 @@ class FilledButton extends ButtonStyleButton { /// [ButtonStyle.padding] is reduced from 24 to 16. @override ButtonStyle defaultStyleOf(BuildContext context) { + final ThemeData theme = Theme.of(context); + final StyleVariant effectiveVariant = FilledButtonTheme.of(context).variant ?? theme.variant; + assert(effectiveVariant != .material3Expressive, kUnsupportedStyleVariantAssertionMessage); final ButtonStyle buttonStyle = switch (_variant) { _FilledButtonVariant.filled => _FilledButtonDefaultsM3(context), _FilledButtonVariant.tonal => _FilledTonalButtonDefaultsM3(context), }; if (_addPadding) { - final bool useMaterial3 = Theme.of(context).useMaterial3; + final bool useMaterial3 = theme.useMaterial3; final double defaultFontSize = buttonStyle.textStyle?.resolve(const {})?.fontSize ?? 14.0; final double effectiveTextScale = diff --git a/packages/material_ui/lib/src/filled_button_theme.dart b/packages/material_ui/lib/src/filled_button_theme.dart index 61db92eae255..e648e635b568 100644 --- a/packages/material_ui/lib/src/filled_button_theme.dart +++ b/packages/material_ui/lib/src/filled_button_theme.dart @@ -9,6 +9,7 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/widgets.dart'; import 'button_style.dart'; +import 'debug.dart'; import 'theme.dart'; // Examples can assume: @@ -39,7 +40,8 @@ class FilledButtonThemeData with Diagnosticable { /// Creates an [FilledButtonThemeData]. /// /// The [style] may be null. - const FilledButtonThemeData({this.style}); + const FilledButtonThemeData({this.style, this.variant}) + : assert(variant != .material3Expressive, kUnsupportedStyleVariantAssertionMessage); /// Overrides for [FilledButton]'s default style. /// @@ -50,16 +52,22 @@ class FilledButtonThemeData with Diagnosticable { /// If [style] is null, then this theme doesn't override anything. final ButtonStyle? style; + /// The style variant of Material Design used by [FilledButton]. + final StyleVariant? variant; + /// Linearly interpolate between two filled button themes. static FilledButtonThemeData? lerp(FilledButtonThemeData? a, FilledButtonThemeData? b, double t) { if (identical(a, b)) { return a; } - return FilledButtonThemeData(style: ButtonStyle.lerp(a?.style, b?.style, t)); + return FilledButtonThemeData( + style: ButtonStyle.lerp(a?.style, b?.style, t), + variant: t < 0.5 ? a?.variant : b?.variant, + ); } @override - int get hashCode => style.hashCode; + int get hashCode => Object.hash(style, variant); @override bool operator ==(Object other) { @@ -69,13 +77,14 @@ class FilledButtonThemeData with Diagnosticable { if (other.runtimeType != runtimeType) { return false; } - return other is FilledButtonThemeData && other.style == style; + return other is FilledButtonThemeData && other.style == style && other.variant == variant; } @override void debugFillProperties(DiagnosticPropertiesBuilder properties) { super.debugFillProperties(properties); properties.add(DiagnosticsProperty('style', style, defaultValue: null)); + properties.add(EnumProperty('variant', variant, defaultValue: null)); } } diff --git a/packages/material_ui/lib/src/floating_action_button.dart b/packages/material_ui/lib/src/floating_action_button.dart index b77189cd123b..d7d948d5b8ec 100644 --- a/packages/material_ui/lib/src/floating_action_button.dart +++ b/packages/material_ui/lib/src/floating_action_button.dart @@ -15,6 +15,7 @@ import 'package:flutter/widgets.dart'; import 'button.dart'; import 'color_scheme.dart'; +import 'debug.dart'; import 'floating_action_button_theme.dart'; import 'scaffold.dart'; import 'text_theme.dart'; @@ -491,6 +492,8 @@ class FloatingActionButton extends StatelessWidget { final FloatingActionButtonThemeData floatingActionButtonTheme = FloatingActionButtonTheme.of( context, ); + final StyleVariant effectiveVariant = floatingActionButtonTheme.variant ?? theme.variant; + assert(effectiveVariant != .material3Expressive, kUnsupportedStyleVariantAssertionMessage); final FloatingActionButtonThemeData defaults = theme.useMaterial3 ? _FABDefaultsM3(context, _floatingActionButtonType, child != null) : _FABDefaultsM2(context, _floatingActionButtonType, child != null); diff --git a/packages/material_ui/lib/src/floating_action_button_theme.dart b/packages/material_ui/lib/src/floating_action_button_theme.dart index 5abfc47b49ee..cb3ad170c1f7 100644 --- a/packages/material_ui/lib/src/floating_action_button_theme.dart +++ b/packages/material_ui/lib/src/floating_action_button_theme.dart @@ -15,6 +15,7 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter/widgets.dart'; +import 'debug.dart'; import 'theme.dart'; // Examples can assume: @@ -64,7 +65,11 @@ class FloatingActionButtonThemeData with Diagnosticable { this.extendedPadding, this.extendedTextStyle, this.mouseCursor, - }); + this.variant, + }) : assert(variant != .material3Expressive, kUnsupportedStyleVariantAssertionMessage); + + /// The style variant of Material Design used by [FloatingActionButton]. + final StyleVariant? variant; /// Color to be used for the unselected, enabled [FloatingActionButton]'s /// foreground. @@ -171,6 +176,7 @@ class FloatingActionButtonThemeData with Diagnosticable { EdgeInsetsGeometry? extendedPadding, TextStyle? extendedTextStyle, WidgetStateProperty? mouseCursor, + StyleVariant? variant, }) { return FloatingActionButtonThemeData( foregroundColor: foregroundColor ?? this.foregroundColor, @@ -194,6 +200,7 @@ class FloatingActionButtonThemeData with Diagnosticable { extendedPadding: extendedPadding ?? this.extendedPadding, extendedTextStyle: extendedTextStyle ?? this.extendedTextStyle, mouseCursor: mouseCursor ?? this.mouseCursor, + variant: variant ?? this.variant, ); } @@ -248,6 +255,7 @@ class FloatingActionButtonThemeData with Diagnosticable { extendedPadding: EdgeInsetsGeometry.lerp(a?.extendedPadding, b?.extendedPadding, t), extendedTextStyle: TextStyle.lerp(a?.extendedTextStyle, b?.extendedTextStyle, t), mouseCursor: t < 0.5 ? a?.mouseCursor : b?.mouseCursor, + variant: t < 0.5 ? a?.variant : b?.variant, ); } @@ -272,7 +280,7 @@ class FloatingActionButtonThemeData with Diagnosticable { extendedSizeConstraints, extendedIconLabelSpacing, extendedPadding, - Object.hash(extendedTextStyle, mouseCursor), + Object.hash(extendedTextStyle, mouseCursor, variant), ); @override @@ -304,7 +312,8 @@ class FloatingActionButtonThemeData with Diagnosticable { other.extendedIconLabelSpacing == extendedIconLabelSpacing && other.extendedPadding == extendedPadding && other.extendedTextStyle == extendedTextStyle && - other.mouseCursor == mouseCursor; + other.mouseCursor == mouseCursor && + other.variant == variant; } @override @@ -368,6 +377,7 @@ class FloatingActionButtonThemeData with Diagnosticable { defaultValue: null, ), ); + properties.add(EnumProperty('variant', variant, defaultValue: null)); } } diff --git a/packages/material_ui/lib/src/icon_button.dart b/packages/material_ui/lib/src/icon_button.dart index 9f026b7aa3dc..d093d3686467 100644 --- a/packages/material_ui/lib/src/icon_button.dart +++ b/packages/material_ui/lib/src/icon_button.dart @@ -718,6 +718,9 @@ class IconButton extends StatelessWidget { final ThemeData theme = Theme.of(context); if (theme.useMaterial3) { + final StyleVariant effectiveVariant = IconButtonTheme.of(context).variant ?? theme.variant; + assert(effectiveVariant != .material3Expressive, kUnsupportedStyleVariantAssertionMessage); + final Size? minSize = constraints == null ? null : Size(constraints!.minWidth, constraints!.minHeight); diff --git a/packages/material_ui/lib/src/icon_button_theme.dart b/packages/material_ui/lib/src/icon_button_theme.dart index 0d38686dba0f..e20a5d27be3c 100644 --- a/packages/material_ui/lib/src/icon_button_theme.dart +++ b/packages/material_ui/lib/src/icon_button_theme.dart @@ -9,6 +9,7 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/widgets.dart'; import 'button_style.dart'; +import 'debug.dart'; import 'theme.dart'; // Examples can assume: @@ -39,7 +40,8 @@ class IconButtonThemeData with Diagnosticable { /// Creates a [IconButtonThemeData]. /// /// The [style] may be null. - const IconButtonThemeData({this.style}); + const IconButtonThemeData({this.style, this.variant}) + : assert(variant != .material3Expressive, kUnsupportedStyleVariantAssertionMessage); /// Overrides for [IconButton]'s default style if [ThemeData.useMaterial3] /// is set to true. @@ -50,16 +52,22 @@ class IconButtonThemeData with Diagnosticable { /// If [style] is null, then this theme doesn't override anything. final ButtonStyle? style; + /// The style variant of Material Design used by [IconButton]. + final StyleVariant? variant; + /// Linearly interpolate between two icon button themes. static IconButtonThemeData? lerp(IconButtonThemeData? a, IconButtonThemeData? b, double t) { if (identical(a, b)) { return a; } - return IconButtonThemeData(style: ButtonStyle.lerp(a?.style, b?.style, t)); + return IconButtonThemeData( + style: ButtonStyle.lerp(a?.style, b?.style, t), + variant: t < 0.5 ? a?.variant : b?.variant, + ); } @override - int get hashCode => style.hashCode; + int get hashCode => Object.hash(style, variant); @override bool operator ==(Object other) { @@ -69,13 +77,14 @@ class IconButtonThemeData with Diagnosticable { if (other.runtimeType != runtimeType) { return false; } - return other is IconButtonThemeData && other.style == style; + return other is IconButtonThemeData && other.style == style && other.variant == variant; } @override void debugFillProperties(DiagnosticPropertiesBuilder properties) { super.debugFillProperties(properties); properties.add(DiagnosticsProperty('style', style, defaultValue: null)); + properties.add(EnumProperty('variant', variant, defaultValue: null)); } } diff --git a/packages/material_ui/lib/src/menu_anchor.dart b/packages/material_ui/lib/src/menu_anchor.dart index 1126c8c2e03a..cdb8525076ab 100644 --- a/packages/material_ui/lib/src/menu_anchor.dart +++ b/packages/material_ui/lib/src/menu_anchor.dart @@ -26,6 +26,7 @@ import 'checkbox.dart'; import 'color_scheme.dart'; import 'colors.dart'; import 'constants.dart'; +import 'debug.dart'; import 'icons.dart'; import 'ink_well.dart'; import 'material.dart'; @@ -665,6 +666,11 @@ class _MenuAnchorState extends State with SingleTickerProviderStateM @override Widget build(BuildContext context) { + final ThemeData theme = Theme.of(context); + final MenuThemeData menuTheme = MenuTheme.of(context); + final StyleVariant effectiveVariant = menuTheme.variant ?? theme.variant; + assert(effectiveVariant != .material3Expressive, kUnsupportedStyleVariantAssertionMessage); + final Widget child = _MenuAnchorScope( state: this, animationStatus: _animationController.status, @@ -1228,6 +1234,11 @@ class _MenuItemButtonState extends State { @override Widget build(BuildContext context) { + final ThemeData theme = Theme.of(context); + final MenuButtonThemeData menuButtonTheme = MenuButtonTheme.of(context); + final StyleVariant effectiveVariant = menuButtonTheme.variant ?? theme.variant; + assert(effectiveVariant != .material3Expressive, kUnsupportedStyleVariantAssertionMessage); + // Since we don't want to use the theme style or default style from the // TextButton, we merge the styles, merging them in the right order when // each type of style exists. Each "*StyleOf" function is only called once. @@ -2108,6 +2119,11 @@ class _SubmenuButtonState extends State { @override Widget build(BuildContext context) { + final ThemeData theme = Theme.of(context); + final MenuButtonThemeData menuButtonTheme = MenuButtonTheme.of(context); + final StyleVariant effectiveVariant = menuButtonTheme.variant ?? theme.variant; + assert(effectiveVariant != .material3Expressive, kUnsupportedStyleVariantAssertionMessage); + Offset menuPaddingOffset = widget.alignmentOffset ?? Offset.zero; final EdgeInsets menuPadding = _computeMenuPadding(context); final Axis orientation = _parent?._orientation ?? Axis.vertical; diff --git a/packages/material_ui/lib/src/menu_button_theme.dart b/packages/material_ui/lib/src/menu_button_theme.dart index 11e4b2db72dc..da45c6730607 100644 --- a/packages/material_ui/lib/src/menu_button_theme.dart +++ b/packages/material_ui/lib/src/menu_button_theme.dart @@ -9,6 +9,7 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/widgets.dart'; import 'button_style.dart'; +import 'debug.dart'; import 'menu_anchor.dart'; import 'theme.dart'; @@ -53,7 +54,8 @@ class MenuButtonThemeData with Diagnosticable { /// Creates a [MenuButtonThemeData]. /// /// The [style] may be null. - const MenuButtonThemeData({this.style}); + const MenuButtonThemeData({this.style, this.variant}) + : assert(variant != .material3Expressive, kUnsupportedStyleVariantAssertionMessage); /// Overrides for [SubmenuButton] and [MenuItemButton]'s default style. /// @@ -64,16 +66,22 @@ class MenuButtonThemeData with Diagnosticable { /// If [style] is null, then this theme doesn't override anything. final ButtonStyle? style; + /// The style variant of Material Design used by menu buttons. + final StyleVariant? variant; + /// Linearly interpolate between two menu button themes. static MenuButtonThemeData? lerp(MenuButtonThemeData? a, MenuButtonThemeData? b, double t) { if (identical(a, b)) { return a; } - return MenuButtonThemeData(style: ButtonStyle.lerp(a?.style, b?.style, t)); + return MenuButtonThemeData( + style: ButtonStyle.lerp(a?.style, b?.style, t), + variant: t < 0.5 ? a?.variant : b?.variant, + ); } @override - int get hashCode => style.hashCode; + int get hashCode => Object.hash(style, variant); @override bool operator ==(Object other) { @@ -83,13 +91,14 @@ class MenuButtonThemeData with Diagnosticable { if (other.runtimeType != runtimeType) { return false; } - return other is MenuButtonThemeData && other.style == style; + return other is MenuButtonThemeData && other.style == style && other.variant == variant; } @override void debugFillProperties(DiagnosticPropertiesBuilder properties) { super.debugFillProperties(properties); properties.add(DiagnosticsProperty('style', style, defaultValue: null)); + properties.add(EnumProperty('variant', variant, defaultValue: null)); } } diff --git a/packages/material_ui/lib/src/menu_theme.dart b/packages/material_ui/lib/src/menu_theme.dart index c5d1733d0030..a933165f2f64 100644 --- a/packages/material_ui/lib/src/menu_theme.dart +++ b/packages/material_ui/lib/src/menu_theme.dart @@ -8,6 +8,7 @@ library; import 'package:flutter/foundation.dart'; import 'package:flutter/widgets.dart'; +import 'debug.dart'; import 'menu_anchor.dart'; import 'menu_style.dart'; import 'theme.dart'; @@ -37,7 +38,8 @@ import 'theme.dart'; @immutable class MenuThemeData with Diagnosticable { /// Creates a const set of properties used to configure [MenuTheme]. - const MenuThemeData({this.style, this.submenuIcon}); + const MenuThemeData({this.style, this.submenuIcon, this.variant}) + : assert(variant != .material3Expressive, kUnsupportedStyleVariantAssertionMessage); /// The [MenuStyle] of a [SubmenuButton] menu. /// @@ -53,6 +55,9 @@ class MenuThemeData with Diagnosticable { /// * [WidgetState.focused]. final WidgetStateProperty? submenuIcon; + /// The style variant of Material Design used by menus. + final StyleVariant? variant; + /// Linearly interpolate between two menu button themes. static MenuThemeData? lerp(MenuThemeData? a, MenuThemeData? b, double t) { if (identical(a, b)) { @@ -61,11 +66,12 @@ class MenuThemeData with Diagnosticable { return MenuThemeData( style: MenuStyle.lerp(a?.style, b?.style, t), submenuIcon: t < 0.5 ? a?.submenuIcon : b?.submenuIcon, + variant: t < 0.5 ? a?.variant : b?.variant, ); } @override - int get hashCode => Object.hash(style, submenuIcon); + int get hashCode => Object.hash(style, submenuIcon, variant); @override bool operator ==(Object other) { @@ -75,7 +81,10 @@ class MenuThemeData with Diagnosticable { if (other.runtimeType != runtimeType) { return false; } - return other is MenuThemeData && other.style == style && other.submenuIcon == submenuIcon; + return other is MenuThemeData && + other.style == style && + other.submenuIcon == submenuIcon && + other.variant == variant; } @override @@ -89,6 +98,7 @@ class MenuThemeData with Diagnosticable { defaultValue: null, ), ); + properties.add(EnumProperty('variant', variant, defaultValue: null)); } } diff --git a/packages/material_ui/lib/src/navigation_bar.dart b/packages/material_ui/lib/src/navigation_bar.dart index d8420a1bda27..7170d28d387b 100644 --- a/packages/material_ui/lib/src/navigation_bar.dart +++ b/packages/material_ui/lib/src/navigation_bar.dart @@ -15,6 +15,7 @@ import 'package:flutter/widgets.dart'; import 'color_scheme.dart'; import 'colors.dart'; +import 'debug.dart'; import 'elevation_overlay.dart'; import 'ink_decoration.dart'; import 'ink_well.dart'; @@ -275,9 +276,12 @@ class NavigationBar extends StatelessWidget { @override Widget build(BuildContext context) { + final ThemeData theme = Theme.of(context); final NavigationBarThemeData defaults = _defaultsFor(context); final NavigationBarThemeData navigationBarTheme = NavigationBarTheme.of(context); + final StyleVariant effectiveVariant = navigationBarTheme.variant ?? theme.variant; + assert(effectiveVariant != .material3Expressive, kUnsupportedStyleVariantAssertionMessage); final double effectiveHeight = height ?? navigationBarTheme.height ?? defaults.height!; final NavigationDestinationLabelBehavior effectiveLabelBehavior = labelBehavior ?? navigationBarTheme.labelBehavior ?? defaults.labelBehavior!; diff --git a/packages/material_ui/lib/src/navigation_bar_theme.dart b/packages/material_ui/lib/src/navigation_bar_theme.dart index 3123f6727410..fc27b9589b2a 100644 --- a/packages/material_ui/lib/src/navigation_bar_theme.dart +++ b/packages/material_ui/lib/src/navigation_bar_theme.dart @@ -8,6 +8,7 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter/widgets.dart'; +import 'debug.dart'; import 'navigation_bar.dart'; import 'theme.dart'; @@ -52,7 +53,8 @@ class NavigationBarThemeData with Diagnosticable { this.labelBehavior, this.overlayColor, this.labelPadding, - }); + this.variant, + }) : assert(variant != .material3Expressive, kUnsupportedStyleVariantAssertionMessage); /// Overrides the default value of [NavigationBar.height]. final double? height; @@ -97,6 +99,9 @@ class NavigationBarThemeData with Diagnosticable { /// Overrides the default value of [NavigationBar.labelPadding]. final EdgeInsetsGeometry? labelPadding; + /// The style variant of Material Design used by [NavigationBar]. + final StyleVariant? variant; + /// Creates a copy of this object with the given fields replaced with the /// new values. NavigationBarThemeData copyWith({ @@ -112,6 +117,7 @@ class NavigationBarThemeData with Diagnosticable { NavigationDestinationLabelBehavior? labelBehavior, WidgetStateProperty? overlayColor, EdgeInsetsGeometry? labelPadding, + StyleVariant? variant, }) { return NavigationBarThemeData( height: height ?? this.height, @@ -126,6 +132,7 @@ class NavigationBarThemeData with Diagnosticable { labelBehavior: labelBehavior ?? this.labelBehavior, overlayColor: overlayColor ?? this.overlayColor, labelPadding: labelPadding ?? this.labelPadding, + variant: variant ?? this.variant, ); } @@ -170,6 +177,7 @@ class NavigationBarThemeData with Diagnosticable { Color.lerp, ), labelPadding: EdgeInsetsGeometry.lerp(a?.labelPadding, b?.labelPadding, t), + variant: t < 0.5 ? a?.variant : b?.variant, ); } @@ -187,6 +195,7 @@ class NavigationBarThemeData with Diagnosticable { labelBehavior, overlayColor, labelPadding, + variant, ); @override @@ -209,7 +218,8 @@ class NavigationBarThemeData with Diagnosticable { other.iconTheme == iconTheme && other.labelBehavior == labelBehavior && other.overlayColor == overlayColor && - other.labelPadding == labelPadding; + other.labelPadding == labelPadding && + other.variant == variant; } @override @@ -255,6 +265,7 @@ class NavigationBarThemeData with Diagnosticable { properties.add( DiagnosticsProperty('labelPadding', labelPadding, defaultValue: null), ); + properties.add(EnumProperty('variant', variant, defaultValue: null)); } } diff --git a/packages/material_ui/lib/src/navigation_rail.dart b/packages/material_ui/lib/src/navigation_rail.dart index 20b0ba29d5ed..518af95037b4 100644 --- a/packages/material_ui/lib/src/navigation_rail.dart +++ b/packages/material_ui/lib/src/navigation_rail.dart @@ -13,6 +13,7 @@ import 'dart:ui'; import 'package:flutter/widgets.dart'; import 'color_scheme.dart'; +import 'debug.dart'; import 'ink_well.dart'; import 'material.dart'; import 'material_localizations.dart'; @@ -444,8 +445,11 @@ class _NavigationRailState extends State with TickerProviderStat @override Widget build(BuildContext context) { + final ThemeData theme = Theme.of(context); final NavigationRailThemeData navigationRailTheme = NavigationRailTheme.of(context); - final NavigationRailThemeData defaults = Theme.of(context).useMaterial3 + final StyleVariant effectiveVariant = navigationRailTheme.variant ?? theme.variant; + assert(effectiveVariant != .material3Expressive, kUnsupportedStyleVariantAssertionMessage); + final NavigationRailThemeData defaults = theme.useMaterial3 ? _NavigationRailDefaultsM3(context) : _NavigationRailDefaultsM2(context); final MaterialLocalizations localizations = MaterialLocalizations.of(context); @@ -489,7 +493,7 @@ class _NavigationRailState extends State with TickerProviderStat // For backwards compatibility, in M2 the opacity of the unselected icons needs // to be set to the default if it isn't in the given theme. This can be removed // when Material 3 is the default. - final IconThemeData effectiveUnselectedIconTheme = Theme.of(context).useMaterial3 + final IconThemeData effectiveUnselectedIconTheme = theme.useMaterial3 ? unselectedIconTheme : unselectedIconTheme.copyWith( opacity: unselectedIconTheme.opacity ?? defaults.unselectedIconTheme!.opacity, diff --git a/packages/material_ui/lib/src/navigation_rail_theme.dart b/packages/material_ui/lib/src/navigation_rail_theme.dart index 4e3308446691..e215fddc66f1 100644 --- a/packages/material_ui/lib/src/navigation_rail_theme.dart +++ b/packages/material_ui/lib/src/navigation_rail_theme.dart @@ -11,6 +11,7 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter/widgets.dart'; +import 'debug.dart'; import 'navigation_rail.dart'; import 'theme.dart'; @@ -54,7 +55,8 @@ class NavigationRailThemeData with Diagnosticable { this.indicatorShape, this.minWidth, this.minExtendedWidth, - }); + this.variant, + }) : assert(variant != .material3Expressive, kUnsupportedStyleVariantAssertionMessage); /// Color to be used for the [NavigationRail]'s background. final Color? backgroundColor; @@ -105,6 +107,9 @@ class NavigationRailThemeData with Diagnosticable { /// is extended. final double? minExtendedWidth; + /// The style variant of Material Design used by [NavigationRail]. + final StyleVariant? variant; + /// Creates a copy of this object with the given fields replaced with the /// new values. NavigationRailThemeData copyWith({ @@ -121,6 +126,7 @@ class NavigationRailThemeData with Diagnosticable { ShapeBorder? indicatorShape, double? minWidth, double? minExtendedWidth, + StyleVariant? variant, }) { return NavigationRailThemeData( backgroundColor: backgroundColor ?? this.backgroundColor, @@ -136,6 +142,7 @@ class NavigationRailThemeData with Diagnosticable { indicatorShape: indicatorShape ?? this.indicatorShape, minWidth: minWidth ?? this.minWidth, minExtendedWidth: minExtendedWidth ?? this.minExtendedWidth, + variant: variant ?? this.variant, ); } @@ -178,6 +185,7 @@ class NavigationRailThemeData with Diagnosticable { indicatorShape: ShapeBorder.lerp(a?.indicatorShape, b?.indicatorShape, t), minWidth: lerpDouble(a?.minWidth, b?.minWidth, t), minExtendedWidth: lerpDouble(a?.minExtendedWidth, b?.minExtendedWidth, t), + variant: t < 0.5 ? a?.variant : b?.variant, ); } @@ -196,6 +204,7 @@ class NavigationRailThemeData with Diagnosticable { indicatorShape, minWidth, minExtendedWidth, + variant, ); @override @@ -219,7 +228,8 @@ class NavigationRailThemeData with Diagnosticable { other.indicatorColor == indicatorColor && other.indicatorShape == indicatorShape && other.minWidth == minWidth && - other.minExtendedWidth == minExtendedWidth; + other.minExtendedWidth == minExtendedWidth && + other.variant == variant; } @override @@ -290,6 +300,7 @@ class NavigationRailThemeData with Diagnosticable { defaultValue: defaultData.minExtendedWidth, ), ); + properties.add(EnumProperty('variant', variant, defaultValue: null)); } } diff --git a/packages/material_ui/lib/src/outlined_button.dart b/packages/material_ui/lib/src/outlined_button.dart index 6ae8aa6f12b2..cd3697aa1200 100644 --- a/packages/material_ui/lib/src/outlined_button.dart +++ b/packages/material_ui/lib/src/outlined_button.dart @@ -18,6 +18,7 @@ import 'button_style_button.dart'; import 'color_scheme.dart'; import 'colors.dart'; import 'constants.dart'; +import 'debug.dart'; import 'ink_ripple.dart'; import 'ink_well.dart'; import 'material_state.dart'; @@ -348,6 +349,8 @@ class OutlinedButton extends ButtonStyleButton { @override ButtonStyle defaultStyleOf(BuildContext context) { final ThemeData theme = Theme.of(context); + final StyleVariant effectiveVariant = OutlinedButtonTheme.of(context).variant ?? theme.variant; + assert(effectiveVariant != .material3Expressive, kUnsupportedStyleVariantAssertionMessage); final ColorScheme colorScheme = theme.colorScheme; final ButtonStyle buttonStyle = theme.useMaterial3 ? _OutlinedButtonDefaultsM3(context) diff --git a/packages/material_ui/lib/src/outlined_button_theme.dart b/packages/material_ui/lib/src/outlined_button_theme.dart index 1bc14d32d7c6..e0a87cfe31ec 100644 --- a/packages/material_ui/lib/src/outlined_button_theme.dart +++ b/packages/material_ui/lib/src/outlined_button_theme.dart @@ -9,6 +9,7 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/widgets.dart'; import 'button_style.dart'; +import 'debug.dart'; import 'theme.dart'; // Examples can assume: @@ -39,7 +40,8 @@ class OutlinedButtonThemeData with Diagnosticable { /// Creates a [OutlinedButtonThemeData]. /// /// The [style] may be null. - const OutlinedButtonThemeData({this.style}); + const OutlinedButtonThemeData({this.style, this.variant}) + : assert(variant != .material3Expressive, kUnsupportedStyleVariantAssertionMessage); /// Overrides for [OutlinedButton]'s default style. /// @@ -50,6 +52,9 @@ class OutlinedButtonThemeData with Diagnosticable { /// If [style] is null, then this theme doesn't override anything. final ButtonStyle? style; + /// The style variant of Material Design used by [OutlinedButton]. + final StyleVariant? variant; + /// Linearly interpolate between two outlined button themes. static OutlinedButtonThemeData? lerp( OutlinedButtonThemeData? a, @@ -59,11 +64,14 @@ class OutlinedButtonThemeData with Diagnosticable { if (identical(a, b)) { return a; } - return OutlinedButtonThemeData(style: ButtonStyle.lerp(a?.style, b?.style, t)); + return OutlinedButtonThemeData( + style: ButtonStyle.lerp(a?.style, b?.style, t), + variant: t < 0.5 ? a?.variant : b?.variant, + ); } @override - int get hashCode => style.hashCode; + int get hashCode => Object.hash(style, variant); @override bool operator ==(Object other) { @@ -73,13 +81,14 @@ class OutlinedButtonThemeData with Diagnosticable { if (other.runtimeType != runtimeType) { return false; } - return other is OutlinedButtonThemeData && other.style == style; + return other is OutlinedButtonThemeData && other.style == style && other.variant == variant; } @override void debugFillProperties(DiagnosticPropertiesBuilder properties) { super.debugFillProperties(properties); properties.add(DiagnosticsProperty('style', style, defaultValue: null)); + properties.add(EnumProperty('variant', variant, defaultValue: null)); } } diff --git a/packages/material_ui/lib/src/progress_indicator.dart b/packages/material_ui/lib/src/progress_indicator.dart index 8e8489d5dc8a..f072f9a40f74 100644 --- a/packages/material_ui/lib/src/progress_indicator.dart +++ b/packages/material_ui/lib/src/progress_indicator.dart @@ -14,6 +14,7 @@ import 'package:cupertino_ui/cupertino_ui.dart'; import 'package:flutter/foundation.dart'; import 'color_scheme.dart'; +import 'debug.dart'; import 'material.dart'; import 'progress_indicator_theme.dart'; import 'theme.dart'; @@ -647,6 +648,10 @@ class _LinearProgressIndicatorState extends State @override Widget build(BuildContext context) { + final ThemeData theme = Theme.of(context); + final ProgressIndicatorThemeData indicatorTheme = ProgressIndicatorTheme.of(context); + final StyleVariant effectiveVariant = indicatorTheme.variant ?? theme.variant; + assert(effectiveVariant != .material3Expressive, kUnsupportedStyleVariantAssertionMessage); final TextDirection textDirection = Directionality.of(context); if (widget._effectiveValue != null) { @@ -1126,9 +1131,12 @@ class _CircularProgressIndicatorState extends State double offsetValue, double rotationValue, ) { + final ThemeData theme = Theme.of(context); final ProgressIndicatorThemeData indicatorTheme = ProgressIndicatorTheme.of(context); + final StyleVariant effectiveVariant = indicatorTheme.variant ?? theme.variant; + assert(effectiveVariant != .material3Expressive, kUnsupportedStyleVariantAssertionMessage); final bool year2023 = widget.year2023 ?? indicatorTheme.year2023 ?? true; - final ProgressIndicatorThemeData defaults = switch (Theme.of(context).useMaterial3) { + final ProgressIndicatorThemeData defaults = switch (theme.useMaterial3) { true => year2023 ? _CircularProgressIndicatorDefaultsM3Year2023( diff --git a/packages/material_ui/lib/src/progress_indicator_theme.dart b/packages/material_ui/lib/src/progress_indicator_theme.dart index 6be38c4d6ca7..307e419208d4 100644 --- a/packages/material_ui/lib/src/progress_indicator_theme.dart +++ b/packages/material_ui/lib/src/progress_indicator_theme.dart @@ -11,6 +11,7 @@ import 'dart:ui' show lerpDouble; import 'package:flutter/foundation.dart'; import 'package:flutter/widgets.dart'; +import 'debug.dart'; import 'theme.dart'; // Examples can assume: @@ -57,7 +58,8 @@ class ProgressIndicatorThemeData with Diagnosticable { ) this.year2023, this.controller, - }); + this.variant, + }) : assert(variant != .material3Expressive, kUnsupportedStyleVariantAssertionMessage); /// The color of the [ProgressIndicator]'s indicator. /// @@ -152,6 +154,9 @@ class ProgressIndicatorThemeData with Diagnosticable { /// manage its own internal [AnimationController]. final AnimationController? controller; + /// The style variant of Material Design used by progress indicators. + final StyleVariant? variant; + /// Creates a copy of this object but with the given fields replaced with the /// new values. ProgressIndicatorThemeData copyWith({ @@ -171,6 +176,7 @@ class ProgressIndicatorThemeData with Diagnosticable { EdgeInsetsGeometry? circularTrackPadding, bool? year2023, AnimationController? controller, + StyleVariant? variant, }) { return ProgressIndicatorThemeData( color: color ?? this.color, @@ -189,6 +195,7 @@ class ProgressIndicatorThemeData with Diagnosticable { circularTrackPadding: circularTrackPadding ?? this.circularTrackPadding, year2023: year2023 ?? this.year2023, controller: controller ?? this.controller, + variant: variant ?? this.variant, ); } @@ -224,6 +231,7 @@ class ProgressIndicatorThemeData with Diagnosticable { ), year2023: t < 0.5 ? a?.year2023 : b?.year2023, controller: t < 0.5 ? a?.controller : b?.controller, + variant: t < 0.5 ? a?.variant : b?.variant, ); } @@ -245,6 +253,7 @@ class ProgressIndicatorThemeData with Diagnosticable { circularTrackPadding, year2023, controller, + variant, ); @override @@ -271,7 +280,8 @@ class ProgressIndicatorThemeData with Diagnosticable { other.trackGap == trackGap && other.circularTrackPadding == circularTrackPadding && other.year2023 == year2023 && - other.controller == controller; + other.controller == controller && + other.variant == variant; } @override @@ -307,6 +317,7 @@ class ProgressIndicatorThemeData with Diagnosticable { properties.add( DiagnosticsProperty('controller', controller, defaultValue: null), ); + properties.add(EnumProperty('variant', variant, defaultValue: null)); } } diff --git a/packages/material_ui/lib/src/range_slider.dart b/packages/material_ui/lib/src/range_slider.dart index fb735a936cc7..bd50df6c0c7d 100644 --- a/packages/material_ui/lib/src/range_slider.dart +++ b/packages/material_ui/lib/src/range_slider.dart @@ -653,6 +653,8 @@ class _RangeSliderState extends State with TickerProviderStateMixin final ThemeData theme = Theme.of(context); SliderThemeData sliderTheme = SliderTheme.of(context); + final StyleVariant effectiveVariant = sliderTheme.variant ?? theme.variant; + assert(effectiveVariant != .material3Expressive, kUnsupportedStyleVariantAssertionMessage); final bool year2023 = widget.year2023 ?? sliderTheme.year2023 ?? true; final SliderThemeData defaults = theme.useMaterial3 && !year2023 ? _RangeSliderDefaultsM3(context) diff --git a/packages/material_ui/lib/src/search_anchor.dart b/packages/material_ui/lib/src/search_anchor.dart index 3763971e8faa..da98e510a370 100644 --- a/packages/material_ui/lib/src/search_anchor.dart +++ b/packages/material_ui/lib/src/search_anchor.dart @@ -19,6 +19,7 @@ import 'button_style.dart'; import 'color_scheme.dart'; import 'colors.dart'; import 'constants.dart'; +import 'debug.dart'; import 'divider.dart'; import 'divider_theme.dart'; import 'icon_button.dart'; @@ -568,6 +569,11 @@ class _SearchAnchorState extends State { @override Widget build(BuildContext context) { + final ThemeData theme = Theme.of(context); + final SearchViewThemeData viewTheme = SearchViewTheme.of(context); + final StyleVariant effectiveVariant = viewTheme.variant ?? theme.variant; + assert(effectiveVariant != .material3Expressive, kUnsupportedStyleVariantAssertionMessage); + return AnimatedOpacity( key: _anchorKey, opacity: _getOpacity(), @@ -1661,8 +1667,11 @@ class _SearchBarState extends State { @override Widget build(BuildContext context) { final TextDirection textDirection = Directionality.of(context); - final ColorScheme colorScheme = Theme.of(context).colorScheme; + final ThemeData theme = Theme.of(context); + final ColorScheme colorScheme = theme.colorScheme; final SearchBarThemeData searchBarTheme = SearchBarTheme.of(context); + final StyleVariant effectiveVariant = searchBarTheme.variant ?? theme.variant; + assert(effectiveVariant != .material3Expressive, kUnsupportedStyleVariantAssertionMessage); final SearchBarThemeData defaults = _SearchBarDefaultsM3(context); T? resolve( diff --git a/packages/material_ui/lib/src/search_bar_theme.dart b/packages/material_ui/lib/src/search_bar_theme.dart index ddce8adbd15b..21668d5e9a96 100644 --- a/packages/material_ui/lib/src/search_bar_theme.dart +++ b/packages/material_ui/lib/src/search_bar_theme.dart @@ -12,6 +12,7 @@ import 'package:flutter/rendering.dart'; import 'package:flutter/services.dart'; import 'package:flutter/widgets.dart'; +import 'debug.dart'; import 'theme.dart'; // Examples can assume: @@ -51,7 +52,8 @@ class SearchBarThemeData with Diagnosticable { this.hintStyle, this.constraints, this.textCapitalization, - }); + this.variant, + }) : assert(variant != .material3Expressive, kUnsupportedStyleVariantAssertionMessage); /// Overrides the default value of the [SearchBar.elevation]. final WidgetStateProperty? elevation; @@ -89,6 +91,9 @@ class SearchBarThemeData with Diagnosticable { /// Overrides the value of [SearchBar.textCapitalization]. final TextCapitalization? textCapitalization; + /// The style variant of Material Design used by [SearchBar]. + final StyleVariant? variant; + /// Creates a copy of this object but with the given fields replaced with the /// new values. SearchBarThemeData copyWith({ @@ -104,6 +109,7 @@ class SearchBarThemeData with Diagnosticable { WidgetStateProperty? hintStyle, BoxConstraints? constraints, TextCapitalization? textCapitalization, + StyleVariant? variant, }) { return SearchBarThemeData( elevation: elevation ?? this.elevation, @@ -118,6 +124,7 @@ class SearchBarThemeData with Diagnosticable { hintStyle: hintStyle ?? this.hintStyle, constraints: constraints ?? this.constraints, textCapitalization: textCapitalization ?? this.textCapitalization, + variant: variant ?? this.variant, ); } @@ -171,6 +178,7 @@ class SearchBarThemeData with Diagnosticable { ), constraints: BoxConstraints.lerp(a?.constraints, b?.constraints, t), textCapitalization: t < 0.5 ? a?.textCapitalization : b?.textCapitalization, + variant: t < 0.5 ? a?.variant : b?.variant, ); } @@ -188,6 +196,7 @@ class SearchBarThemeData with Diagnosticable { hintStyle, constraints, textCapitalization, + variant, ); @override @@ -210,7 +219,8 @@ class SearchBarThemeData with Diagnosticable { other.textStyle == textStyle && other.hintStyle == hintStyle && other.constraints == constraints && - other.textCapitalization == textCapitalization; + other.textCapitalization == textCapitalization && + other.variant == variant; } @override @@ -284,6 +294,7 @@ class SearchBarThemeData with Diagnosticable { defaultValue: null, ), ); + properties.add(EnumProperty('variant', variant, defaultValue: null)); } } diff --git a/packages/material_ui/lib/src/search_view_theme.dart b/packages/material_ui/lib/src/search_view_theme.dart index 563f85ac3a1c..4b729e9107c6 100644 --- a/packages/material_ui/lib/src/search_view_theme.dart +++ b/packages/material_ui/lib/src/search_view_theme.dart @@ -12,6 +12,7 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter/widgets.dart'; +import 'debug.dart'; import 'theme.dart'; // Examples can assume: @@ -53,7 +54,8 @@ class SearchViewThemeData with Diagnosticable { this.headerTextStyle, this.headerHintStyle, this.dividerColor, - }); + this.variant, + }) : assert(variant != .material3Expressive, kUnsupportedStyleVariantAssertionMessage); /// Overrides the default value of the [SearchAnchor.viewBackgroundColor]. final Color? backgroundColor; @@ -94,6 +96,9 @@ class SearchViewThemeData with Diagnosticable { /// Overrides the value of the divider color for [SearchAnchor.dividerColor]. final Color? dividerColor; + /// The style variant of Material Design used by search views. + final StyleVariant? variant; + /// Creates a copy of this object but with the given fields replaced with the /// new values. SearchViewThemeData copyWith({ @@ -110,6 +115,7 @@ class SearchViewThemeData with Diagnosticable { EdgeInsetsGeometry? barPadding, bool? shrinkWrap, Color? dividerColor, + StyleVariant? variant, }) { return SearchViewThemeData( backgroundColor: backgroundColor ?? this.backgroundColor, @@ -125,6 +131,7 @@ class SearchViewThemeData with Diagnosticable { barPadding: barPadding ?? this.barPadding, shrinkWrap: shrinkWrap ?? this.shrinkWrap, dividerColor: dividerColor ?? this.dividerColor, + variant: variant ?? this.variant, ); } @@ -147,6 +154,7 @@ class SearchViewThemeData with Diagnosticable { barPadding: EdgeInsetsGeometry.lerp(a?.barPadding, b?.barPadding, t), shrinkWrap: t < 0.5 ? a?.shrinkWrap : b?.shrinkWrap, dividerColor: Color.lerp(a?.dividerColor, b?.dividerColor, t), + variant: t < 0.5 ? a?.variant : b?.variant, ); } @@ -165,6 +173,7 @@ class SearchViewThemeData with Diagnosticable { barPadding, shrinkWrap, dividerColor, + variant, ); @override @@ -188,7 +197,8 @@ class SearchViewThemeData with Diagnosticable { other.padding == padding && other.barPadding == barPadding && other.shrinkWrap == shrinkWrap && - other.dividerColor == dividerColor; + other.dividerColor == dividerColor && + other.variant == variant; } @override @@ -221,6 +231,7 @@ class SearchViewThemeData with Diagnosticable { ); properties.add(DiagnosticsProperty('shrinkWrap', shrinkWrap, defaultValue: null)); properties.add(DiagnosticsProperty('dividerColor', dividerColor, defaultValue: null)); + properties.add(EnumProperty('variant', variant, defaultValue: null)); } // Special case because BorderSide.lerp() doesn't support null arguments diff --git a/packages/material_ui/lib/src/slider.dart b/packages/material_ui/lib/src/slider.dart index 4b99d858f387..ac843b91ed51 100644 --- a/packages/material_ui/lib/src/slider.dart +++ b/packages/material_ui/lib/src/slider.dart @@ -831,6 +831,8 @@ class _SliderState extends State with TickerProviderStateMixin { Widget _buildMaterialSlider(BuildContext context) { final ThemeData theme = Theme.of(context); SliderThemeData sliderTheme = SliderTheme.of(context); + final StyleVariant effectiveVariant = sliderTheme.variant ?? theme.variant; + assert(effectiveVariant != .material3Expressive, kUnsupportedStyleVariantAssertionMessage); final bool year2023 = widget.year2023 ?? sliderTheme.year2023 ?? true; final SliderThemeData defaults = switch (theme.useMaterial3) { true => year2023 ? _SliderDefaultsM3Year2023(context) : _SliderDefaultsM3(context), diff --git a/packages/material_ui/lib/src/slider_theme.dart b/packages/material_ui/lib/src/slider_theme.dart index 8275d4cad7ff..ff3e7f98b68f 100644 --- a/packages/material_ui/lib/src/slider_theme.dart +++ b/packages/material_ui/lib/src/slider_theme.dart @@ -14,6 +14,7 @@ import 'package:flutter/rendering.dart'; import 'package:flutter/widgets.dart'; import 'colors.dart'; +import 'debug.dart'; import 'range_slider_parts.dart'; import 'slider.dart'; import 'slider_parts.dart'; @@ -318,7 +319,8 @@ class SliderThemeData with Diagnosticable { 'This feature was deprecated after v3.27.0-0.2.pre.', ) this.year2023, - }); + this.variant, + }) : assert(variant != .material3Expressive, kUnsupportedStyleVariantAssertionMessage); /// Generates a SliderThemeData from three main colors. /// @@ -659,6 +661,9 @@ class SliderThemeData with Diagnosticable { ) final bool? year2023; + /// The style variant of Material Design used by sliders. + final StyleVariant? variant; + /// Creates a copy of this object but with the given fields replaced with the /// new values. SliderThemeData copyWith({ @@ -698,6 +703,7 @@ class SliderThemeData with Diagnosticable { WidgetStateProperty? thumbSize, double? trackGap, bool? year2023, + StyleVariant? variant, }) { return SliderThemeData( trackHeight: trackHeight ?? this.trackHeight, @@ -738,6 +744,7 @@ class SliderThemeData with Diagnosticable { thumbSize: thumbSize ?? this.thumbSize, trackGap: trackGap ?? this.trackGap, year2023: year2023 ?? this.year2023, + variant: variant ?? this.variant, ); } @@ -821,6 +828,7 @@ class SliderThemeData with Diagnosticable { thumbSize: WidgetStateProperty.lerp(a.thumbSize, b.thumbSize, t, Size.lerp), trackGap: lerpDouble(a.trackGap, b.trackGap, t), year2023: t < 0.5 ? a.year2023 : b.year2023, + variant: t < 0.5 ? a.variant : b.variant, ); } @@ -862,6 +870,7 @@ class SliderThemeData with Diagnosticable { thumbSize, trackGap, year2023, + variant, ), ); @@ -909,7 +918,8 @@ class SliderThemeData with Diagnosticable { other.padding == padding && other.thumbSize == thumbSize && other.trackGap == trackGap && - other.year2023 == year2023; + other.year2023 == year2023 && + other.variant == variant; } @override @@ -1144,6 +1154,7 @@ class SliderThemeData with Diagnosticable { properties.add( DiagnosticsProperty('year2023', year2023, defaultValue: defaultData.year2023), ); + properties.add(EnumProperty('variant', variant, defaultValue: null)); } } diff --git a/packages/material_ui/lib/src/text_button.dart b/packages/material_ui/lib/src/text_button.dart index f2868f3398c2..e7e28ef9a140 100644 --- a/packages/material_ui/lib/src/text_button.dart +++ b/packages/material_ui/lib/src/text_button.dart @@ -18,6 +18,7 @@ import 'button_style_button.dart'; import 'color_scheme.dart'; import 'colors.dart'; import 'constants.dart'; +import 'debug.dart'; import 'ink_ripple.dart'; import 'ink_well.dart'; import 'material_state.dart'; @@ -378,6 +379,8 @@ class TextButton extends ButtonStyleButton { @override ButtonStyle defaultStyleOf(BuildContext context) { final ThemeData theme = Theme.of(context); + final StyleVariant effectiveVariant = TextButtonTheme.of(context).variant ?? theme.variant; + assert(effectiveVariant != .material3Expressive, kUnsupportedStyleVariantAssertionMessage); final ColorScheme colorScheme = theme.colorScheme; final ButtonStyle buttonStyle = theme.useMaterial3 ? _TextButtonDefaultsM3(context) diff --git a/packages/material_ui/lib/src/text_button_theme.dart b/packages/material_ui/lib/src/text_button_theme.dart index e1a7aefb3cb0..1e4e52d035ea 100644 --- a/packages/material_ui/lib/src/text_button_theme.dart +++ b/packages/material_ui/lib/src/text_button_theme.dart @@ -9,6 +9,7 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/widgets.dart'; import 'button_style.dart'; +import 'debug.dart'; import 'theme.dart'; // Examples can assume: @@ -39,7 +40,8 @@ class TextButtonThemeData with Diagnosticable { /// Creates a [TextButtonThemeData]. /// /// The [style] may be null. - const TextButtonThemeData({this.style}); + const TextButtonThemeData({this.style, this.variant}) + : assert(variant != .material3Expressive, kUnsupportedStyleVariantAssertionMessage); /// Overrides for [TextButton]'s default style. /// @@ -50,16 +52,22 @@ class TextButtonThemeData with Diagnosticable { /// If [style] is null, then this theme doesn't override anything. final ButtonStyle? style; + /// The style variant of Material Design used by [TextButton]. + final StyleVariant? variant; + /// Linearly interpolate between two text button themes. static TextButtonThemeData? lerp(TextButtonThemeData? a, TextButtonThemeData? b, double t) { if (identical(a, b)) { return a; } - return TextButtonThemeData(style: ButtonStyle.lerp(a?.style, b?.style, t)); + return TextButtonThemeData( + style: ButtonStyle.lerp(a?.style, b?.style, t), + variant: t < 0.5 ? a?.variant : b?.variant, + ); } @override - int get hashCode => style.hashCode; + int get hashCode => Object.hash(style, variant); @override bool operator ==(Object other) { @@ -69,13 +77,14 @@ class TextButtonThemeData with Diagnosticable { if (other.runtimeType != runtimeType) { return false; } - return other is TextButtonThemeData && other.style == style; + return other is TextButtonThemeData && other.style == style && other.variant == variant; } @override void debugFillProperties(DiagnosticPropertiesBuilder properties) { super.debugFillProperties(properties); properties.add(DiagnosticsProperty('style', style, defaultValue: null)); + properties.add(EnumProperty('variant', variant, defaultValue: null)); } } diff --git a/packages/material_ui/lib/src/theme.dart b/packages/material_ui/lib/src/theme.dart index b103f725904f..e04e1bdb26b8 100644 --- a/packages/material_ui/lib/src/theme.dart +++ b/packages/material_ui/lib/src/theme.dart @@ -14,7 +14,7 @@ import 'material_localizations.dart'; import 'theme_data.dart'; import 'typography.dart'; -export 'theme_data.dart' show Brightness, MaterialTapTargetSize, ThemeData; +export 'theme_data.dart' show Brightness, MaterialTapTargetSize, StyleVariant, ThemeData; /// The duration over which theme changes animate by default. const Duration kThemeAnimationDuration = Duration(milliseconds: 200); diff --git a/packages/material_ui/lib/src/theme_data.dart b/packages/material_ui/lib/src/theme_data.dart index b4c7e1e0b145..43a36250b45d 100644 --- a/packages/material_ui/lib/src/theme_data.dart +++ b/packages/material_ui/lib/src/theme_data.dart @@ -29,6 +29,7 @@ import 'colors.dart'; import 'constants.dart'; import 'data_table_theme.dart'; import 'date_picker_theme.dart'; +import 'debug.dart'; import 'dialog_theme.dart'; import 'divider_theme.dart'; import 'drawer_theme.dart'; @@ -182,6 +183,15 @@ enum MaterialTapTargetSize { shrinkWrap, } +/// Defines the Material Design style variant used by Material components. +enum StyleVariant { + /// The Material Design 3 style variant. + material3, + + /// The Material Design 3 Expressive style variant. + material3Expressive, +} + /// Defines the configuration of the overall visual [Theme] for a [MaterialApp] /// or a widget subtree within the app. /// @@ -282,6 +292,7 @@ class ThemeData with Diagnosticable { InteractiveInkFeatureFactory? splashFactory, bool? useMaterial3, bool? useSystemColors, + StyleVariant? variant, VisualDensity? visualDensity, // COLOR ColorScheme? colorScheme, @@ -385,6 +396,8 @@ class ThemeData with Diagnosticable { cupertinoOverrideTheme = cupertinoOverrideTheme?.noDefault(); extensions ??= >[]; adaptations ??= >[]; + variant ??= StyleVariant.material3; + assert(variant != .material3Expressive, kUnsupportedStyleVariantAssertionMessage); // TODO(bleroux): Clean this up once the type of `inputDecorationTheme` is changed to `InputDecorationThemeData` if (inputDecorationTheme != null) { if (inputDecorationTheme is InputDecorationTheme) { @@ -605,6 +618,7 @@ class ThemeData with Diagnosticable { scrollbarTheme: scrollbarTheme, splashFactory: splashFactory, useMaterial3: useMaterial3, + variant: variant, visualDensity: visualDensity, // COLOR canvasColor: canvasColor, @@ -715,6 +729,7 @@ class ThemeData with Diagnosticable { required this.scrollbarTheme, required this.splashFactory, required this.useMaterial3, + required this.variant, required this.visualDensity, // COLOR required this.colorScheme, @@ -806,7 +821,8 @@ class ThemeData with Diagnosticable { 'This feature was deprecated after v3.28.0-1.0.pre.', ) required this.indicatorColor, - }) : // DEPRECATED (newest deprecations at the bottom) + }) : assert(variant != .material3Expressive, kUnsupportedStyleVariantAssertionMessage), + // DEPRECATED (newest deprecations at the bottom) // should not be `required`, use getter pattern to avoid breakages. _buttonBarTheme = buttonBarTheme, assert(buttonBarTheme != null); @@ -841,6 +857,7 @@ class ThemeData with Diagnosticable { required ColorScheme colorScheme, TextTheme? textTheme, bool? useMaterial3, + StyleVariant? variant, }) { final isDark = colorScheme.brightness == Brightness.dark; @@ -861,6 +878,7 @@ class ThemeData with Diagnosticable { textTheme: textTheme, applyElevationOverlayColor: isDark, useMaterial3: useMaterial3, + variant: variant, ); } @@ -868,15 +886,15 @@ 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({bool? useMaterial3}) => - ThemeData(brightness: Brightness.light, useMaterial3: useMaterial3); + factory ThemeData.light({bool? useMaterial3, StyleVariant? variant}) => + ThemeData(brightness: Brightness.light, useMaterial3: useMaterial3, variant: variant); /// A default dark theme. /// /// 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({bool? useMaterial3}) => - ThemeData(brightness: Brightness.dark, useMaterial3: useMaterial3); + factory ThemeData.dark({bool? useMaterial3, StyleVariant? variant}) => + ThemeData(brightness: Brightness.dark, useMaterial3: useMaterial3, variant: variant); /// The default color theme. Same as [ThemeData.light]. /// @@ -887,7 +905,8 @@ class ThemeData with Diagnosticable { /// /// Most applications would use [Theme.of], which provides correct localized /// text geometry. - factory ThemeData.fallback({bool? useMaterial3}) => ThemeData.light(useMaterial3: useMaterial3); + factory ThemeData.fallback({bool? useMaterial3, StyleVariant? variant}) => + ThemeData.light(useMaterial3: useMaterial3, variant: variant); /// Used to obtain a particular [Adaptation] from [adaptationMap]. /// @@ -1145,6 +1164,11 @@ class ThemeData with Diagnosticable { /// * [Material 3 specification](https://m3.material.io/). final bool useMaterial3; + /// The style variant of Material Design used by Material components. + /// + /// Defaults to [StyleVariant.material3]. + final StyleVariant variant; + /// The density value for specifying the compactness of various UI components. /// /// {@template flutter.material.themedata.visualDensity} @@ -1498,6 +1522,7 @@ class ThemeData with Diagnosticable { TargetPlatform? platform, ScrollbarThemeData? scrollbarTheme, InteractiveInkFeatureFactory? splashFactory, + StyleVariant? variant, VisualDensity? visualDensity, // COLOR ColorScheme? colorScheme, @@ -1634,6 +1659,7 @@ class ThemeData with Diagnosticable { // When deprecated useMaterial3 removed, maintain `this.useMaterial3` here // for == evaluation. useMaterial3: useMaterial3 ?? this.useMaterial3, + variant: variant ?? this.variant, visualDensity: visualDensity ?? this.visualDensity, // COLOR canvasColor: canvasColor ?? this.canvasColor, @@ -1959,6 +1985,7 @@ class ThemeData with Diagnosticable { scrollbarTheme: ScrollbarThemeData.lerp(a.scrollbarTheme, b.scrollbarTheme, t), splashFactory: t < 0.5 ? a.splashFactory : b.splashFactory, useMaterial3: t < 0.5 ? a.useMaterial3 : b.useMaterial3, + variant: t < 0.5 ? a.variant : b.variant, visualDensity: VisualDensity.lerp(a.visualDensity, b.visualDensity, t), // COLOR canvasColor: Color.lerp(a.canvasColor, b.canvasColor, t)!, @@ -2107,6 +2134,7 @@ class ThemeData with Diagnosticable { other.scrollbarTheme == scrollbarTheme && other.splashFactory == splashFactory && other.useMaterial3 == useMaterial3 && + other.variant == variant && other.visualDensity == visualDensity && // COLOR other.canvasColor == canvasColor && @@ -2207,6 +2235,7 @@ class ThemeData with Diagnosticable { scrollbarTheme, splashFactory, useMaterial3, + variant, visualDensity, // COLOR canvasColor, @@ -2381,6 +2410,14 @@ class ThemeData with Diagnosticable { level: DiagnosticLevel.debug, ), ); + properties.add( + EnumProperty( + 'variant', + variant, + defaultValue: defaultData.variant, + level: DiagnosticLevel.debug, + ), + ); properties.add( DiagnosticsProperty( 'visualDensity', diff --git a/packages/material_ui/test/app_bar_theme_test.dart b/packages/material_ui/test/app_bar_theme_test.dart index c23152855d4b..b078bf37c0d1 100644 --- a/packages/material_ui/test/app_bar_theme_test.dart +++ b/packages/material_ui/test/app_bar_theme_test.dart @@ -8,6 +8,21 @@ import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:material_ui/material_ui.dart'; +class _AppBarThemeDataWithExpressiveVariant extends AppBarThemeData { + const _AppBarThemeDataWithExpressiveVariant(); + + @override + StyleVariant? get variant => .material3Expressive; +} + +Matcher get _throwsUnsupportedStyleVariantAssertion { + return isA().having( + (AssertionError error) => error.message, + 'message', + kUnsupportedStyleVariantAssertionMessage, + ); +} + void main() { const appBarTheme = AppBarThemeData( backgroundColor: Color(0xff00ff00), @@ -55,6 +70,19 @@ void main() { expect(identical(AppBarTheme.lerp(data, data, 0.5), data), true); }); + testWidgets('AppBar asserts on unsupported style variants', (WidgetTester tester) async { + await tester.pumpWidget( + MaterialApp( + home: AppBarTheme( + data: const _AppBarThemeDataWithExpressiveVariant(), + child: AppBar(title: const Text('Title')), + ), + ), + ); + + expect(tester.takeException(), _throwsUnsupportedStyleVariantAssertion); + }); + testWidgets('Material2 - Passing no AppBarTheme returns defaults', (WidgetTester tester) async { final theme = ThemeData(useMaterial3: false); await tester.pumpWidget( diff --git a/packages/material_ui/test/elevated_button_theme_test.dart b/packages/material_ui/test/elevated_button_theme_test.dart index 179c311fb81e..643d40286cc1 100644 --- a/packages/material_ui/test/elevated_button_theme_test.dart +++ b/packages/material_ui/test/elevated_button_theme_test.dart @@ -5,6 +5,21 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:material_ui/material_ui.dart'; +class _ElevatedButtonThemeDataWithExpressiveVariant extends ElevatedButtonThemeData { + const _ElevatedButtonThemeDataWithExpressiveVariant(); + + @override + StyleVariant? get variant => .material3Expressive; +} + +Matcher get _throwsUnsupportedStyleVariantAssertion { + return isA().having( + (AssertionError error) => error.message, + 'message', + kUnsupportedStyleVariantAssertionMessage, + ); +} + void main() { TextStyle iconStyle(WidgetTester tester, IconData icon) { final RichText iconRichText = tester.widget( @@ -19,6 +34,19 @@ void main() { expect(identical(ElevatedButtonThemeData.lerp(data, data, 0.5), data), true); }); + testWidgets('ElevatedButton asserts on unsupported style variants', (WidgetTester tester) async { + await tester.pumpWidget( + MaterialApp( + home: ElevatedButtonTheme( + data: const _ElevatedButtonThemeDataWithExpressiveVariant(), + child: ElevatedButton(onPressed: () {}, child: const Text('Button')), + ), + ), + ); + + expect(tester.takeException(), _throwsUnsupportedStyleVariantAssertion); + }); + testWidgets('Material3: Passing no ElevatedButtonTheme returns defaults', ( WidgetTester tester, ) async { diff --git a/packages/material_ui/test/filled_button_theme_test.dart b/packages/material_ui/test/filled_button_theme_test.dart index b99eb89e620e..9e2048147936 100644 --- a/packages/material_ui/test/filled_button_theme_test.dart +++ b/packages/material_ui/test/filled_button_theme_test.dart @@ -5,6 +5,21 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:material_ui/material_ui.dart'; +class _FilledButtonThemeDataWithExpressiveVariant extends FilledButtonThemeData { + const _FilledButtonThemeDataWithExpressiveVariant(); + + @override + StyleVariant? get variant => .material3Expressive; +} + +Matcher get _throwsUnsupportedStyleVariantAssertion { + return isA().having( + (AssertionError error) => error.message, + 'message', + kUnsupportedStyleVariantAssertionMessage, + ); +} + void main() { TextStyle iconStyle(WidgetTester tester, IconData icon) { final RichText iconRichText = tester.widget( @@ -19,6 +34,19 @@ void main() { expect(identical(FilledButtonThemeData.lerp(data, data, 0.5), data), true); }); + testWidgets('FilledButton asserts on unsupported style variants', (WidgetTester tester) async { + await tester.pumpWidget( + MaterialApp( + home: FilledButtonTheme( + data: const _FilledButtonThemeDataWithExpressiveVariant(), + child: FilledButton(onPressed: () {}, child: const Text('Button')), + ), + ), + ); + + expect(tester.takeException(), _throwsUnsupportedStyleVariantAssertion); + }); + testWidgets('Passing no FilledButtonTheme returns defaults', (WidgetTester tester) async { const colorScheme = ColorScheme.light(); await tester.pumpWidget( diff --git a/packages/material_ui/test/floating_action_button_theme_test.dart b/packages/material_ui/test/floating_action_button_theme_test.dart index cb5234fb9bea..bc40c318811e 100644 --- a/packages/material_ui/test/floating_action_button_theme_test.dart +++ b/packages/material_ui/test/floating_action_button_theme_test.dart @@ -7,6 +7,21 @@ import 'package:flutter/rendering.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:material_ui/material_ui.dart'; +class _FloatingActionButtonThemeDataWithExpressiveVariant extends FloatingActionButtonThemeData { + const _FloatingActionButtonThemeDataWithExpressiveVariant(); + + @override + StyleVariant? get variant => .material3Expressive; +} + +Matcher get _throwsUnsupportedStyleVariantAssertion { + return isA().having( + (AssertionError error) => error.message, + 'message', + kUnsupportedStyleVariantAssertionMessage, + ); +} + void main() { test('FloatingActionButtonThemeData copyWith, ==, hashCode basics', () { expect(const FloatingActionButtonThemeData(), const FloatingActionButtonThemeData().copyWith()); @@ -22,6 +37,21 @@ void main() { expect(identical(FloatingActionButtonThemeData.lerp(data, data, 0.5), data), true); }); + testWidgets('FloatingActionButton asserts on unsupported style variants', ( + WidgetTester tester, + ) async { + await tester.pumpWidget( + MaterialApp( + home: FloatingActionButtonTheme( + data: const _FloatingActionButtonThemeDataWithExpressiveVariant(), + child: FloatingActionButton(onPressed: () {}), + ), + ), + ); + + expect(tester.takeException(), _throwsUnsupportedStyleVariantAssertion); + }); + testWidgets( 'Material3: Default values are used when no FloatingActionButton or FloatingActionButtonThemeData properties are specified', (WidgetTester tester) async { diff --git a/packages/material_ui/test/icon_button_theme_test.dart b/packages/material_ui/test/icon_button_theme_test.dart index c271ba758bd4..6ad4e03ad603 100644 --- a/packages/material_ui/test/icon_button_theme_test.dart +++ b/packages/material_ui/test/icon_button_theme_test.dart @@ -7,6 +7,13 @@ import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:material_ui/material_ui.dart'; +class _IconButtonThemeDataWithExpressiveVariant extends IconButtonThemeData { + const _IconButtonThemeDataWithExpressiveVariant(); + + @override + StyleVariant? get variant => .material3Expressive; +} + void main() { RenderObject getOverlayColor(WidgetTester tester) { return tester.allRenderObjects.firstWhere( @@ -20,6 +27,28 @@ void main() { expect(identical(IconButtonThemeData.lerp(data, data, 0.5), data), true); }); + testWidgets('IconButton asserts on unsupported style variants', (WidgetTester tester) async { + await tester.pumpWidget( + const MaterialApp( + home: Scaffold( + body: IconButtonTheme( + data: _IconButtonThemeDataWithExpressiveVariant(), + child: IconButton(onPressed: null, icon: Icon(Icons.ac_unit)), + ), + ), + ), + ); + + expect( + tester.takeException(), + isA().having( + (AssertionError error) => error.message, + 'message', + kUnsupportedStyleVariantAssertionMessage, + ), + ); + }); + testWidgets('Passing no IconButtonTheme returns defaults', (WidgetTester tester) async { const colorScheme = ColorScheme.light(); await tester.pumpWidget( diff --git a/packages/material_ui/test/menu_button_theme_test.dart b/packages/material_ui/test/menu_button_theme_test.dart index 119e42b2c32f..fbf64723c5ba 100644 --- a/packages/material_ui/test/menu_button_theme_test.dart +++ b/packages/material_ui/test/menu_button_theme_test.dart @@ -5,10 +5,54 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:material_ui/material_ui.dart'; +class _MenuButtonThemeDataWithExpressiveVariant extends MenuButtonThemeData { + const _MenuButtonThemeDataWithExpressiveVariant(); + + @override + StyleVariant? get variant => .material3Expressive; +} + +Matcher get _throwsUnsupportedStyleVariantAssertion { + return isA().having( + (AssertionError error) => error.message, + 'message', + kUnsupportedStyleVariantAssertionMessage, + ); +} + void main() { test('MenuButtonThemeData lerp special cases', () { expect(MenuButtonThemeData.lerp(null, null, 0), null); const data = MenuButtonThemeData(); expect(identical(MenuButtonThemeData.lerp(data, data, 0.5), data), true); }); + + testWidgets('MenuItemButton asserts on unsupported style variants', (WidgetTester tester) async { + await tester.pumpWidget( + MaterialApp( + home: MenuButtonTheme( + data: const _MenuButtonThemeDataWithExpressiveVariant(), + child: MenuItemButton(onPressed: () {}, child: const Text('Item')), + ), + ), + ); + + expect(tester.takeException(), _throwsUnsupportedStyleVariantAssertion); + }); + + testWidgets('SubmenuButton asserts on unsupported style variants', (WidgetTester tester) async { + await tester.pumpWidget( + MaterialApp( + home: MenuButtonTheme( + data: const _MenuButtonThemeDataWithExpressiveVariant(), + child: SubmenuButton( + menuChildren: [MenuItemButton(onPressed: () {}, child: const Text('Item'))], + child: const Text('Submenu'), + ), + ), + ), + ); + + expect(tester.takeException(), _throwsUnsupportedStyleVariantAssertion); + }); } diff --git a/packages/material_ui/test/menu_theme_test.dart b/packages/material_ui/test/menu_theme_test.dart index d86ff0028092..59512bb6b4a7 100644 --- a/packages/material_ui/test/menu_theme_test.dart +++ b/packages/material_ui/test/menu_theme_test.dart @@ -7,6 +7,21 @@ import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:material_ui/material_ui.dart'; +class _MenuThemeDataWithExpressiveVariant extends MenuThemeData { + const _MenuThemeDataWithExpressiveVariant(); + + @override + StyleVariant? get variant => .material3Expressive; +} + +Matcher get _throwsUnsupportedStyleVariantAssertion { + return isA().having( + (AssertionError error) => error.message, + 'message', + kUnsupportedStyleVariantAssertionMessage, + ); +} + void main() { void onPressed(TestMenu item) {} @@ -60,6 +75,24 @@ void main() { expect(menuThemeData.submenuIcon, isNull); }); + testWidgets('MenuAnchor asserts on unsupported style variants', (WidgetTester tester) async { + await tester.pumpWidget( + MaterialApp( + home: MenuTheme( + data: const _MenuThemeDataWithExpressiveVariant(), + child: MenuAnchor( + menuChildren: [MenuItemButton(onPressed: () {}, child: const Text('Item'))], + builder: (BuildContext context, MenuController controller, Widget? child) { + return TextButton(onPressed: controller.open, child: const Text('Open')); + }, + ), + ), + ), + ); + + expect(tester.takeException(), _throwsUnsupportedStyleVariantAssertion); + }); + testWidgets('Default MenuThemeData debugFillProperties', (WidgetTester tester) async { final builder = DiagnosticPropertiesBuilder(); const MenuThemeData().debugFillProperties(builder); diff --git a/packages/material_ui/test/navigation_bar_theme_test.dart b/packages/material_ui/test/navigation_bar_theme_test.dart index 38a78326660c..ef17b32445a0 100644 --- a/packages/material_ui/test/navigation_bar_theme_test.dart +++ b/packages/material_ui/test/navigation_bar_theme_test.dart @@ -14,6 +14,21 @@ import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:material_ui/material_ui.dart'; +class _NavigationBarThemeDataWithExpressiveVariant extends NavigationBarThemeData { + const _NavigationBarThemeDataWithExpressiveVariant(); + + @override + StyleVariant? get variant => .material3Expressive; +} + +Matcher get _throwsUnsupportedStyleVariantAssertion { + return isA().having( + (AssertionError error) => error.message, + 'message', + kUnsupportedStyleVariantAssertionMessage, + ); +} + void main() { test('copyWith, ==, hashCode basics', () { expect(const NavigationBarThemeData(), const NavigationBarThemeData().copyWith()); @@ -29,6 +44,24 @@ void main() { expect(identical(NavigationBarThemeData.lerp(data, data, 0.5), data), true); }); + testWidgets('NavigationBar asserts on unsupported style variants', (WidgetTester tester) async { + await tester.pumpWidget( + MaterialApp( + home: NavigationBarTheme( + data: const _NavigationBarThemeDataWithExpressiveVariant(), + child: NavigationBar( + destinations: const [ + NavigationDestination(icon: Icon(Icons.home), label: 'Home'), + NavigationDestination(icon: Icon(Icons.settings), label: 'Settings'), + ], + ), + ), + ), + ); + + expect(tester.takeException(), _throwsUnsupportedStyleVariantAssertion); + }); + testWidgets('Default debugFillProperties', (WidgetTester tester) async { final builder = DiagnosticPropertiesBuilder(); const NavigationBarThemeData().debugFillProperties(builder); diff --git a/packages/material_ui/test/navigation_rail_theme_test.dart b/packages/material_ui/test/navigation_rail_theme_test.dart index b47494e4d865..01549a6ec638 100644 --- a/packages/material_ui/test/navigation_rail_theme_test.dart +++ b/packages/material_ui/test/navigation_rail_theme_test.dart @@ -6,7 +6,41 @@ import 'package:flutter/rendering.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:material_ui/material_ui.dart'; +class _NavigationRailThemeDataWithExpressiveVariant extends NavigationRailThemeData { + const _NavigationRailThemeDataWithExpressiveVariant(); + + @override + StyleVariant? get variant => .material3Expressive; +} + +Matcher get _throwsUnsupportedStyleVariantAssertion { + return isA().having( + (AssertionError error) => error.message, + 'message', + kUnsupportedStyleVariantAssertionMessage, + ); +} + void main() { + testWidgets('NavigationRail asserts on unsupported style variants', (WidgetTester tester) async { + await tester.pumpWidget( + MaterialApp( + home: NavigationRailTheme( + data: const _NavigationRailThemeDataWithExpressiveVariant(), + child: NavigationRail( + selectedIndex: 0, + destinations: const [ + NavigationRailDestination(icon: Icon(Icons.home), label: Text('Home')), + NavigationRailDestination(icon: Icon(Icons.settings), label: Text('Settings')), + ], + ), + ), + ), + ); + + expect(tester.takeException(), _throwsUnsupportedStyleVariantAssertion); + }); + test('copyWith, ==, hashCode basics', () { expect(const NavigationRailThemeData(), const NavigationRailThemeData().copyWith()); expect( diff --git a/packages/material_ui/test/outlined_button_theme_test.dart b/packages/material_ui/test/outlined_button_theme_test.dart index 393b985ebd02..5e23b6f444af 100644 --- a/packages/material_ui/test/outlined_button_theme_test.dart +++ b/packages/material_ui/test/outlined_button_theme_test.dart @@ -5,6 +5,21 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:material_ui/material_ui.dart'; +class _OutlinedButtonThemeDataWithExpressiveVariant extends OutlinedButtonThemeData { + const _OutlinedButtonThemeDataWithExpressiveVariant(); + + @override + StyleVariant? get variant => .material3Expressive; +} + +Matcher get _throwsUnsupportedStyleVariantAssertion { + return isA().having( + (AssertionError error) => error.message, + 'message', + kUnsupportedStyleVariantAssertionMessage, + ); +} + void main() { TextStyle iconStyle(WidgetTester tester, IconData icon) { final RichText iconRichText = tester.widget( @@ -19,6 +34,19 @@ void main() { expect(identical(OutlinedButtonThemeData.lerp(data, data, 0.5), data), true); }); + testWidgets('OutlinedButton asserts on unsupported style variants', (WidgetTester tester) async { + await tester.pumpWidget( + MaterialApp( + home: OutlinedButtonTheme( + data: const _OutlinedButtonThemeDataWithExpressiveVariant(), + child: OutlinedButton(onPressed: () {}, child: const Text('Button')), + ), + ), + ); + + expect(tester.takeException(), _throwsUnsupportedStyleVariantAssertion); + }); + testWidgets('Material3: Passing no OutlinedButtonTheme returns defaults', ( WidgetTester tester, ) async { diff --git a/packages/material_ui/test/progress_indicator_theme_test.dart b/packages/material_ui/test/progress_indicator_theme_test.dart index edd24237840d..c96e05c49dc6 100644 --- a/packages/material_ui/test/progress_indicator_theme_test.dart +++ b/packages/material_ui/test/progress_indicator_theme_test.dart @@ -12,6 +12,21 @@ import 'package:flutter/rendering.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:material_ui/material_ui.dart'; +class _ProgressIndicatorThemeDataWithExpressiveVariant extends ProgressIndicatorThemeData { + const _ProgressIndicatorThemeDataWithExpressiveVariant(); + + @override + StyleVariant? get variant => .material3Expressive; +} + +Matcher get _throwsUnsupportedStyleVariantAssertion { + return isA().having( + (AssertionError error) => error.message, + 'message', + kUnsupportedStyleVariantAssertionMessage, + ); +} + void main() { test('ProgressIndicatorThemeData copyWith, ==, hashCode, basics', () { expect(const ProgressIndicatorThemeData(), const ProgressIndicatorThemeData().copyWith()); @@ -27,6 +42,36 @@ void main() { expect(identical(ProgressIndicatorThemeData.lerp(data, data, 0.5), data), true); }); + testWidgets('LinearProgressIndicator asserts on unsupported style variants', ( + WidgetTester tester, + ) async { + await tester.pumpWidget( + const MaterialApp( + home: ProgressIndicatorTheme( + data: _ProgressIndicatorThemeDataWithExpressiveVariant(), + child: LinearProgressIndicator(), + ), + ), + ); + + expect(tester.takeException(), _throwsUnsupportedStyleVariantAssertion); + }); + + testWidgets('CircularProgressIndicator asserts on unsupported style variants', ( + WidgetTester tester, + ) async { + await tester.pumpWidget( + const MaterialApp( + home: ProgressIndicatorTheme( + data: _ProgressIndicatorThemeDataWithExpressiveVariant(), + child: CircularProgressIndicator(), + ), + ), + ); + + expect(tester.takeException(), _throwsUnsupportedStyleVariantAssertion); + }); + testWidgets('ProgressIndicatorThemeData implements debugFillProperties', ( WidgetTester tester, ) async { diff --git a/packages/material_ui/test/search_bar_theme_test.dart b/packages/material_ui/test/search_bar_theme_test.dart index 8db913ad882a..c518f5e37cea 100644 --- a/packages/material_ui/test/search_bar_theme_test.dart +++ b/packages/material_ui/test/search_bar_theme_test.dart @@ -6,6 +6,21 @@ import 'package:flutter/rendering.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:material_ui/material_ui.dart'; +class _SearchBarThemeDataWithExpressiveVariant extends SearchBarThemeData { + const _SearchBarThemeDataWithExpressiveVariant(); + + @override + StyleVariant? get variant => .material3Expressive; +} + +Matcher get _throwsUnsupportedStyleVariantAssertion { + return isA().having( + (AssertionError error) => error.message, + 'message', + kUnsupportedStyleVariantAssertionMessage, + ); +} + void main() { test('SearchBarThemeData copyWith, ==, hashCode basics', () { expect(const SearchBarThemeData(), const SearchBarThemeData().copyWith()); @@ -18,6 +33,16 @@ void main() { expect(identical(SearchBarThemeData.lerp(data, data, 0.5), data), true); }); + testWidgets('SearchBar asserts on unsupported style variants', (WidgetTester tester) async { + await tester.pumpWidget( + const MaterialApp( + home: SearchBarTheme(data: _SearchBarThemeDataWithExpressiveVariant(), child: SearchBar()), + ), + ); + + expect(tester.takeException(), _throwsUnsupportedStyleVariantAssertion); + }); + test('SearchBarThemeData defaults', () { const themeData = SearchBarThemeData(); expect(themeData.elevation, null); diff --git a/packages/material_ui/test/search_view_theme_test.dart b/packages/material_ui/test/search_view_theme_test.dart index df9ef81c8140..fe0d8119ba3f 100644 --- a/packages/material_ui/test/search_view_theme_test.dart +++ b/packages/material_ui/test/search_view_theme_test.dart @@ -6,6 +6,21 @@ import 'package:flutter/rendering.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:material_ui/material_ui.dart'; +class _SearchViewThemeDataWithExpressiveVariant extends SearchViewThemeData { + const _SearchViewThemeDataWithExpressiveVariant(); + + @override + StyleVariant? get variant => .material3Expressive; +} + +Matcher get _throwsUnsupportedStyleVariantAssertion { + return isA().having( + (AssertionError error) => error.message, + 'message', + kUnsupportedStyleVariantAssertionMessage, + ); +} + void main() { test('SearchViewThemeData copyWith, ==, hashCode basics', () { expect(const SearchViewThemeData(), const SearchViewThemeData().copyWith()); @@ -18,6 +33,26 @@ void main() { expect(identical(SearchViewThemeData.lerp(data, data, 0.5), data), true); }); + testWidgets('SearchAnchor asserts on unsupported style variants', (WidgetTester tester) async { + await tester.pumpWidget( + MaterialApp( + home: SearchViewTheme( + data: const _SearchViewThemeDataWithExpressiveVariant(), + child: SearchAnchor( + builder: (BuildContext context, SearchController controller) { + return TextButton(onPressed: controller.openView, child: const Text('Search')); + }, + suggestionsBuilder: (BuildContext context, SearchController controller) { + return []; + }, + ), + ), + ), + ); + + expect(tester.takeException(), _throwsUnsupportedStyleVariantAssertion); + }); + test('SearchViewThemeData defaults', () { const themeData = SearchViewThemeData(); expect(themeData.backgroundColor, null); diff --git a/packages/material_ui/test/slider_theme_test.dart b/packages/material_ui/test/slider_theme_test.dart index 31882acf6942..12d2000a48ec 100644 --- a/packages/material_ui/test/slider_theme_test.dart +++ b/packages/material_ui/test/slider_theme_test.dart @@ -7,6 +7,21 @@ import 'package:flutter/rendering.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:material_ui/material_ui.dart'; +class _SliderThemeDataWithExpressiveVariant extends SliderThemeData { + const _SliderThemeDataWithExpressiveVariant(); + + @override + StyleVariant? get variant => .material3Expressive; +} + +Matcher get _throwsUnsupportedStyleVariantAssertion { + return isA().having( + (AssertionError error) => error.message, + 'message', + kUnsupportedStyleVariantAssertionMessage, + ); +} + void main() { test('SliderThemeData copyWith, ==, hashCode basics', () { expect(const SliderThemeData(), const SliderThemeData().copyWith()); @@ -18,6 +33,34 @@ void main() { expect(identical(SliderThemeData.lerp(data, data, 0.5), data), true); }); + testWidgets('RangeSlider asserts on unsupported style variants', (WidgetTester tester) async { + await tester.pumpWidget( + MaterialApp( + home: SliderTheme( + data: const _SliderThemeDataWithExpressiveVariant(), + child: Material( + child: RangeSlider(values: const RangeValues(0.25, 0.75), onChanged: (_) {}), + ), + ), + ), + ); + + expect(tester.takeException(), _throwsUnsupportedStyleVariantAssertion); + }); + + testWidgets('Slider asserts on unsupported style variants', (WidgetTester tester) async { + await tester.pumpWidget( + MaterialApp( + home: SliderTheme( + data: const _SliderThemeDataWithExpressiveVariant(), + child: Material(child: Slider(value: 0.5, onChanged: (_) {})), + ), + ), + ); + + expect(tester.takeException(), _throwsUnsupportedStyleVariantAssertion); + }); + testWidgets('Default SliderThemeData debugFillProperties', (WidgetTester tester) async { final builder = DiagnosticPropertiesBuilder(); const SliderThemeData().debugFillProperties(builder); diff --git a/packages/material_ui/test/text_button_theme_test.dart b/packages/material_ui/test/text_button_theme_test.dart index 83be109a5e4d..27b4827a4268 100644 --- a/packages/material_ui/test/text_button_theme_test.dart +++ b/packages/material_ui/test/text_button_theme_test.dart @@ -5,6 +5,21 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:material_ui/material_ui.dart'; +class _TextButtonThemeDataWithExpressiveVariant extends TextButtonThemeData { + const _TextButtonThemeDataWithExpressiveVariant(); + + @override + StyleVariant? get variant => .material3Expressive; +} + +Matcher get _throwsUnsupportedStyleVariantAssertion { + return isA().having( + (AssertionError error) => error.message, + 'message', + kUnsupportedStyleVariantAssertionMessage, + ); +} + void main() { TextStyle iconStyle(WidgetTester tester, IconData icon) { final RichText iconRichText = tester.widget( @@ -19,6 +34,19 @@ void main() { expect(identical(TextButtonThemeData.lerp(data, data, 0.5), data), true); }); + testWidgets('TextButton asserts on unsupported style variants', (WidgetTester tester) async { + await tester.pumpWidget( + MaterialApp( + home: TextButtonTheme( + data: const _TextButtonThemeDataWithExpressiveVariant(), + child: TextButton(onPressed: () {}, child: const Text('Button')), + ), + ), + ); + + expect(tester.takeException(), _throwsUnsupportedStyleVariantAssertion); + }); + testWidgets('Material3: Passing no TextButtonTheme returns defaults', ( WidgetTester tester, ) async { diff --git a/packages/material_ui/test/theme_data_test.dart b/packages/material_ui/test/theme_data_test.dart index ca97ec327c0f..4f1517b3e02a 100644 --- a/packages/material_ui/test/theme_data_test.dart +++ b/packages/material_ui/test/theme_data_test.dart @@ -24,6 +24,106 @@ void main() { expect(dawn.primaryColor, Color.lerp(dark.primaryColor, light.primaryColor, 0.25)); }); + test('ThemeData defaults to Material 3 style variant', () { + expect(ThemeData().variant, StyleVariant.material3); + expect(ThemeData.light().variant, StyleVariant.material3); + expect(ThemeData.dark().variant, StyleVariant.material3); + expect(ThemeData.fallback().variant, StyleVariant.material3); + }); + + test('ThemeData asserts on unsupported style variants', () { + Matcher throwsUnsupportedStyleVariantAssertion() { + return throwsA( + isA().having( + (AssertionError error) => error.message, + 'message', + kUnsupportedStyleVariantAssertionMessage, + ), + ); + } + + expect( + () => ThemeData(variant: .material3Expressive), + throwsUnsupportedStyleVariantAssertion(), + ); + expect( + () => ThemeData.light(variant: .material3Expressive), + throwsUnsupportedStyleVariantAssertion(), + ); + expect( + () => ThemeData.dark(variant: .material3Expressive), + throwsUnsupportedStyleVariantAssertion(), + ); + expect( + () => ThemeData.fallback(variant: .material3Expressive), + throwsUnsupportedStyleVariantAssertion(), + ); + expect( + () => ThemeData.from(colorScheme: const ColorScheme.light(), variant: .material3Expressive), + throwsUnsupportedStyleVariantAssertion(), + ); + }); + + test('ThemeData.copyWith asserts on unsupported style variants', () { + final theme = ThemeData(); + + expect( + () => theme.copyWith(variant: .material3Expressive), + throwsA( + isA().having( + (AssertionError error) => error.message, + 'message', + kUnsupportedStyleVariantAssertionMessage, + ), + ), + ); + }); + + test('component theme data asserts on unsupported style variants', () { + Matcher throwsUnsupportedStyleVariantAssertion() { + return throwsA( + isA().having( + (AssertionError error) => error.message, + 'message', + kUnsupportedStyleVariantAssertionMessage, + ), + ); + } + + final constructors = [ + () => ThemeData(appBarTheme: AppBarThemeData(variant: .material3Expressive)), + () => ThemeData(elevatedButtonTheme: ElevatedButtonThemeData(variant: .material3Expressive)), + () => ThemeData(filledButtonTheme: FilledButtonThemeData(variant: .material3Expressive)), + () => ThemeData( + floatingActionButtonTheme: FloatingActionButtonThemeData(variant: .material3Expressive), + ), + () => ThemeData(iconButtonTheme: IconButtonThemeData(variant: .material3Expressive)), + () => ThemeData(menuButtonTheme: MenuButtonThemeData(variant: .material3Expressive)), + () => ThemeData(menuTheme: MenuThemeData(variant: .material3Expressive)), + () => ThemeData(navigationBarTheme: NavigationBarThemeData(variant: .material3Expressive)), + () => ThemeData(navigationRailTheme: NavigationRailThemeData(variant: .material3Expressive)), + () => ThemeData(outlinedButtonTheme: OutlinedButtonThemeData(variant: .material3Expressive)), + () => ThemeData( + progressIndicatorTheme: ProgressIndicatorThemeData(variant: .material3Expressive), + ), + () => ThemeData(searchBarTheme: SearchBarThemeData(variant: .material3Expressive)), + () => ThemeData(searchViewTheme: SearchViewThemeData(variant: .material3Expressive)), + () => ThemeData(sliderTheme: SliderThemeData(variant: .material3Expressive)), + () => ThemeData(textButtonTheme: TextButtonThemeData(variant: .material3Expressive)), + ]; + + for (final constructor in constructors) { + expect(constructor, throwsUnsupportedStyleVariantAssertion()); + } + }); + + test('ThemeData.lerp preserves style variants', () { + final material3 = ThemeData(variant: StyleVariant.material3); + + expect(ThemeData.lerp(material3, material3, 0.25).variant, StyleVariant.material3); + expect(ThemeData.lerp(material3, material3, 0.75).variant, StyleVariant.material3); + }); + test('ThemeData objects with .styleFrom() members are equal', () { ThemeData createThemeData() { return ThemeData( @@ -1290,6 +1390,7 @@ void main() { scrollbarTheme: const ScrollbarThemeData(radius: Radius.circular(10.0)), splashFactory: InkRipple.splashFactory, useMaterial3: false, + variant: StyleVariant.material3, visualDensity: VisualDensity.standard, // COLOR canvasColor: Colors.black, @@ -1419,6 +1520,7 @@ void main() { scrollbarTheme: const ScrollbarThemeData(radius: Radius.circular(10.0)), splashFactory: InkRipple.splashFactory, useMaterial3: true, + variant: StyleVariant.material3, visualDensity: VisualDensity.standard, // COLOR canvasColor: Colors.white, @@ -1523,6 +1625,7 @@ void main() { scrollbarTheme: otherTheme.scrollbarTheme, splashFactory: otherTheme.splashFactory, useMaterial3: otherTheme.useMaterial3, + variant: otherTheme.variant, visualDensity: otherTheme.visualDensity, // COLOR canvasColor: otherTheme.canvasColor, @@ -1615,6 +1718,7 @@ void main() { expect(themeDataCopy.scrollbarTheme, equals(otherTheme.scrollbarTheme)); expect(themeDataCopy.splashFactory, equals(otherTheme.splashFactory)); expect(themeDataCopy.useMaterial3, equals(otherTheme.useMaterial3)); + expect(themeDataCopy.variant, equals(otherTheme.variant)); expect(themeDataCopy.visualDensity, equals(otherTheme.visualDensity)); // COLOR expect(themeDataCopy.canvasColor, equals(otherTheme.canvasColor)); @@ -1761,8 +1865,9 @@ void main() { 'platform', 'scrollbarTheme', 'splashFactory', - 'visualDensity', 'useMaterial3', + 'variant', + 'visualDensity', // COLOR 'colorScheme', 'primaryColor',