Skip to content

Commit

Permalink
chore(passkit, passkit_ui): Move barcode visualization to UI (#64)
Browse files Browse the repository at this point in the history
* Change barcode

* adapt passkit_ui accordingly

* adapt readme and changelog
  • Loading branch information
ueman authored Jul 7, 2024
1 parent 273f057 commit 2fb4af9
Show file tree
Hide file tree
Showing 16 changed files with 79 additions and 89 deletions.
4 changes: 2 additions & 2 deletions app/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -683,14 +683,14 @@ packages:
path: "../passkit"
relative: true
source: path
version: "0.0.2"
version: "0.0.4"
passkit_ui:
dependency: "direct main"
description:
path: "../passkit_ui"
relative: true
source: path
version: "0.0.1"
version: "0.0.3"
path:
dependency: "direct main"
description:
Expand Down
3 changes: 3 additions & 0 deletions passkit/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
- Add checksum verification (signature verification is still missing)
- Change `webServiceUrl` from `String?` to `Uri?`. This is a breaking change
- Fix building URLs for the PassKit web service
- Remove `formatType` from `Barcode`. `Barcode.format` is an enum instead.
- This is a breaking change
- Also drop the dependency on `package:barcode`

## 0.0.3

Expand Down
36 changes: 15 additions & 21 deletions passkit/lib/src/order/order_barcode.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:barcode/barcode.dart' as barcode;
import 'package:json_annotation/json_annotation.dart';

part 'order_barcode.g.dart';
Expand Down Expand Up @@ -28,26 +27,7 @@ class OrderBarcode {
/// (Required) The format of the barcode.
/// Possible Values: qr, pdf417, aztec, code128
@JsonKey(name: 'format')
final String format;

barcode.Barcode get formatType {
if (format == 'qr') {
return barcode.Barcode.qrCode(
errorCorrectLevel: barcode.BarcodeQRCorrectionLevel.high,
);
}
if (format == 'pdf417') {
return barcode.Barcode.pdf417();
}
if (format == 'aztec') {
return barcode.Barcode.aztec();
}
if (format == 'code128') {
return barcode.Barcode.code128();
}

throw UnsupportedError('$format is not supported for barcodes in PKPASS');
}
final OrderBarcodeType format;

/// The contents of the barcode.
@JsonKey(name: 'message')
Expand All @@ -58,3 +38,17 @@ class OrderBarcode {
@JsonKey(name: 'messageEncoding')
final String messageEncoding;
}

enum OrderBarcodeType {
@JsonValue('qr')
qr,

@JsonValue('pdf417')
pdf417,

@JsonValue('aztec')
aztec,

@JsonValue('code128')
code128,
}
11 changes: 9 additions & 2 deletions passkit/lib/src/order/order_barcode.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 15 additions & 21 deletions passkit/lib/src/pkpass/barcode.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:json_annotation/json_annotation.dart';
import 'package:barcode/barcode.dart' as barcode;

part 'barcode.g.dart';

Expand All @@ -25,26 +24,7 @@ class Barcode {
/// following values: PKBarcodeFormatQR, PKBarcodeFormatPDF417, or
/// PKBarcodeFormatAztec. For dictionaries in the barcodes array, you may also
/// use PKBarcodeFormatCode128.
final String format;

barcode.Barcode get formatType {
if (format == 'PKBarcodeFormatQR') {
return barcode.Barcode.qrCode(
errorCorrectLevel: barcode.BarcodeQRCorrectionLevel.high,
);
}
if (format == 'PKBarcodeFormatPDF417') {
return barcode.Barcode.pdf417();
}
if (format == 'PKBarcodeFormatAztec') {
return barcode.Barcode.aztec();
}
if (format == 'PKBarcodeFormatCode128') {
return barcode.Barcode.code128();
}

throw UnsupportedError('$format is not supported for barcodes in PKPASS');
}
final PkPassBarcodeType format;

/// Required. Message or payload to be displayed as a barcode.
final String message;
Expand All @@ -59,3 +39,17 @@ class Barcode {
/// Converts this instance to a JSON object
Map<String, dynamic> toJson() => _$BarcodeToJson(this);
}

enum PkPassBarcodeType {
@JsonValue('PKBarcodeFormatQR')
qr,

@JsonValue('PKBarcodeFormatPDF417')
pdf417,

@JsonValue('PKBarcodeFormatAztec')
aztec,

@JsonValue('PKBarcodeFormatCode128')
code128,
}
11 changes: 9 additions & 2 deletions passkit/lib/src/pkpass/barcode.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion passkit/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ environment:

dependencies:
archive: ^3.6.0
barcode: ^2.2.0
crypto: ^3.0.0
csslib: ^1.0.0
http: ^1.2.0
Expand Down
2 changes: 2 additions & 0 deletions passkit_ui/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## 0.0.3

- Update to `passkit: ^0.0.4`

## 0.0.2

- Update to `passkit: ^0.0.2`
Expand Down
27 changes: 1 addition & 26 deletions passkit_ui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
[![GitHub followers](https://img.shields.io/github/followers/ueman?style=social)](https://github.com/ueman)

> 🚧 API is subject to change! 🚧
> Not all pass types are yet supported. Not ready for production use.
> All passkit types can be shown, but might not look perfect.
## What is PassKit?

Expand Down Expand Up @@ -76,28 +76,3 @@ Contribute to this library, and you'll show up too.
We encourage you to contribute to this library.
A good starting point is to look at these [good first issues](https://github.com/ueman/passkit/issues?q=is%3Aopen+is%3Aissue+label%3A%22package%3A+passkit_ui%22+label%3A%22good+first+issue%22). Take a look at [these issues](https://github.com/ueman/passkit/issues?q=is%3Aopen+is%3Aissue+label%3A%22package%3A+passkit_ui%22)
if you're up for a challenge.
# Development related docs
Design docs:
- https://developer.apple.com/design/human-interface-guidelines/wallet
- https://developer.apple.com/library/archive/documentation/UserExperience/Conceptual/PassKit_PG/Creating.html#//apple_ref/doc/uid/TP40012195-CH4-SW1
## Image docs
Taken from [here](https://developer.apple.com/library/archive/documentation/UserExperience/Conceptual/PassKit_PG/Creating.html#//apple_ref/doc/uid/TP40012195-CH4-SW1).
# Images Fill Their Allotted Space
The pass layout allots a certain area on the front of the pass for each image. Images are scaled (preserving aspect ratio) to fill this allotted space. Images with a different aspect ratio than their allotted space are cropped after being scaled. The space allotted is as follows:
- The background image (`background.png`) is displayed behind the entire front of the pass. The expected dimensions are 180 x 220 points. The image is cropped slightly on all sides and blurred. Depending on the image, you can often provide an image at a smaller size and let it be scaled up, because the blur effect hides details. This lets you reduce the file size without a noticeable difference in the pass.
- The footer image (`footer.png`) is displayed near the barcode. The allotted space is 286 x 15 points.
- The icon (`icon.png`) is displayed when a pass is shown on the lock screen and by apps such as Mail when showing a pass attached to an email. The icon should measure 29 x 29 points.
- The logo image (`logo.png`) is displayed in the top left corner of the pass, next to the logo text. The allotted space is 160 x 50 points; in most cases it should be narrower.
- The strip image (`strip.png`) is displayed behind the primary fields.
- **On iPhone 6 and 6 Plus** The allotted space is 375 x 98 points for event tickets, 375 x 144 points for gift cards and coupons, and 375 x 123 in all other cases.
- **On prior hardware** The allotted space is 320 x 84 points for event tickets, 320 x 110 points for other pass styles with a square barcode on devices with 3.5 inch screens, and 320 x 123 in all other cases.
- The thumbnail image (`thumbnail.png`) displayed next to the fields on the front of the pass. The allotted space is 90 x 90 points. The aspect ratio should be in the range of 2:3 to 3:2, otherwise the image is cropped.

> [!NOTE ]The dimensions given above are all in points. On a non-Retina display, each point equals exactly 1 pixel. On a Retina display, there are 2 or 3 pixels per point, depending on the device. To support all screen sizes and resolutions, provide the original, @2x, and @3x versions of your art.
4 changes: 2 additions & 2 deletions passkit_ui/lib/src/boarding_pass.dart
Original file line number Diff line number Diff line change
Expand Up @@ -219,15 +219,15 @@ class _AuxiliaryRow extends StatelessWidget {
fontSize: 10,
fontWeight: FontWeight.w600,
),
textAlign: item.textAlignment?.toFlutterTextAlign(),
textAlign: item.textAlignment.toFlutterTextAlign(),
),
Text(
item.value.toString(),
style: passTheme.foregroundTextStyle.copyWith(
fontSize: 16,
height: 0.9,
),
textAlign: item.textAlignment?.toFlutterTextAlign(),
textAlign: item.textAlignment.toFlutterTextAlign(),
),
],
),
Expand Down
4 changes: 2 additions & 2 deletions passkit_ui/lib/src/coupon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,12 @@ class _AuxiliaryRow extends StatelessWidget {
Text(
item.label ?? '',
style: passTheme.labelTextStyle,
textAlign: item.textAlignment?.toFlutterTextAlign(),
textAlign: item.textAlignment.toFlutterTextAlign(),
),
Text(
item.value.toString(),
style: passTheme.foregroundTextStyle,
textAlign: item.textAlignment?.toFlutterTextAlign(),
textAlign: item.textAlignment.toFlutterTextAlign(),
),
],
);
Expand Down
4 changes: 2 additions & 2 deletions passkit_ui/lib/src/event_ticket.dart
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,12 @@ class _AuxiliaryRow extends StatelessWidget {
Text(
item.label ?? '',
style: passTheme.labelTextStyle,
textAlign: item.textAlignment?.toFlutterTextAlign(),
textAlign: item.textAlignment.toFlutterTextAlign(),
),
Text(
item.value.toString(),
style: passTheme.foregroundTextStyle,
textAlign: item.textAlignment?.toFlutterTextAlign(),
textAlign: item.textAlignment.toFlutterTextAlign(),
),
],
);
Expand Down
4 changes: 2 additions & 2 deletions passkit_ui/lib/src/generic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,12 @@ class _AuxiliaryRow extends StatelessWidget {
Text(
item.label ?? '',
style: passTheme.labelTextStyle,
textAlign: item.textAlignment?.toFlutterTextAlign(),
textAlign: item.textAlignment.toFlutterTextAlign(),
),
Text(
item.value.toString(),
style: passTheme.foregroundTextStyle,
textAlign: item.textAlignment?.toFlutterTextAlign(),
textAlign: item.textAlignment.toFlutterTextAlign(),
),
],
);
Expand Down
4 changes: 2 additions & 2 deletions passkit_ui/lib/src/store_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,12 @@ class _AuxiliaryRow extends StatelessWidget {
Text(
item.label ?? '',
style: passTheme.labelTextStyle,
textAlign: item.textAlignment?.toFlutterTextAlign(),
textAlign: item.textAlignment.toFlutterTextAlign(),
),
Text(
item.value.toString(),
style: passTheme.foregroundTextStyle,
textAlign: item.textAlignment?.toFlutterTextAlign(),
textAlign: item.textAlignment.toFlutterTextAlign(),
),
],
);
Expand Down
15 changes: 12 additions & 3 deletions passkit_ui/lib/src/widgets/passkit_barcode.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ class PasskitBarcode extends StatelessWidget {
Widget build(BuildContext context) {
double? height;
double? width;
if ({
'PKBarcodeFormatQR', /* 'PKBarcodeFormatAztec' */
}.contains(barcode.format)) {
if (barcode.format == passkit.PkPassBarcodeType.qr) {
// These two formats are quadratic, meaning they have the same height and width.
height = 150;
width = 150;
Expand Down Expand Up @@ -70,3 +68,14 @@ class PasskitBarcode extends StatelessWidget {
);
}
}

extension on passkit.Barcode {
Barcode get formatType {
return switch (format) {
passkit.PkPassBarcodeType.qr => Barcode.qrCode(),
passkit.PkPassBarcodeType.pdf417 => Barcode.pdf417(),
passkit.PkPassBarcodeType.aztec => Barcode.aztec(),
passkit.PkPassBarcodeType.code128 => Barcode.code128(),
};
}
}
2 changes: 1 addition & 1 deletion passkit_ui/test/src/widgets/passkit_barcode_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void main() {
PasskitBarcode(
barcode: pk.Barcode(
message: '1234567890',
format: 'PKBarcodeFormatQR',
format: pk.PkPassBarcodeType.qr,
messageEncoding: 'utf-8',
altText: altText,
),
Expand Down

0 comments on commit 2fb4af9

Please sign in to comment.