drawerTheme static method

DrawerThemeData drawerTheme({
  1. required ColorScheme colorScheme,
  2. SchemeColor? backgroundSchemeColor,
  3. double? radius,
  4. double? elevation,
  5. Color? shadowColor,
  6. Color? surfaceTintColor,
  7. double? width,
  8. bool? useMaterial3,
})

An opinionated DrawerThemeData theme for the Drawer.

The NavigationDrawer also uses these value for its drawer parts. Its menu part has an own theme in Flutter SDK.

Implementation

static DrawerThemeData drawerTheme({
  /// Typically the same [ColorScheme] that is also used for your [ThemeData].
  required final ColorScheme colorScheme,

  /// Selects which color from the passed in [colorScheme] to use as
  /// [Drawer] background color.
  ///
  /// If not defined, defaults to [SchemeColor.surface]. Flutter
  /// SDK uses surface color as default in M3, and background in M2.
  /// FCS uses surface in both modes.
  final SchemeColor? backgroundSchemeColor,

  /// Corner radius of the [Drawer]'s visible edge.
  ///
  /// If not defined, defaults to [kDrawerRadius] 16 dp in M2 mode,
  /// in M3 mode, null is kept but gets 16 via M3 mode defaults.
  /// The 16 dp values is based on M3 specification:
  /// https://m3.material.io/components/navigation-drawer/specs
  final double? radius,

  /// Drawer elevation.
  ///
  /// If not defined, defaults to Flutter default values, in M2 mode (16)
  /// and in M3 (1) via SDK defaults.
  final double? elevation,

  /// Drawer elevation shadow color.
  ///
  /// In M2 defaults to [Colors.black] and elevation casts a shadow.
  /// In M3 it defaults [Colors.transparent] and there is no shadow.
  final Color? shadowColor,

  /// Overrides the default value for [Drawer.surfaceTintColor].
  final Color? surfaceTintColor,

  /// Themes the default width of the [Drawer].
  ///
  /// Currently not available as a property in [FlexSubThemesData], may be
  /// added later.
  final double? width,

  /// A temporary flag used to opt-in to Material 3 features.
  ///
  /// If set to true, the theme will use Material3 default styles when
  /// properties are undefined, if false defaults will use FlexColorScheme's
  /// own opinionated default values.
  ///
  /// The M2/M3 defaults will only be used for properties that are not
  /// defined, if defined they keep their defined values.
  ///
  /// If undefined, defaults to false.
  final bool? useMaterial3,
}) {
  final bool useM3 = useMaterial3 ?? false;
  // Get selected background color, defaults to surface.
  final Color backgroundColor =
      schemeColor(backgroundSchemeColor ?? SchemeColor.surface, colorScheme);

  return DrawerThemeData(
    backgroundColor: backgroundColor,
    elevation: elevation,
    width: width,
    shadowColor: shadowColor,
    surfaceTintColor: surfaceTintColor,
    shape: useM3 && radius == null
        ? null
        : RoundedRectangleBorder(
            borderRadius: BorderRadiusDirectional.horizontal(
              end: Radius.circular(radius ?? kDrawerRadius),
            ),
          ),
    endShape: useM3 && radius == null
        ? null
        : RoundedRectangleBorder(
            borderRadius: BorderRadiusDirectional.horizontal(
              start: Radius.circular(radius ?? kDrawerRadius),
            ),
          ),
  );
}