-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.dart
131 lines (123 loc) · 4.17 KB
/
main.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import 'package:add_to_google_wallet/widgets/add_to_google_wallet_button.dart';
import 'package:flutter/material.dart';
import 'package:uuid/uuid.dart';
void main() => runApp(const MaterialApp(home: MyApp()));
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(title: const Text('Plugin example app')),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
AddToGoogleWalletButton(
pass: _examplePass,
onError: (Object error) => _onError(context, error),
onSuccess: () => _onSuccess(context),
onCanceled: () => _onCanceled(context),
// Unsupported locale. Button will display English version.
locale: const Locale('und'),
),
const SizedBox(height: 8.0),
AddToGoogleWalletButton(
pass: _examplePass,
onError: (Object error) => _onError(context, error),
onSuccess: () => _onSuccess(context),
onCanceled: () => _onCanceled(context),
locale: const Locale.fromSubtags(
languageCode: 'fr',
countryCode: 'FR',
),
),
const SizedBox(height: 8.0),
AddToGoogleWalletButton(
pass: _examplePass,
onError: (Object error) => _onError(context, error),
onSuccess: () => _onSuccess(context),
onCanceled: () => _onCanceled(context),
),
],
),
),
);
void _onError(BuildContext context, Object error) => ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
backgroundColor: Colors.red,
content: Text(error.toString()),
),
);
void _onSuccess(BuildContext context) => ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
backgroundColor: Colors.green,
content: Text('Pass has been successfully added to the Google Wallet.'),
),
);
void _onCanceled(BuildContext context) => ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
backgroundColor: Colors.yellow,
content: Text('Adding a pass has been canceled.'),
),
);
}
final String _passId = const Uuid().v4();
const String _passClass = 'example';
const String _issuerId = '3333000000000000000';
const String _issuerEmail = 'example@example.com';
final String _examplePass = """
{
"iss": "$_issuerEmail",
"aud": "google",
"typ": "savetowallet",
"origins": [],
"payload": {
"genericObjects": [
{
"id": "$_issuerId.$_passId",
"classId": "$_issuerId.$_passClass",
"genericType": "GENERIC_TYPE_UNSPECIFIED",
"hexBackgroundColor": "#4285f4",
"logo": {
"sourceUri": {
"uri": "https://storage.googleapis.com/wallet-lab-tools-codelab-artifacts-public/pass_google_logo.jpg"
}
},
"cardTitle": {
"defaultValue": {
"language": "en",
"value": "Google I/O '22 [DEMO ONLY]"
}
},
"subheader": {
"defaultValue": {
"language": "en",
"value": "Attendee"
}
},
"header": {
"defaultValue": {
"language": "en",
"value": "Alex McJacobs"
}
},
"barcode": {
"type": "QR_CODE",
"value": "$_passId"
},
"heroImage": {
"sourceUri": {
"uri": "https://storage.googleapis.com/wallet-lab-tools-codelab-artifacts-public/google-io-hero-demo-only.jpg"
}
},
"textModulesData": [
{
"header": "POINTS",
"body": "1234",
"id": "points"
}
]
}
]
}
}
""";