menuBarTheme static method
An opinionated MenuBarThemeData theme.
Only offers scheme color and elevation theming at the moment.
Implementation
static MenuBarThemeData menuBarTheme({
// Typically the same [ColorScheme] that is also used for your [ThemeData].
required final ColorScheme colorScheme,
/// Select which color from the passed in [colorScheme] parameter to use as
/// the MenuBar background color.
///
/// If not defined, default to [colorScheme.surface]. FlexColorScheme
/// passes in [FlexSubThemesData.menuBarBackgroundSchemeColor] first uses
/// [FlexSubThemesData.menuSchemeColor] as fallback, that can also be null.
final SchemeColor? backgroundSchemeColor,
/// The shadow color of the MenuBar's [Material].
///
/// The material's elevation shadow can be difficult to see for dark themes,
/// so by default the menu classes add a semi-transparent overlay to
/// indicate elevation. See [ThemeData.applyElevationOverlayColor].
final Color? shadowColor,
/// The surface tint color of the MenuBar's [Material].
///
/// See [Material.surfaceTintColor] for more details.
final Color? surfaceTintColor,
/// The elevation of the MenuBar's [Material].
final double? elevation,
/// MenuBar corner radius.
///
/// If not defined, defaults to 4, the M3 specification, via Flutter SDK
/// widget default values.
final double? radius,
}) {
final Color surface =
schemeColor(backgroundSchemeColor ?? SchemeColor.surface, colorScheme);
final bool allDefault = backgroundSchemeColor == null &&
shadowColor == null &&
surfaceTintColor == null &&
elevation == null &&
radius == null;
return MenuBarThemeData(
style: allDefault
? null
: MenuStyle(
backgroundColor: backgroundSchemeColor != null
? MaterialStatePropertyAll<Color?>(surface)
: null,
surfaceTintColor: surfaceTintColor != null
? MaterialStatePropertyAll<Color?>(surfaceTintColor)
: null,
shadowColor: shadowColor != null
? MaterialStatePropertyAll<Color?>(shadowColor)
: null,
elevation: elevation != null
? MaterialStatePropertyAll<double?>(elevation)
: null,
shape: radius != null
? MaterialStatePropertyAll<OutlinedBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.all(
Radius.circular(radius),
),
),
)
: null,
),
);
}