buildGradient method

String buildGradient()

Builds the CSS gradient string from the properties.

Implementation

String buildGradient() {
  // Full gradient string takes precedence
  if (gradient != null) return gradient!;

  // Multi-color stops
  if (colorStops != null && colorStops!.isNotEmpty) {
    final angle = gradientAngle ?? '135deg';
    final stops = <String>[];

    for (var i = 0; i < colorStops!.length; i++) {
      final stop = colorStops![i];
      if (stop.position != null) {
        stops.add(stop.css);
      } else {
        // Evenly distribute stops without explicit positions
        final position = i / (colorStops!.length - 1) * 100;
        stops.add('${stop.color} ${position.round()}%');
      }
    }

    return 'linear-gradient($angle, ${stops.join(', ')})';
  }

  // Simple two-color gradient
  final start = gradientStart ?? 'var(--primary)';
  final end = gradientEnd ?? 'var(--accent)';
  final angle = gradientAngle ?? '135deg';
  return 'linear-gradient($angle, $start 0%, $end 100%)';
}