LinearGradientSpec.fromJson constructor
LinearGradientSpec.fromJson(
- Map<String, dynamic> json
)
Implementation
factory LinearGradientSpec.fromJson(Map<String, dynamic> json) {
_requireExactKeys(json, const <String>{
'start',
'end',
'stops',
}, 'LinearGradientSpec');
final stops = json['stops'];
if (stops is! List) {
throw const FormatException('LinearGradientSpec.stops must be a list.');
}
return LinearGradientSpec(
start: _gradientPoint(json['start'], 'LinearGradientSpec.start'),
end: _gradientPoint(json['end'], 'LinearGradientSpec.end'),
stops: stops.map((raw) {
if (raw is! Map || raw.keys.any((key) => key is! String)) {
throw const FormatException(
'LinearGradientSpec.stops must contain objects with string keys.',
);
}
return GradientStop.fromJson(Map<String, dynamic>.from(raw));
}),
);
}