flatButtonStyle function

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

Returns a ButtonStyle that is used to make a TextButton look like a deprecated FlatButton, but with given styles.

Implementation

ButtonStyle flatButtonStyle({
  Color? primary,
  Color? onSurface,
  Color? backgroundColor,
  Color? shadowColor,
  Color? splashColor,
  double? elevation,
  TextStyle? textStyle,
  EdgeInsetsGeometry? padding,
  Size? minimumSize,
  Size? fixedSize,
  Size? maximumSize,
  BorderSide? side,
  OutlinedBorder? shape,
  MouseCursor? enabledMouseCursor,
  MouseCursor? disabledMouseCursor,
  VisualDensity? visualDensity,
  MaterialTapTargetSize? tapTargetSize,
  Duration? animationDuration,
  bool? enableFeedback,
  AlignmentGeometry? alignment,
  InteractiveInkFeatureFactory? splashFactory,
}) {
  var style = TextButton.styleFrom(
    // fields for FlatButton
    primary: primary ?? Colors.black87,
    padding: padding ?? const EdgeInsets.symmetric(horizontal: 16.0),
    shape: shape ?? const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(2.0))),
    // fields for TextButton
    onSurface: onSurface,
    backgroundColor: backgroundColor,
    shadowColor: shadowColor,
    elevation: elevation,
    textStyle: textStyle,
    minimumSize: minimumSize,
    fixedSize: fixedSize,
    maximumSize: maximumSize,
    side: side,
    enabledMouseCursor: enabledMouseCursor,
    disabledMouseCursor: disabledMouseCursor,
    visualDensity: visualDensity,
    tapTargetSize: tapTargetSize,
    animationDuration: animationDuration,
    enableFeedback: enableFeedback,
    alignment: alignment,
    splashFactory: splashFactory,
  );
  if (splashColor != null) {
    // add extra splashColor style
    style = style.copyWith(
      overlayColor: MaterialStateProperty.resolveWith(
        (s) => s.contains(MaterialState.pressed) ? splashColor : null,
      ),
    );
  }
  return style;
}