diff --git a/CHANGELOG.md b/CHANGELOG.md index 458201f..fbff0df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## v2.0.2 + +- refactor: use binary barcode data by default (The one with the braid) + ## v1.3.0 - chore: add funding (The one with the braid) diff --git a/lib/pkpass/models/barcode.dart b/lib/pkpass/models/barcode.dart index 37d3e19..83bc06a 100644 --- a/lib/pkpass/models/barcode.dart +++ b/lib/pkpass/models/barcode.dart @@ -23,11 +23,11 @@ class PassBarcode { /// - iso-8859-1: [Latin1Codec] /// - utf-8: [Utf8Codec] static Map 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 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 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); } diff --git a/pubspec.yaml b/pubspec.yaml index 21aa127..44c5a9f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: pkpass description: A Dart native pkpass parsing library supporting checksum verification, barcode parsing, localization and much more. -version: 1.3.0 +version: 2.0.0 repository: https://gitlab.com/TheOneWithTheBraid/dart_pkpass.git homepage: https://gitlab.com/TheOneWithTheBraid/dart_pkpass issue_tracker: https://gitlab.com/TheOneWithTheBraid/dart_pkpass/-/issues @@ -15,9 +15,9 @@ dependencies: barcode: ^2.2.4 crypto: ^3.0.3 http: ^1.0.0 - intl: ^0.18.1 + intl: ^0.19.0 dev_dependencies: import_sorter: ^4.6.0 - lints: ">= 2.0.0 < 4.0.0" + lints: ">=2.0.0 <4.0.0" test: ^1.21.0