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

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

The foregroundColor color is used to create a WidgetStateProperty 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.

Similarly, the enabledMouseCursor and disabledMouseCursor parameters are used to construct ButtonStyle.mouseCursor.

The iconColor, disabledIconColor are used to construct ButtonStyle.iconColor and iconSize is used to construct ButtonStyle.iconSize.

All of the other parameters are either used directly or used to create a WidgetStateProperty 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 SubmenuButton, as well as its overlay color, with all of the standard opacity adjustments for the pressed, focused, and hovered states, one could write:

SubmenuButton(
  leadingIcon: const Icon(Icons.pets),
  style: SubmenuButton.styleFrom(foregroundColor: Colors.green),
  menuChildren: const <Widget>[ /* ... */ ],
  child: const Text('Button Label'),
),

Implementation

static ButtonStyle styleFrom({
  Color? foregroundColor,
  Color? backgroundColor,
  Color? disabledForegroundColor,
  Color? disabledBackgroundColor,
  Color? shadowColor,
  Color? surfaceTintColor,
  Color? iconColor,
  double? iconSize,
  Color? disabledIconColor,
  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,
    disabledIconColor: disabledIconColor,
    iconSize: iconSize,
    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,
  );
}