Line data Source code
1 : import 'package:meta/meta.dart'; 2 : import 'package:widgetbook_models/src/devices/device_type.dart'; 3 : import 'package:widgetbook_models/src/devices/resolution.dart'; 4 : 5 : /// A virtual device that will rendered when a story is previewed 6 : @immutable 7 : class Device { 8 : /// Creates a new device with [name], [resolution], and [type]. 9 1 : const Device({ 10 : required this.name, 11 : required this.resolution, 12 : required this.type, 13 : }); 14 : 15 : /// Creates a new watch device 16 1 : const Device.watch({ 17 : required this.name, 18 : required this.resolution, 19 : }) : type = DeviceType.watch; 20 : 21 : /// Creates a new mobile device 22 5 : const Device.mobile({ 23 : required this.name, 24 : required this.resolution, 25 : }) : type = DeviceType.mobile; 26 : 27 : /// Creates a new tablet device 28 3 : const Device.tablet({ 29 : required this.name, 30 : required this.resolution, 31 : }) : type = DeviceType.tablet; 32 : 33 : /// Creates a new desktop device 34 1 : const Device.desktop({ 35 : required this.name, 36 : required this.resolution, 37 : }) : type = DeviceType.desktop; 38 : 39 : /// Creates a new special device which does not fit into the other categories 40 1 : const Device.special({ 41 : required this.name, 42 : required this.resolution, 43 : }) : type = DeviceType.unknown; 44 : 45 : /// For example 'iPhone 12' or 'Samsung S10'. 46 : final String name; 47 : 48 : /// Specifies the native resolution (of the device screen) 49 : /// and the logical resolution (for rendering a preview on the device). 50 : final Resolution resolution; 51 : 52 : /// Categorizes the Device. 53 : /// For instance mobile or tablet. 54 : /// This is used to display an appropriate icon in the device bar. 55 : final DeviceType type; 56 : 57 1 : @override 58 : bool operator ==(Object other) { 59 : if (identical(this, other)) return true; 60 : 61 1 : return other is Device && 62 3 : other.name == name && 63 3 : other.resolution == resolution && 64 3 : other.type == type; 65 : } 66 : 67 1 : @override 68 8 : int get hashCode => name.hashCode ^ resolution.hashCode ^ type.hashCode; 69 : }