getButtonStyle method

ButtonStyle? getButtonStyle(
  1. Map? spec
)

Implementation

ButtonStyle? getButtonStyle(Map? spec) {
  if (spec == null || spec.isEmpty) return null;

  final padding = Lowder.properties.getInsets(spec["padding"]);
  final textStyle = getTextStyle(spec["textStyle"]);
  final backgroundColor = tryParseColor(spec["backgroundColor"]);
  final foregroundColor = tryParseColor(spec["foregroundColor"]);
  final overlayColor = tryParseColor(spec["overlayColor"]);
  final fixedSize = getSize(spec["fixedSize"]);
  final maximumSize = getSize(spec["maximumSize"]);
  final minimumSize = getSize(spec["minimumSize"]);
  BorderSide? borderSide;
  if (spec["side"] != null &&
      spec["side"]["color"] != null &&
      spec["side"]["width"] != null) {
    borderSide = BorderSide(
      color: parseColor(spec["side"]["color"], defaultColor: Colors.black),
      width: parseDouble(spec["side"]["width"], defaultValue: 1.0),
    );
  }
  final VisualDensity visualDensity;
  switch (spec["visualDensity"] ?? "") {
    case "comfortable":
      visualDensity = VisualDensity.comfortable;
      break;
    case "compact":
      visualDensity = VisualDensity.compact;
      break;
    case "standard":
      visualDensity = VisualDensity.standard;
      break;
    default:
      visualDensity = VisualDensity.adaptivePlatformDensity;
      break;
  }

  return ButtonStyle(
    alignment: getAlignment(spec["alignment"]),
    shape: spec["shape"] != null
        ? WidgetStateProperty.all(getShapeBorder(spec["shape"]))
        : null,
    padding:
        padding != null ? WidgetStateProperty.all<EdgeInsets>(padding) : null,
    foregroundColor: foregroundColor != null
        ? WidgetStateProperty.all<Color>(foregroundColor)
        : null,
    backgroundColor: backgroundColor != null
        ? WidgetStateProperty.all<Color>(backgroundColor)
        : null,
    surfaceTintColor: backgroundColor != null
        ? WidgetStateProperty.all<Color>(backgroundColor)
        : null,
    overlayColor: overlayColor != null
        ? WidgetStateProperty.all<Color>(overlayColor)
        : null,
    side: borderSide != null
        ? WidgetStateProperty.all<BorderSide>(borderSide)
        : null,
    textStyle: textStyle != null
        ? WidgetStateProperty.all<TextStyle>(textStyle)
        : null,
    fixedSize:
        fixedSize != null ? WidgetStateProperty.all<Size>(fixedSize) : null,
    maximumSize: maximumSize != null
        ? WidgetStateProperty.all<Size>(maximumSize)
        : null,
    minimumSize: minimumSize != null
        ? WidgetStateProperty.all<Size>(minimumSize)
        : null,
    visualDensity: visualDensity,
  );
}