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. Color? overlayColor,
  10. double? elevation,
  11. EdgeInsetsGeometry? padding,
  12. Size? minimumSize,
  13. Size? fixedSize,
  14. Size? maximumSize,
  15. MouseCursor? enabledMouseCursor,
  16. MouseCursor? disabledMouseCursor,
  17. BorderSide? side,
  18. OutlinedBorder? shape,
  19. VisualDensity? visualDensity,
  20. MaterialTapTargetSize? tapTargetSize,
  21. Duration? animationDuration,
  22. bool? enableFeedback,
  23. AlignmentGeometry? alignment,
  24. 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,
  Color? overlayColor,
  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,
    overlayColor: overlayColor,
    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,
  );
}