styleFrom static method

ButtonStyle styleFrom(
  1. {Color? foregroundColor,
  2. Color? backgroundColor,
  3. Color? disabledForegroundColor,
  4. Color? disabledBackgroundColor,
  5. Color? shadowColor,
  6. Color? surfaceTintColor,
  7. Color? iconColor,
  8. TextStyle? textStyle,
  9. double? elevation,
  10. EdgeInsetsGeometry? padding,
  11. Size? minimumSize,
  12. Size? fixedSize,
  13. Size? maximumSize,
  14. MouseCursor? enabledMouseCursor,
  15. MouseCursor? disabledMouseCursor,
  16. BorderSide? side,
  17. OutlinedBorder? shape,
  18. VisualDensity? visualDensity,
  19. MaterialTapTargetSize? tapTargetSize,
  20. Duration? animationDuration,
  21. bool? enableFeedback,
  22. AlignmentGeometry? alignment,
  23. InteractiveInkFeatureFactory? splashFactory}
)

A static convenience method that constructs a MenuItemButton's ButtonStyle given simple values.

The foregroundColor color is used to create a MaterialStateProperty ButtonStyle.foregroundColor value. Specify a value for foregroundColor to specify the color of the button's icons. Use backgroundColor for the button's background fill color. Use disabledForegroundColor and disabledBackgroundColor to specify the button's disabled icon and fill color.

All of the other parameters are either used directly or used to create a MaterialStateProperty with a single value for all states.

All parameters default to null, by default this method returns a ButtonStyle that doesn't override anything.

For example, to override the default foreground color for a MenuItemButton, as well as its overlay color, with all of the standard opacity adjustments for the pressed, focused, and hovered states, one could write:

MenuItemButton(
  leadingIcon: const Icon(Icons.pets),
  style: MenuItemButton.styleFrom(foregroundColor: Colors.green),
  onPressed: () {
    // ...
  },
  child: const Text('Button Label'),
),

Implementation

static ButtonStyle styleFrom({
  Color? foregroundColor,
  Color? backgroundColor,
  Color? disabledForegroundColor,
  Color? disabledBackgroundColor,
  Color? shadowColor,
  Color? surfaceTintColor,
  Color? iconColor,
  TextStyle? textStyle,
  double? elevation,
  EdgeInsetsGeometry? padding,
  Size? minimumSize,
  Size? fixedSize,
  Size? maximumSize,
  MouseCursor? enabledMouseCursor,
  MouseCursor? disabledMouseCursor,
  BorderSide? side,
  OutlinedBorder? shape,
  VisualDensity? visualDensity,
  MaterialTapTargetSize? tapTargetSize,
  Duration? animationDuration,
  bool? enableFeedback,
  AlignmentGeometry? alignment,
  InteractiveInkFeatureFactory? splashFactory,
}) {
  return TextButton.styleFrom(
    foregroundColor: foregroundColor,
    backgroundColor: backgroundColor,
    disabledBackgroundColor: disabledBackgroundColor,
    disabledForegroundColor: disabledForegroundColor,
    shadowColor: shadowColor,
    surfaceTintColor: surfaceTintColor,
    iconColor: iconColor,
    textStyle: textStyle,
    elevation: elevation,
    padding: padding,
    minimumSize: minimumSize,
    fixedSize: fixedSize,
    maximumSize: maximumSize,
    enabledMouseCursor: enabledMouseCursor,
    disabledMouseCursor: disabledMouseCursor,
    side: side,
    shape: shape,
    visualDensity: visualDensity,
    tapTargetSize: tapTargetSize,
    animationDuration: animationDuration,
    enableFeedback: enableFeedback,
    alignment: alignment,
    splashFactory: splashFactory,
  );
}