@@ -19,10 +19,15 @@ class MyApp extends StatefulWidget {
1919class _MyAppState extends State <MyApp > {
2020 final String _platformVersion = 'Unknown' ;
2121
22+ late Future <bool > _isWalletAvailable;
23+
2224 @override
2325 void initState () {
2426 super .initState ();
25- widget.flutterGoogleWalletPlugin.initWalletClient ();
27+ _isWalletAvailable = Future (() async {
28+ await widget.flutterGoogleWalletPlugin.initWalletClient ();
29+ return widget.flutterGoogleWalletPlugin.getWalletApiAvailabilityStatus ();
30+ });
2631 }
2732
2833 @override
@@ -38,21 +43,22 @@ class _MyAppState extends State<MyApp> {
3843 children: [
3944 Text ('Running on: $_platformVersion \n ' ),
4045 FutureBuilder <bool >(
41- future: widget.flutterGoogleWalletPlugin
42- .getWalletApiAvailabilityStatus (),
46+ future: _isWalletAvailable,
4347 builder: (BuildContext context, AsyncSnapshot <bool > available) {
44- if (available.data ?? false ) {
48+ if (available.data == true ) {
4549 return Padding (
4650 padding: const EdgeInsets .all (10 ),
4751 child: Align (
48- alignment: Alignment .topCenter,
49- child: AddToGoogleWalletButton (
50- locale: const Locale ('en' , 'US' ),
51- onPress: () {
52- widget.flutterGoogleWalletPlugin.savePasses (
53- jsonPass: '' ,
54- addToGoogleWalletRequestCode: 2 );
55- })),
52+ alignment: Alignment .topCenter,
53+ child: AddToGoogleWalletButton (
54+ locale: const Locale ('fr' , 'FR' ),
55+ onPress: () {
56+ widget.flutterGoogleWalletPlugin.savePasses (
57+ jsonPass: exampleJsonPass,
58+ addToGoogleWalletRequestCode: 2 );
59+ },
60+ ),
61+ ),
5662 );
5763 } else {
5864 return const SizedBox .shrink ();
@@ -66,3 +72,40 @@ class _MyAppState extends State<MyApp> {
6672 );
6773 }
6874}
75+
76+ // This is a pass with fake data, and it will trigger an error when added to Google Wallet
77+ // For a pass with real data, you must follow the Google developer guide here: https://developers.google.com/wallet
78+ const exampleJsonPass = '''
79+ {
80+ "aud": "google",
81+ "origins": [
82+ "https://localhost:8080"
83+ ],
84+ 85+ "iat": 123456789,
86+ "typ": "savetowallet",
87+ "payload": {
88+ "loyaltyObjects": [
89+ {
90+ "barcode": {
91+ "alternateText": "12345",
92+ "type": "qrCode",
93+ "value": "28343E3"
94+ },
95+ "id": "123456789.LoyaltyObject",
96+ "loyaltyPoints": {
97+ "balance": {
98+ "string": "500"
99+ },
100+ "label": "Points"
101+ },
102+ "accountId": "1234567890",
103+ "classId": "123456789.LoyaltyClass",
104+ "accountName": "Jane Doe",
105+ "state": "active",
106+ "version": 1
107+ }
108+ ]
109+ }
110+ }
111+ ''' ;
0 commit comments