parseGradient static method

LinearGradient? parseGradient(
  1. Object? source,
  2. bool dark
)

Implementation

static LinearGradient? parseGradient(Object? source, bool dark) {
  if (source is! Map || source.isEmpty) return null;
  final colors = source['colors'];
  final mColors = colors is List
      ? colors
          .map((e) => parseThemedColor(e, dark))
          .whereType<Color>()
          .toList()
      : <Color>[];
  if (mColors.length < 2) return null;
  final stops = source['stops'];
  final tileMode = source['tileMode'];
  return LinearGradient(
    begin: parseAlignment(source['begin']) ?? Alignment.centerLeft,
    end: parseAlignment(source['end']) ?? Alignment.centerRight,
    colors: mColors,
    stops: stops is List
        ? stops.map(parseDouble).whereType<double>().toList()
        : [],
    tileMode: TileMode.values.where((e) {
          if (e.toString() == tileMode.toString()) return true;
          if (e.name == tileMode.toString()) return true;
          return false;
        }).firstOrNull ??
        TileMode.clamp,
    transform: parseGradientTransform(source["transform"]),
  );
}