Line data Source code
1 : import 'package:flutter/material.dart';
2 :
3 : import 'package:widgetbook/src/models/resolution.dart';
4 :
5 : /// Category of different device types.
6 4 : enum DeviceType {
7 : watch,
8 : mobile,
9 : tablet,
10 : desktop,
11 : unknown,
12 : }
13 :
14 : /// A virtual device that will rendered when a story is previewed
15 : class Device {
16 : /// For example 'iPhone 12' or 'Samsung S10'.
17 : final String name;
18 :
19 : /// Specifies the native resolution (of the device screen)
20 : /// and the logical resolution (for rendering a preview on the device).
21 : final Resolution resolution;
22 :
23 : /// Categorizes the Device.
24 : /// For instance mobile or tablet.
25 : /// This is used to display an appropriate icon in the device bar.
26 : final DeviceType type;
27 :
28 4 : const Device({
29 : required this.name,
30 : required this.resolution,
31 : required this.type,
32 : });
33 :
34 0 : factory Device.custom({
35 : required String name,
36 : required Resolution resolution,
37 : }) {
38 0 : return Device(
39 : name: name,
40 : resolution: resolution,
41 : type: DeviceType.unknown,
42 : );
43 : }
44 :
45 2 : @override
46 : bool operator ==(Object other) {
47 : if (identical(this, other)) return true;
48 :
49 1 : return other is Device &&
50 3 : other.name == name &&
51 0 : other.resolution == resolution &&
52 0 : other.type == type;
53 : }
54 :
55 1 : @override
56 8 : int get hashCode => name.hashCode ^ resolution.hashCode ^ type.hashCode;
57 : }
58 :
59 : /// Collection of Samsung devices
60 : class Samsung {
61 : static const Device s21ultra = Device(
62 : name: 'S21 Ultra',
63 : type: DeviceType.mobile,
64 : resolution: Resolution(
65 : nativeSize: Size(1440, 3200),
66 : scaleFactor: 3.75,
67 : ),
68 : );
69 :
70 : static const Device s10 = Device(
71 : name: 'S10',
72 : type: DeviceType.mobile,
73 : resolution: Resolution(
74 : nativeSize: Size(1440, 3050),
75 : scaleFactor: 4,
76 : ),
77 : );
78 : }
79 :
80 : // For apple phone sizes and layout see:
81 : // https://developer.apple.com/design/human-interface-guidelines/ios/visual-design/adaptivity-and-layout/
82 :
83 : /// Collection of Apple devices
84 : class Apple {
85 : static const Device iPadPro12inch = Device(
86 : name: '12.9" iPad Pro',
87 : type: DeviceType.tablet,
88 : resolution: Resolution(
89 : nativeSize: Size(2048, 2732),
90 : scaleFactor: 2,
91 : ),
92 : );
93 :
94 : static const Device iPadPro11inch = Device(
95 : name: '11" iPad Pro',
96 : type: DeviceType.tablet,
97 : resolution: Resolution(
98 : nativeSize: Size(1668, 2388),
99 : scaleFactor: 2,
100 : ),
101 : );
102 :
103 : static const Device iPadPro10inch = Device(
104 : name: '10.5" iPad Pro',
105 : type: DeviceType.tablet,
106 : resolution: Resolution(
107 : nativeSize: Size(1668, 2388),
108 : scaleFactor: 2,
109 : ),
110 : );
111 :
112 : static const Device iPadPro9inch = Device(
113 : name: '9.7" iPad Pro',
114 : type: DeviceType.tablet,
115 : resolution: Resolution(
116 : nativeSize: Size(768, 1024),
117 : scaleFactor: 2,
118 : ),
119 : );
120 :
121 : static const Device iPadMini = Device(
122 : name: '7.9" iPad mini',
123 : type: DeviceType.tablet,
124 : resolution: Resolution(
125 : nativeSize: Size(768, 1024),
126 : scaleFactor: 2,
127 : ),
128 : );
129 :
130 : static const Device iPadAir10Inch = Device(
131 : name: '10.5" iPad Air',
132 : type: DeviceType.tablet,
133 : resolution: Resolution(
134 : nativeSize: Size(1668, 2224),
135 : scaleFactor: 2,
136 : ),
137 : );
138 :
139 : static const Device iPadAir9Inch = Device(
140 : name: '9.7" iPad Air',
141 : type: DeviceType.tablet,
142 : resolution: Resolution(
143 : nativeSize: Size(1536, 2048),
144 : scaleFactor: 2,
145 : ),
146 : );
147 :
148 : static const Device iPhone11 = Device(
149 : name: 'iPhone 11',
150 : type: DeviceType.mobile,
151 : resolution: Resolution(
152 : nativeSize: Size(828, 1792),
153 : scaleFactor: 2,
154 : ),
155 : );
156 :
157 : static const Device iPhone12 = Device(
158 : name: 'iPhone 12',
159 : type: DeviceType.mobile,
160 : resolution: Resolution(
161 : nativeSize: Size(1170, 2532),
162 : scaleFactor: 3,
163 : ),
164 : );
165 :
166 : static const Device iPhone12pro = Device(
167 : name: 'iPhone 12 Pro',
168 : type: DeviceType.mobile,
169 : resolution: Resolution(
170 : nativeSize: Size(1170, 2532),
171 : scaleFactor: 3,
172 : ),
173 : );
174 :
175 : static const Device iPhone12mini = Device(
176 : name: 'iPhone 12 Mini',
177 : type: DeviceType.mobile,
178 : resolution: Resolution(
179 : nativeSize: Size(1125, 2436),
180 : scaleFactor: 3,
181 : ),
182 : );
183 : }
|