generateHippyLinearGradient static method
LinearGradient?
generateHippyLinearGradient(
- double width,
- double height,
- String angle,
- VoltronArray colorStopList,
Implementation
static LinearGradient? generateHippyLinearGradient (double width, double height, String angle, VoltronArray colorStopList) {
if (colorStopList.size() < 2) return null;
var oppositeDegree = _getOppositeAngle(width, height);
var gradientAngle = _calculateGradientAngle(angle, oppositeDegree);
var initBeginAndEnd = _checkSpecialAngle(gradientAngle);
Alignment begin;
Alignment end;
initBeginAndEnd ??= _calculateBeginAndEnd(width, height, gradientAngle, oppositeDegree);
begin = initBeginAndEnd[0];
end = initBeginAndEnd[1];
var colors = <Color>[];
var stops = <double>[];
for (var i = 0; i < colorStopList.size(); i++) {
VoltronMap? colorStop = colorStopList.get<VoltronMap>(i);
var color = colorStop?.get<int>('color') ?? colorStop?.get<double>('color')?.toInt();
var stop = colorStop?.get<double>('ratio');
if (color != null) colors.add(Color(color));
if (stop != null) stops.add(stop);
}
return LinearGradient(
begin: begin,
end: end,
colors: colors,
stops: stops.isNotEmpty ? stops : null,
);
}