fromJson static method
Implementation
static IrGradient? fromJson(Object? json) {
if (json == null) return null;
final m = json as Map<String, Object?>;
(double, double) point(Object? v, (double, double) fallback) {
final l = (v as List?)?.cast<num>();
return l == null ? fallback : (l[0].toDouble(), l[1].toDouble());
}
return IrGradient(
colors: [for (final c in m['colors'] as List) IrColor.fromJson(c)],
stops: [for (final s in (m['stops'] as List)) (s as num).toDouble()],
radial: m['type'] == 'radial',
sweep: m['type'] == 'sweep',
rotation: _d(m['rotation']) ?? 0,
begin: point(m['begin'], (0, 0.5)),
end: point(m['end'], (1, 0.5)),
center: point(m['center'], (0.5, 0.5)),
radius: _d(m['radius']) ?? 0.5,
size: switch (m['size']) {
[final num w, final num h] => (w.toDouble(), h.toDouble()),
_ => null,
},
);
}