fromJson method
Implementation
@override
Gradient? fromJson(Map<String, dynamic>? json) {
if (json == null) return null;
var type = json['type'];
switch (type) {
case 'linear':
return LinearGradient(
begin: const NullableAlignmentConverter().fromJson(
json['begin'],
) ??
Alignment.centerLeft,
colors: _decodeStringList<Color>(
json['colors'],
(json) {
var color = const NullableColorConverter().fromJson(json);
return color!;
},
)!,
end: const NullableAlignmentConverter().fromJson(
json['end'],
) ??
Alignment.centerRight,
stops: _decodeDynamicList<double>(
json['stops'],
(json) => (json as num).toDouble(),
),
tileMode: const NullableTileModeConverter().fromJson(
json['tileMode'],
) ??
TileMode.clamp,
transform: const NullableGradientTransformConverter().fromJson(
json['transform'],
),
);
case 'radial':
return RadialGradient(
center: const NullableAlignmentConverter().fromJson(
json['center'],
) ??
Alignment.center,
colors: _decodeStringList<Color>(
json['colors'],
(json) => const NullableColorConverter().fromJson(json)!,
)!,
focal: const NullableAlignmentConverter().fromJson(
json['focal'],
),
focalRadius: ((json['focalRadius'] ?? 0.0) as num).toDouble(),
radius: ((json['radius'] ?? 0.5) as num).toDouble(),
stops: _decodeDynamicList<double>(
json['stops'],
(json) => (json as num).toDouble(),
),
tileMode: const NullableTileModeConverter().fromJson(
json['tileMode'],
) ??
TileMode.clamp,
transform: const NullableGradientTransformConverter().fromJson(
json['transform'],
),
);
case 'sweep':
return SweepGradient(
center: const NullableAlignmentConverter().fromJson(
json['center'],
) ??
Alignment.center,
colors: _decodeStringList<Color>(
json['colors'],
(json) => const NullableColorConverter().fromJson(json)!,
)!,
endAngle: ((json['endAngle'] ?? math.pi * 2) as num).toDouble(),
startAngle: ((json['startAngle'] ?? 0.0) as num).toDouble(),
stops: _decodeDynamicList<double>(
json['stops'],
(json) => (json as num).toDouble(),
),
tileMode: const NullableTileModeConverter().fromJson(
json['tileMode'],
) ??
TileMode.clamp,
transform: const NullableGradientTransformConverter().fromJson(
json['transform'],
),
);
}
throw 'Unsuported_Json_Value';
}