merge method

UIAdjust merge(
  1. UIAdjust? other
)

Merge user-provided ui adjust with defaults; user values override defaults except for background/button backgrounds which remain white and blue values are ignored.

Implementation

UIAdjust merge(UIAdjust? other) {
  final d = UIAdjust.defaults;
  if (other == null) return d;

  Color sanitizeBackground(Color? c) {
    if (c == null) return d.backgroundColor!;
    if (c == Colors.blue) return Colors.white;
    return c;
  }

  Color sanitizeButtonBg(Color? c) => Colors.white;

  Color sanitizeMerchantHeader(Color? c) {
    if (c == null) return d.merchantHeaderColor!;
    if (c == Colors.blue) return Colors.white;
    return c;
  }

  Color sanitizeForeground(Color? c) {
    if (c == null) return d.buttonForegroundColor!;
    if (c == Colors.blue) return Colors.black;
    return c;
  }

  return UIAdjust(
    u: other._u ?? d._u,
    backgroundColor: sanitizeBackground(other.backgroundColor ?? d.backgroundColor),
    sheetCornerRadius: other.sheetCornerRadius ?? d.sheetCornerRadius,
    merchantHeaderColor: sanitizeMerchantHeader(other.merchantHeaderColor ?? d.merchantHeaderColor),
    merchantHeaderElevation: other.merchantHeaderElevation ?? d.merchantHeaderElevation,
    merchantNameTextStyle: other.merchantNameTextStyle ?? d.merchantNameTextStyle,
    merchantInfoTextStyle: other.merchantInfoTextStyle ?? d.merchantInfoTextStyle,
    summaryTitleTextStyle: other.summaryTitleTextStyle ?? d.summaryTitleTextStyle,
    summaryItemTextStyle: other.summaryItemTextStyle ?? d.summaryItemTextStyle,
    buttonBackgroundColor: sanitizeButtonBg(other.buttonBackgroundColor ?? d.buttonBackgroundColor),
    buttonForegroundColor: sanitizeForeground(other.buttonForegroundColor ?? d.buttonForegroundColor),
    buttonTextStyle: other.buttonTextStyle ?? d.buttonTextStyle,
    contentPadding: other.contentPadding ?? d.contentPadding,
  );
}