toGradient static method

Gradient? toGradient({
  1. Data? colors,
  2. Data? linear,
  3. Data? radial,
  4. Data? sweep,
})

Implementation

static Gradient? toGradient({
  Data? colors,
  Data? linear,
  Data? radial,
  Data? sweep,
}) {
  if (colors == null) return null;
  final colorsList = colors.value
      .map<Color>((Data e) => e.toColor())
      .toList();
  if (colorsList.isEmpty) return null;

  if (linear != null) {
    final begin = linear.value['begin'];
    final end = linear.value['end'];
    return LinearGradient(
      colors: colorsList,
      begin:
          begin?._value['x']._value != null &&
              begin?._value['y']._value != null
          ? Alignment(begin!._value['x']._value, begin._value['y']._value)
          : Alignment.centerLeft,
      end: end?._value['x']._value != null && end?._value['y']._value != null
          ? Alignment(end!._value['x']._value, end._value['y']._value)
          : Alignment.centerRight,
    );
  }

  if (radial != null) return RadialGradient(colors: colorsList);
  if (sweep != null) return SweepGradient(colors: colorsList);
  return null;
}