barcode_utility.dart
4.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
import 'dart:math' as math;
import 'package:flutter/material.dart';
import 'package:mobile_scanner/mobile_scanner.dart';
import 'package:mobile_scanner/src/objects/geo_point.dart';
Size toSize(Map data) {
final width = data['width'] as double;
final height = data['height'] as double;
return Size(width, height);
}
List<Offset>? toCorners(List<Map<Object?, Object?>>? data) {
if (data == null) {
return null;
}
return List.unmodifiable(
data.map((Map<Object?, Object?> e) {
return Offset(e['x']! as double, e['y']! as double);
}),
);
}
BarcodeFormat toFormat(int value) {
switch (value) {
case 0:
return BarcodeFormat.all;
case 1:
return BarcodeFormat.code128;
case 2:
return BarcodeFormat.code39;
case 4:
return BarcodeFormat.code93;
case 8:
return BarcodeFormat.codebar;
case 16:
return BarcodeFormat.dataMatrix;
case 32:
return BarcodeFormat.ean13;
case 64:
return BarcodeFormat.ean8;
case 128:
return BarcodeFormat.itf;
case 256:
return BarcodeFormat.qrCode;
case 512:
return BarcodeFormat.upcA;
case 1024:
return BarcodeFormat.upcE;
case 2048:
return BarcodeFormat.pdf417;
case 4096:
return BarcodeFormat.aztec;
default:
return BarcodeFormat.unknown;
}
}
CalendarEvent? toCalendarEvent(Map? data) {
if (data != null) {
return CalendarEvent.fromNative(data);
} else {
return null;
}
}
DateTime? toDateTime(Map<String, dynamic>? data) {
if (data != null) {
final year = data['year'] as int;
final month = data['month'] as int;
final day = data['day'] as int;
final hour = data['hours'] as int;
final minute = data['minutes'] as int;
final second = data['seconds'] as int;
return data['isUtc'] as bool
? DateTime.utc(year, month, day, hour, minute, second)
: DateTime(year, month, day, hour, minute, second);
} else {
return null;
}
}
ContactInfo? toContactInfo(Map? data) {
if (data != null) {
return ContactInfo.fromNative(data);
} else {
return null;
}
}
PersonName? toName(Map? data) {
if (data != null) {
return PersonName.fromNative(data);
} else {
return null;
}
}
DriverLicense? toDriverLicense(Map? data) {
if (data != null) {
return DriverLicense.fromNative(data);
} else {
return null;
}
}
Email? toEmail(Map? data) {
if (data != null) {
return Email.fromNative(data);
} else {
return null;
}
}
GeoPoint? toGeoPoint(Map? data) {
if (data != null) {
return GeoPoint.fromNative(data);
} else {
return null;
}
}
Phone? toPhone(Map? data) {
if (data != null) {
return Phone.fromNative(data);
} else {
return null;
}
}
SMS? toSMS(Map? data) {
if (data != null) {
return SMS.fromNative(data);
} else {
return null;
}
}
UrlBookmark? toUrl(Map? data) {
if (data != null) {
return UrlBookmark.fromNative(data);
} else {
return null;
}
}
WiFi? toWiFi(Map? data) {
if (data != null) {
return WiFi.fromNative(data);
} else {
return null;
}
}
Size applyBoxFit(BoxFit fit, Size input, Size output) {
if (input.height <= 0.0 ||
input.width <= 0.0 ||
output.height <= 0.0 ||
output.width <= 0.0) {
return Size.zero;
}
Size destination;
final inputAspectRatio = input.width / input.height;
final outputAspectRatio = output.width / output.height;
switch (fit) {
case BoxFit.fill:
destination = output;
break;
case BoxFit.contain:
if (outputAspectRatio > inputAspectRatio) {
destination = Size(
input.width * output.height / input.height,
output.height,
);
} else {
destination = Size(
output.width,
input.height * output.width / input.width,
);
}
break;
case BoxFit.cover:
if (outputAspectRatio > inputAspectRatio) {
destination = Size(
output.width,
input.height * (output.width / input.width),
);
} else {
destination = Size(
input.width * (output.height / input.height),
output.height,
);
}
break;
case BoxFit.fitWidth:
destination = Size(
output.width,
input.height * (output.width / input.width),
);
break;
case BoxFit.fitHeight:
destination = Size(
input.width * (output.height / input.height),
output.height,
);
break;
case BoxFit.none:
destination = Size(
math.min(input.width, output.width),
math.min(input.height, output.height),
);
break;
case BoxFit.scaleDown:
destination = input;
if (destination.height > output.height) {
destination = Size(output.height * inputAspectRatio, output.height);
}
if (destination.width > output.width) {
destination = Size(output.width, output.width / inputAspectRatio);
}
break;
}
return destination;
}