entryready_wallet 0.2.0
entryready_wallet: ^0.2.0 copied to clipboard
Add EntryReady mobile keys to Apple Wallet and Google Wallet. Presents the platform's provisioning flow and reports what is already in the wallet.
example/example.dart
// Illustrative example for entryready_wallet.
//
// This shows the shape of the package's calls and nothing else. The two pieces of data it takes —
// the reference identifiers and the prepared credentials — come from the EntryReady API, which
// your application calls itself. That integration is documented in the EntryReady developer
// portal; contact support@entryready.com for access.
//
// Everything below uses placeholders in their place.
import 'dart:typed_data';
import 'package:entryready_wallet/entryready_wallet.dart';
import 'package:flutter/material.dart';
const wallet = EntryReadyWallet();
class RoomKeySection extends StatefulWidget {
const RoomKeySection({super.key});
@override
State<RoomKeySection> createState() => _RoomKeySectionState();
}
class _RoomKeySectionState extends State<RoomKeySection> {
WalletKeyStatus _status = WalletKeyStatus.notProvisioned;
@override
void initState() {
super.initState();
_refresh();
}
Future<void> _refresh() async {
// Your application supplies these. They are the `referenceIdentifier` of each of the key's
// wallet-provisioning events.
const referenceIdentifiers = <String>{'REFERENCE-IDENTIFIER-FROM-YOUR-BACKEND'};
final status = await wallet.keyStatus(
referenceIdentifiers: referenceIdentifiers,
);
if (!mounted) return;
setState(() => _status = status);
}
Future<void> _addToWallet() async {
// Your application supplies these three, per attempt. They are single-use.
final credentials = PassCredentials(
provisioningCredentialIdentifier: 'FROM-YOUR-BACKEND',
sharingInstanceIdentifier: 'FROM-YOUR-BACKEND',
cardTemplateIdentifier: 'FROM-YOUR-BACKEND',
);
try {
await wallet.addKey(
credentials: credentials,
preview: PassPreview(
thumbnail: Uint8List(0), // PNG or JPEG bytes for your key artwork.
description: 'Room key',
),
);
await _refresh(); // Reflect the newly added pass.
} on WalletException catch (error) {
if (error.isCancellation) return; // User dismissed the sheet; not a failure.
if (error.code == WalletErrorCode.cannotAddPass) {
// Usually the Wallet Access Key entitlement, which fails silently everywhere else.
debugPrint((await wallet.diagnose()).summary);
}
}
}
@override
Widget build(BuildContext context) {
final note = _status.note;
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Apple's rule: offer the button until the pass is on both this device and a paired one.
if (_status.shouldOfferButton)
AddToAppleWalletButton(onPressed: _addToWallet)
else
const Text('Already in Apple Wallet'),
// Set when the pass is on one device but not the other.
if (note != null) Padding(padding: const EdgeInsets.only(top: 8), child: Text(note)),
],
);
}
}