toJson method
Implementation
@override
Map<String, dynamic>? toJson(Gradient? object) {
if (object == null) return null;
if (object is LinearGradient) {
return {
'begin': const NullableAlignmentConverter()
.toJson(object.begin as Alignment?),
'colors': _encodeList<String?>(
object.colors,
(object) => const NullableColorConverter().toJson(object),
),
'end':
const NullableAlignmentConverter().toJson(object.end as Alignment?),
'stops': object.stops,
'tileMode': const NullableTileModeConverter().toJson(object.tileMode),
'transform':
const NullableGradientTransformConverter().toJson(object.transform),
'type': 'linear',
};
} else if (object is RadialGradient) {
return {
'center': const NullableAlignmentConverter()
.toJson(object.center as Alignment?),
'colors': _encodeList<String?>(
object.colors,
(object) => const NullableColorConverter().toJson(object),
),
'focal': const NullableAlignmentConverter()
.toJson(object.focal as Alignment?),
'focalRadius': object.focalRadius,
'radius': object.radius,
'stops': object.stops,
'tileMode': const NullableTileModeConverter().toJson(object.tileMode),
'transform':
const NullableGradientTransformConverter().toJson(object.transform),
'type': 'radial',
};
} else if (object is SweepGradient) {
return {
'center': const NullableAlignmentConverter()
.toJson(object.center as Alignment?),
'colors': _encodeList<String?>(
object.colors,
(object) => const NullableColorConverter().toJson(object),
),
'endAngle': object.endAngle,
'startAngle': object.startAngle,
'stops': object.stops,
'tileMode': const NullableTileModeConverter().toJson(object.tileMode),
'transform':
const NullableGradientTransformConverter().toJson(object.transform),
'type': 'sweep',
};
}
throw 'Json_Unsuported_Value';
}