Line data Source code
1 : import 'package:meta/meta.dart'; 2 : import 'package:widgetbook_models/src/devices/device_size.dart'; 3 : 4 : /// The resolution of a device defined by the nativeSize of the Device 5 : /// and its scaling factor. 6 : @immutable 7 : class Resolution { 8 : /// Creates a new instance based on nativeSize and scaleFactor 9 6 : const Resolution({ 10 : required this.nativeSize, 11 : required this.scaleFactor, 12 : }); 13 : 14 : /// Crates a newinstance based on nativeWidth, nativeHeight and scaleFactor 15 2 : factory Resolution.dimensions({ 16 : required double nativeWidth, 17 : required double nativeHeight, 18 : required double scaleFactor, 19 : }) { 20 2 : return Resolution( 21 2 : nativeSize: DeviceSize( 22 : width: nativeWidth, 23 : height: nativeHeight, 24 : ), 25 : scaleFactor: scaleFactor, 26 : ); 27 : } 28 : 29 : /// The logicalSize defines the number of pixels in the render engine. 30 : /// It is calculated by using the following formula: 31 : /// logicalSize = nativeSize / scaleFactor 32 4 : DeviceSize get logicalSize => nativeSize / scaleFactor; 33 : 34 : /// The nativeSize defines the number of pixels of the device screen. 35 : /// It is used to calculate the logical size of the device by 36 : /// using the following formula: 37 : /// logicalSize = nativeSize / scaleFactor 38 : final DeviceSize nativeSize; 39 : 40 : /// The scaleFactor is used to calculate the logical size of the device by 41 : /// using the following formula: 42 : /// logicalSize = nativeSize / scaleFactor 43 : final double scaleFactor; 44 : 45 2 : @override 46 : bool operator ==(Object other) { 47 : if (identical(this, other)) return true; 48 : 49 2 : return other is Resolution && 50 6 : other.nativeSize == nativeSize && 51 6 : other.scaleFactor == scaleFactor; 52 : } 53 : 54 2 : @override 55 10 : int get hashCode => nativeSize.hashCode ^ scaleFactor.hashCode; 56 : }