Line data Source code
1 : import 'dart:convert';
2 :
3 : /// Represents an image for Google Cast.
4 : class GoogleCastImage {
5 : ///url URI URI for the image
6 : final Uri url;
7 :
8 : ///height integer optional Height of the image
9 : final int? height;
10 :
11 : ///width integer optional Width of the image
12 : final int? width;
13 :
14 : /// Creates a new [GoogleCastImage] instance.
15 0 : GoogleCastImage({
16 : required this.url,
17 : this.height,
18 : this.width,
19 : });
20 :
21 : /// Converts this image to a map representation.
22 0 : Map<String, dynamic> toMap() {
23 0 : return {
24 0 : 'url': url.toString(),
25 0 : 'height': height,
26 0 : 'width': width,
27 : };
28 : }
29 :
30 : /// Creates a [GoogleCastImage] from a map representation.
31 0 : factory GoogleCastImage.fromMap(Map<String, dynamic> map) {
32 0 : return GoogleCastImage(
33 0 : url: Uri.parse(map['url']),
34 0 : height: map['height']?.toInt(),
35 0 : width: map['width']?.toInt(),
36 : );
37 : }
38 :
39 : /// Converts this image to a JSON string.
40 0 : String toJson() => json.encode(toMap());
41 :
42 : /// Creates a [GoogleCastImage] from a JSON string.
43 0 : factory GoogleCastImage.fromJson(String source) =>
44 0 : GoogleCastImage.fromMap(json.decode(source));
45 : }
|