dialogTheme static method

DialogTheme dialogTheme({
  1. ColorScheme? colorScheme,
  2. Color? backgroundColor,
  3. SchemeColor? backgroundSchemeColor,
  4. double? radius,
  5. double? elevation,
  6. Color? shadowColor,
  7. Color? surfaceTintColor,
  8. TextStyle? titleTextStyle,
  9. TextStyle? contentTextStyle,
  10. EdgeInsetsGeometry? actionsPadding,
})

An opinionated DialogTheme with custom corner radius and elevation.

Corner radius defaults to kDialogRadius = 28 and elevation to kDialogElevation = 10.

The default radius follows Material M3 guide specification.

Implementation

static DialogTheme dialogTheme({
  /// Typically the same [ColorScheme] that is also use for your [ThemeData].
  final ColorScheme? colorScheme,

  /// Dialog background color.
  ///
  /// If null and [backgroundSchemeColor] is also null, then it
  /// gets default via Dialog's default null theme behavior.
  ///
  /// If [backgroundSchemeColor] is defined, it will override any color
  /// passed in here.
  ///
  /// Can be used to make a custom themed dialog with own background color,
  /// even after the [ThemeData.dialogBackgroundColor] property is
  /// is deprecated in Flutter SDK. See
  /// https://github.com/flutter/flutter/issues/91772).
  final Color? backgroundColor,

  /// Selects which color from the passed in colorScheme to use as the dialog
  /// background color.
  ///
  /// If not defined, then the passed in [backgroundColor] will be used,
  /// which may be null too and dialog then falls back to Flutter SDK default
  /// value for TimePickerDialog, which is [colorScheme.surface].
  ///
  /// FlexColorScheme sub-theming uses this property to match the background
  /// color of this dialog to other standard dialogs. It sets it via
  /// [FlexSubThemesData] to [SchemeColor.surface].
  final SchemeColor? backgroundSchemeColor,

  /// Corner radius of the dialog.
  ///
  /// If not defined, defaults to [kDialogRadius] 28dp,
  /// based on M3 Specification
  /// https://m3.material.io/components/dialogs/specs
  final double? radius,

  /// Dialog elevation.
  ///
  /// If not defined, defaults to [kDialogElevation] = 6.
  final double? elevation,

  /// Overrides the default value for [Dialog.shadowColor].
  final Color? shadowColor,

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

  /// Overrides the default value for [DefaultTextStyle] for
  /// [SimpleDialog.title] and [AlertDialog.title].
  final TextStyle? titleTextStyle,

  /// Overrides the default value for [DefaultTextStyle] for
  /// [SimpleDialog.children] and [AlertDialog.content].
  final TextStyle? contentTextStyle,

  /// Padding around the set of [actions] at the bottom of the dialog.
  ///
  /// Typically used to provide padding to the button bar between the button
  /// bar and the edges of the dialog.
  ///
  /// If there are no [actions], then no padding will be included. It is also
  /// important to note that [buttonPadding] may contribute to the padding on
  /// the edges of [actions] as well.
  ///
  /// If null defaults to:
  /// const EdgeInsets.only(left: 24.0, right: 24.0, bottom: 24.0)
  /// same as M3 default.
  final EdgeInsetsGeometry? actionsPadding,
}) {
  final Color? background =
      colorScheme == null || backgroundSchemeColor == null
          ? backgroundColor // might be null, then SDK theme defaults.
          : schemeColor(backgroundSchemeColor, colorScheme);

  return DialogTheme(
    elevation: elevation ?? kDialogElevation,
    backgroundColor: background,
    actionsPadding: actionsPadding ??
        const EdgeInsets.only(left: 24.0, right: 24.0, bottom: 24.0),
    shape: RoundedRectangleBorder(
      borderRadius: BorderRadius.all(
        Radius.circular(radius ?? kDialogRadius),
      ),
    ),
    shadowColor: shadowColor,
    surfaceTintColor: surfaceTintColor,
    titleTextStyle: titleTextStyle,
    contentTextStyle: contentTextStyle,
  );
}