Navaron Bracke

format & analyze

@@ -3,141 +3,155 @@ import 'package:flutter_test/flutter_test.dart'; @@ -3,141 +3,155 @@ import 'package:flutter_test/flutter_test.dart';
3 import 'package:mobile_scanner/src/scan_window_calculation.dart'; 3 import 'package:mobile_scanner/src/scan_window_calculation.dart';
4 4
5 void main() { 5 void main() {
6 - group('Scan window relative to texture', () {  
7 - group('Widget (landscape) smaller than texture (portrait)', () {  
8 - const textureSize = Size(480.0, 640.0);  
9 - const widgetSize = Size(432.0, 256.0);  
10 - final ctx = ScanWindowTestContext(  
11 - textureSize: textureSize,  
12 - widgetSize: widgetSize,  
13 - scanWindow: Rect.fromLTWH(  
14 - widgetSize.width / 4,  
15 - widgetSize.height / 4,  
16 - widgetSize.width / 2,  
17 - widgetSize.height / 2,  
18 - ),  
19 - );  
20 -  
21 - test('wl tp: BoxFit.none', () {  
22 - ctx.testScanWindow(  
23 - BoxFit.none,  
24 - const Rect.fromLTRB(0.275, 0.4, 0.725, 0.6), 6 + group(
  7 + 'Scan window relative to texture',
  8 + () {
  9 + group('Widget (landscape) smaller than texture (portrait)', () {
  10 + const textureSize = Size(480.0, 640.0);
  11 + const widgetSize = Size(432.0, 256.0);
  12 + final ctx = ScanWindowTestContext(
  13 + textureSize: textureSize,
  14 + widgetSize: widgetSize,
  15 + scanWindow: Rect.fromLTWH(
  16 + widgetSize.width / 4,
  17 + widgetSize.height / 4,
  18 + widgetSize.width / 2,
  19 + widgetSize.height / 2,
  20 + ),
25 ); 21 );
26 - });  
27 -  
28 - test('wl tp: BoxFit.fill', () {  
29 - ctx.testScanWindow(  
30 - BoxFit.fill,  
31 - const Rect.fromLTRB(0.25, 0.25, 0.75, 0.75),  
32 - );  
33 - });  
34 -  
35 - test('wl tp: BoxFit.fitHeight', () {  
36 - ctx.testScanWindow(  
37 - BoxFit.fitHeight,  
38 - const Rect.fromLTRB(0.0, 0.25, 1.0, 0.75),  
39 - );  
40 - });  
41 -  
42 - test('wl tp: BoxFit.fitWidth', () {  
43 - ctx.testScanWindow(  
44 - BoxFit.fitWidth,  
45 - const Rect.fromLTRB(0.25, 0.38888888888888895, 0.75, 0.6111111111111112),  
46 - );  
47 - });  
48 -  
49 - test('wl tp: BoxFit.cover', () {  
50 - // equal to fitWidth  
51 - ctx.testScanWindow(  
52 - BoxFit.cover,  
53 - const Rect.fromLTRB(0.25, 0.38888888888888895, 0.75, 0.6111111111111112),  
54 - );  
55 - });  
56 -  
57 - test('wl tp: BoxFit.contain', () {  
58 - // equal to fitHeigth  
59 - ctx.testScanWindow(  
60 - BoxFit.contain,  
61 - const Rect.fromLTRB(0.0, 0.25, 1.0, 0.75),  
62 - );  
63 - });  
64 -  
65 - test('wl tp: BoxFit.scaleDown', () {  
66 - // equal to fitHeigth, contain  
67 - ctx.testScanWindow(  
68 - BoxFit.scaleDown,  
69 - const Rect.fromLTRB(0.0, 0.25, 1.0, 0.75),  
70 - );  
71 - });  
72 - });  
73 -  
74 - group('Widget (landscape) smaller than texture and texture (landscape)', () {  
75 - const textureSize = Size(640.0, 480.0);  
76 - const widgetSize = Size(320.0, 120.0);  
77 - final ctx = ScanWindowTestContext(  
78 - textureSize: textureSize,  
79 - widgetSize: widgetSize,  
80 - scanWindow: Rect.fromLTWH(  
81 - widgetSize.width / 4,  
82 - widgetSize.height / 4,  
83 - widgetSize.width / 2,  
84 - widgetSize.height / 2,  
85 - ),  
86 - );  
87 -  
88 - test('wl tl: BoxFit.none', () {  
89 - ctx.testScanWindow(  
90 - BoxFit.none,  
91 - const Rect.fromLTRB(0.375, 0.4375, 0.625, 0.5625),  
92 - );  
93 - });  
94 22
95 - test('wl tl: BoxFit.fill', () {  
96 - ctx.testScanWindow(  
97 - BoxFit.fill,  
98 - const Rect.fromLTRB(0.25, 0.25, 0.75, 0.75),  
99 - ); 23 + test('wl tp: BoxFit.none', () {
  24 + ctx.testScanWindow(
  25 + BoxFit.none,
  26 + const Rect.fromLTRB(0.275, 0.4, 0.725, 0.6),
  27 + );
  28 + });
  29 +
  30 + test('wl tp: BoxFit.fill', () {
  31 + ctx.testScanWindow(
  32 + BoxFit.fill,
  33 + const Rect.fromLTRB(0.25, 0.25, 0.75, 0.75),
  34 + );
  35 + });
  36 +
  37 + test('wl tp: BoxFit.fitHeight', () {
  38 + ctx.testScanWindow(
  39 + BoxFit.fitHeight,
  40 + const Rect.fromLTRB(0.0, 0.25, 1.0, 0.75),
  41 + );
  42 + });
  43 +
  44 + test('wl tp: BoxFit.fitWidth', () {
  45 + ctx.testScanWindow(
  46 + BoxFit.fitWidth,
  47 + const Rect.fromLTRB(
  48 + 0.25,
  49 + 0.38888888888888895,
  50 + 0.75,
  51 + 0.6111111111111112,
  52 + ),
  53 + );
  54 + });
  55 +
  56 + test('wl tp: BoxFit.cover', () {
  57 + // equal to fitWidth
  58 + ctx.testScanWindow(
  59 + BoxFit.cover,
  60 + const Rect.fromLTRB(
  61 + 0.25,
  62 + 0.38888888888888895,
  63 + 0.75,
  64 + 0.6111111111111112,
  65 + ),
  66 + );
  67 + });
  68 +
  69 + test('wl tp: BoxFit.contain', () {
  70 + // equal to fitHeigth
  71 + ctx.testScanWindow(
  72 + BoxFit.contain,
  73 + const Rect.fromLTRB(0.0, 0.25, 1.0, 0.75),
  74 + );
  75 + });
  76 +
  77 + test('wl tp: BoxFit.scaleDown', () {
  78 + // equal to fitHeigth, contain
  79 + ctx.testScanWindow(
  80 + BoxFit.scaleDown,
  81 + const Rect.fromLTRB(0.0, 0.25, 1.0, 0.75),
  82 + );
  83 + });
100 }); 84 });
101 85
102 - test('wl tl: BoxFit.fitHeight', () {  
103 - ctx.testScanWindow(  
104 - BoxFit.fitHeight,  
105 - const Rect.fromLTRB(0.0, 0.25, 1.0, 0.75), 86 + group('Widget (landscape) smaller than texture and texture (landscape)',
  87 + () {
  88 + const textureSize = Size(640.0, 480.0);
  89 + const widgetSize = Size(320.0, 120.0);
  90 + final ctx = ScanWindowTestContext(
  91 + textureSize: textureSize,
  92 + widgetSize: widgetSize,
  93 + scanWindow: Rect.fromLTWH(
  94 + widgetSize.width / 4,
  95 + widgetSize.height / 4,
  96 + widgetSize.width / 2,
  97 + widgetSize.height / 2,
  98 + ),
106 ); 99 );
107 - });  
108 100
109 - test('wl tl: BoxFit.fitWidth', () {  
110 - ctx.testScanWindow(  
111 - BoxFit.fitWidth,  
112 - const Rect.fromLTRB(0.25, 0.375, 0.75, 0.625),  
113 - ); 101 + test('wl tl: BoxFit.none', () {
  102 + ctx.testScanWindow(
  103 + BoxFit.none,
  104 + const Rect.fromLTRB(0.375, 0.4375, 0.625, 0.5625),
  105 + );
  106 + });
  107 +
  108 + test('wl tl: BoxFit.fill', () {
  109 + ctx.testScanWindow(
  110 + BoxFit.fill,
  111 + const Rect.fromLTRB(0.25, 0.25, 0.75, 0.75),
  112 + );
  113 + });
  114 +
  115 + test('wl tl: BoxFit.fitHeight', () {
  116 + ctx.testScanWindow(
  117 + BoxFit.fitHeight,
  118 + const Rect.fromLTRB(0.0, 0.25, 1.0, 0.75),
  119 + );
  120 + });
  121 +
  122 + test('wl tl: BoxFit.fitWidth', () {
  123 + ctx.testScanWindow(
  124 + BoxFit.fitWidth,
  125 + const Rect.fromLTRB(0.25, 0.375, 0.75, 0.625),
  126 + );
  127 + });
  128 +
  129 + test('wl tl: BoxFit.cover', () {
  130 + // equal to fitWidth
  131 + ctx.testScanWindow(
  132 + BoxFit.cover,
  133 + const Rect.fromLTRB(0.25, 0.375, 0.75, 0.625),
  134 + );
  135 + });
  136 +
  137 + test('wl tl: BoxFit.contain', () {
  138 + // equal to fitHeigth
  139 + ctx.testScanWindow(
  140 + BoxFit.contain,
  141 + const Rect.fromLTRB(0.0, 0.25, 1.0, 0.75),
  142 + );
  143 + });
  144 +
  145 + test('wl tl: BoxFit.scaleDown', () {
  146 + // equal to fitHeigth, contain
  147 + ctx.testScanWindow(
  148 + BoxFit.scaleDown,
  149 + const Rect.fromLTRB(0.0, 0.25, 1.0, 0.75),
  150 + );
  151 + });
114 }); 152 });
115 -  
116 - test('wl tl: BoxFit.cover', () {  
117 - // equal to fitWidth  
118 - ctx.testScanWindow(  
119 - BoxFit.cover,  
120 - const Rect.fromLTRB(0.25, 0.375, 0.75, 0.625),  
121 - );  
122 - });  
123 -  
124 - test('wl tl: BoxFit.contain', () {  
125 - // equal to fitHeigth  
126 - ctx.testScanWindow(  
127 - BoxFit.contain,  
128 - const Rect.fromLTRB(0.0, 0.25, 1.0, 0.75),  
129 - );  
130 - });  
131 -  
132 - test('wl tl: BoxFit.scaleDown', () {  
133 - // equal to fitHeigth, contain  
134 - ctx.testScanWindow(  
135 - BoxFit.scaleDown,  
136 - const Rect.fromLTRB(0.0, 0.25, 1.0, 0.75),  
137 - );  
138 - });  
139 - });  
140 - }); 153 + },
  154 + );
141 } 155 }
142 156
143 class ScanWindowTestContext { 157 class ScanWindowTestContext {