Flutter Wallet Card 是一个插件,可让 iOS 和 Android 应用通过本地文件或网页 URL 生成 Apple Wallet 通行证和 Google Wallet 卡片。它简化了将数字钱包集成到 Flutter 应用程序的过程,使用户能够直接从应用中添加票券、登机牌、忠诚度卡等。该插件支持两个平台,并通过平台通道利用原生钱包 API。非常适合需要无缝数字钱包交互且设置简单的应用程序。
适合场景
将忠诚卡添加到 Apple Wallet
为旅行应用生成登机牌
为票务应用创建活动门票
启用数字礼品卡
支持健身应用中的会员卡
主要特点
支持 Apple Wallet 和 Google Wallet
从本地文件或URL生成通行凭证
跨平台(iOS 和 Android)
用于生成通行码的简单 API
安全的文件处理
平台通道集成
适合对象
旅行和活动应用
零售和忠诚度计划
健身和会员服务
数字票务系统
手机银行和支付应用
使用建议
需要正确的密钥文件格式
需要有效的证书以用于 Apple Wallet
Google Wallet 集成需要特定设置
限于支持的通行证类型
文件大小和格式限制适用
原始 README
以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。
Flutter Wallet Card
A comprehensive Flutter plugin for creating and managing wallet cards on both iOS (Apple Wallet) and Android (Google Wallet). This plugin provides a unified API for generating, adding, and managing wallet passes across platforms.
Features
Cross-Platform Support
iOS: Full Apple Wallet (Passkit) integration
Android: Google Wallet integration
Unified API: Single codebase for both platforms
Card Operations
✅ Check wallet availability
✅ Add cards to wallet
✅ Check if card is already added
✅ View cards in wallet
✅ Generate card files from data
✅ Parse existing card files
✅ Download cards from URLs
Card Types Supported
Generic Cards: General purpose cards
Boarding Passes: Flight tickets
Coupons: Discount and promotional cards
Event Tickets: Concert, sports, and event passes
Store Cards: Loyalty and membership cards
Advanced Features
🎨 Custom colors and styling
📍 Location-based relevance
📅 Date-based relevance
🔒 Secure certificate signing (iOS)
🌐 Network download support
🧪 Comprehensive test coverage
Installation
Add this to your package's pubspec.yaml file:
dependencies:flutter_wallet_card:^5.0.0
Then run:
flutter pub get
Platform Setup
iOS Setup
Enable Wallet capability in your iOS project:
Open ios/Runner.xcworkspace in Xcode
Select your target → Signing & Capabilities
Add "Wallet" capability
Configure your Apple Developer account:
Create a Pass Type ID in Apple Developer Console
Generate certificates for pass signing
Android Setup
Add Google Wallet API to your project:
Enable Google Wallet API in Google Cloud Console
Configure OAuth 2.0 credentials
Ensure your app uses play-services-pay (automatically included by the plugin):
// Generate a card file for sharing or storageFile cardFile = awaitFlutterWalletCard.generateCardFile(card);
print('Card file created at: ${cardFile.path}');
Adding Cards from URLs
// Download and add a card from a URLtry {
bool success = awaitFlutterWalletCard.addFromUrl(
'https://example.com/mycard.pkpass',
);
print('Card added: $success');
} catch (e) {
print('Failed to add card from URL: $e');
}
Parsing Existing Card Files
// Parse a wallet card from a local fileWalletCard card = awaitFlutterWalletCard.parseFromFile(File('/path/to/card.pkpass'));
print('Card title: ${card.metadata.title}');
Platform-Specific Features
// iOS: Add multiple cards at onceif (Platform.isIOS) {
List<WalletCard> cards = [card1, card2, card3];
bool success = awaitFlutterWalletCard.addMultipleToWallet(cards);
}
// Android: Save pass with JWTif (Platform.isAndroid) {
String jwt = 'your-google-wallet-jwt';
bool success = awaitFlutterWalletCard.savePassWithJwt(jwt);
// Create a pass linkString link = awaitFlutterWalletCard.createPassLink({
'objectId': 'your-object-id',
});
}