Barcode.fromNative constructor
Creates a new Barcode instance from the given data.
Implementation
factory Barcode.fromNative(Map<Object?, Object?> data) {
final calendarEvent = data['calendarEvent'] as Map<Object?, Object?>?;
final contactInfo = data['contactInfo'] as Map<Object?, Object?>?;
final corners = data['corners'] as List<Object?>?;
final driverLicense = data['driverLicense'] as Map<Object?, Object?>?;
final email = data['email'] as Map<Object?, Object?>?;
final geoPoint = data['geoPoint'] as Map<Object?, Object?>?;
final phone = data['phone'] as Map<Object?, Object?>?;
final sms = data['sms'] as Map<Object?, Object?>?;
final size = data['size'] as Map<Object?, Object?>?;
final url = data['url'] as Map<Object?, Object?>?;
final wifi = data['wifi'] as Map<Object?, Object?>?;
final barcodeWidth = size?['width'] as double?;
final barcodeHeight = size?['height'] as double?;
final rawBytesData = data['rawBytes'] as Uint8List?;
final rawPayloadData = data['rawPayloadData'] as Uint8List?;
final BarcodeBytes? rawDecodedBytes;
if (rawPayloadData != null) {
rawDecodedBytes = DecodedVisionBarcodeBytes(
bytes: rawBytesData,
rawBytes: rawPayloadData,
);
} else if (rawBytesData != null) {
rawDecodedBytes = DecodedBarcodeBytes(bytes: rawBytesData);
} else {
rawDecodedBytes = null;
}
return Barcode(
calendarEvent:
calendarEvent == null
? null
: CalendarEvent.fromNative(calendarEvent),
contactInfo:
contactInfo == null ? null : ContactInfo.fromNative(contactInfo),
corners:
corners == null
? const <Offset>[]
: List.unmodifiable(
corners.cast<Map<Object?, Object?>>().map((
e,
) {
final x = e['x']! as double;
final y = e['y']! as double;
return Offset(x, y);
}),
),
displayValue: data['displayValue'] as String?,
driverLicense:
driverLicense == null
? null
: DriverLicense.fromNative(driverLicense),
email: email == null ? null : Email.fromNative(email),
format: BarcodeFormat.fromRawValue(data['format'] as int? ?? -1),
geoPoint: geoPoint == null ? null : GeoPoint.fromNative(geoPoint),
phone: phone == null ? null : Phone.fromNative(phone),
// Populate deprecated rawBytes for backward compatibility.
// ignore: deprecated_member_use_from_same_package
rawBytes: rawBytesData,
rawDecodedBytes: rawDecodedBytes,
rawValue: data['rawValue'] as String?,
size:
barcodeWidth == null || barcodeHeight == null
? Size.zero
: Size(barcodeWidth, barcodeHeight),
sms: sms == null ? null : SMS.fromNative(sms),
type: BarcodeType.fromRawValue(data['type'] as int? ?? 0),
url: url == null ? null : UrlBookmark.fromNative(url),
wifi: wifi == null ? null : WiFi.fromNative(wifi),
);
}