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
        ? MaterialStateProperty.all(getShapeBorder(spec["shape"]))
        : null,
    padding: padding != null
        ? MaterialStateProperty.all<EdgeInsets>(padding)
        : null,
    foregroundColor: foregroundColor != null
        ? MaterialStateProperty.all<Color>(foregroundColor)
        : null,
    backgroundColor: backgroundColor != null
        ? MaterialStateProperty.all<Color>(backgroundColor)
        : null,
    surfaceTintColor: backgroundColor != null
        ? MaterialStateProperty.all<Color>(backgroundColor)
        : null,
    overlayColor: overlayColor != null
        ? MaterialStateProperty.all<Color>(overlayColor)
        : null,
    side: borderSide != null
        ? MaterialStateProperty.all<BorderSide>(borderSide)
        : null,
    textStyle: textStyle != null
        ? MaterialStateProperty.all<TextStyle>(textStyle)
        : null,
    fixedSize:
        fixedSize != null ? MaterialStateProperty.all<Size>(fixedSize) : null,
    maximumSize: maximumSize != null
        ? MaterialStateProperty.all<Size>(maximumSize)
        : null,
    minimumSize: minimumSize != null
        ? MaterialStateProperty.all<Size>(minimumSize)
        : null,
    visualDensity: visualDensity,
  );
}