mirror of
https://gitlab.com/TheOneWithTheBraid/dart_pkpass.git
synced 2025-07-06 05:18:47 +00:00
refactor: use binary barcode data by default
Signed-off-by: The one with the braid <info@braid.business>
This commit is contained in:
parent
3170c456e2
commit
0a32804cc6
2 changed files with 30 additions and 25 deletions
|
@ -23,11 +23,11 @@ class PassBarcode {
|
|||
/// - iso-8859-1: [Latin1Codec]
|
||||
/// - utf-8: [Utf8Codec]
|
||||
static Map<String, Encoding> supportedCodecs = {
|
||||
'iso-8859-1': Latin1Codec(),
|
||||
'iso-8859': Latin1Codec(),
|
||||
'iso8859': Latin1Codec(),
|
||||
'utf-8': Utf8Codec(),
|
||||
'utf8': Utf8Codec(),
|
||||
'iso-8859-1': latin1,
|
||||
'iso-8859': latin1,
|
||||
'iso8859': latin1,
|
||||
'utf-8': utf8,
|
||||
'utf8': utf8,
|
||||
};
|
||||
|
||||
static const _allowedFormats = {
|
||||
|
@ -46,10 +46,8 @@ class PassBarcode {
|
|||
/// representations.
|
||||
final BarcodeType format;
|
||||
|
||||
/// Message or payload to be displayed as a barcode.
|
||||
///
|
||||
/// Do not use directly, use the encoded [barcodeData] instead.
|
||||
final String message;
|
||||
/// Correctly encoded byte list to be displayed in the [barcode].
|
||||
final Uint8List barcodeData;
|
||||
|
||||
/// Text encoding that is used to convert the message from the string
|
||||
/// representation to a data representation to render the barcode.
|
||||
|
@ -68,22 +66,29 @@ class PassBarcode {
|
|||
/// of the barcode data in case the barcode doesn’t scan.
|
||||
final String? altText;
|
||||
|
||||
const PassBarcode({
|
||||
PassBarcode({
|
||||
required this.format,
|
||||
required this.message,
|
||||
required this.messageEncoding,
|
||||
@Deprecated('Use [barcodeData] instead') String? message,
|
||||
this.messageEncoding = utf8,
|
||||
Uint8List? barcodeData,
|
||||
required this.altText,
|
||||
});
|
||||
}) : barcodeData =
|
||||
Uint8List.fromList(barcodeData ?? messageEncoding.encode(message!));
|
||||
|
||||
factory PassBarcode.fromJson(Map<String, Object?> json) => PassBarcode(
|
||||
format: _allowedFormats[json['format']]!,
|
||||
message: json['message'] as String,
|
||||
messageEncoding:
|
||||
supportedCodecs[(json['messageEncoding'] as String).toLowerCase()]!,
|
||||
altText: json['altText'] as String?,
|
||||
);
|
||||
factory PassBarcode.fromJson(Map<String, Object?> json) {
|
||||
final messageEncoding =
|
||||
supportedCodecs[(json['messageEncoding'] as String).toLowerCase()]!;
|
||||
return PassBarcode(
|
||||
format: _allowedFormats[json['format']]!,
|
||||
barcodeData:
|
||||
Uint8List.fromList(messageEncoding.encode(json['message'] as String)),
|
||||
messageEncoding: messageEncoding,
|
||||
altText: json['altText'] as String?,
|
||||
);
|
||||
}
|
||||
|
||||
/// Correctly encoded byte list to be displayed in the [barcode].
|
||||
Uint8List get barcodeData =>
|
||||
Uint8List.fromList(messageEncoding.encode(message));
|
||||
/// Message or payload to be displayed as a barcode.
|
||||
///
|
||||
/// Do not use directly, use the encoded [barcodeData] instead.
|
||||
String get message => messageEncoding.decode(barcodeData);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue