LCOV - code coverage report
Current view: | top level - src/models - device.dart (source / functions) |  |  | Hit | Total | Coverage
Test: | lcov.info |  | Lines: | 11 | 11 | 100.0 %
Date: | 2021-10-11 06:57:03 |  | Functions: | 0 | 0 | -

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

Generated by: LCOV version 1.15