resolveColorToArgb function

int? resolveColorToArgb(
  1. Color? color,
  2. BuildContext context
)

Resolves a possibly dynamic Cupertino color to a concrete ARGB int for the current BuildContext. Falls back to the raw color if not dynamic.

Purpose

This function handles Flutter's dynamic colors (colors that change based on brightness, contrast, or accessibility settings) by resolving them in the current context before converting to native format.

Parameters

  • color: The color to resolve (nullable)
  • context: The build context for resolving dynamic colors

Returns

An ARGB integer suitable for passing to native iOS/macOS code, or null if the input color is null.

Example

final tintInt = resolveColorToArgb(
  CupertinoColors.systemBlue,
  context,
); // Returns: 0xFF007AFF (iOS system blue)

Implementation

int? resolveColorToArgb(Color? color, BuildContext context) {
  if (color == null) return null;
  if (color is CupertinoDynamicColor) {
    final resolved = color.resolveFrom(context);
    return _argbFromColor(resolved);
  }
  return _argbFromColor(color);
}