Skip to content

sncf-connect-tech/flutter_google_wallet

Repository files navigation

flutter_google_wallet

A Flutter Google Wallet Plugin for tickets

pub package Test codecov License: MIT melos

Features

  • Enable and check if wallet is available
  • Add ticket or anything to wallet

Usage

Basic example

Create a FlutterGoogleWalletPlugin instance in your app.

final flutterGoogleWalletPlugin = FlutterGoogleWalletPlugin();

Then, call initWalletClient to create the Wallet instance on Android when you need it in your app.

flutterGoogleWalletPlugin.initWalletClient();

Before display the button, call getWalletApiAvailabilityStatus to know if the device has the wallet app.

FutureBuilder<bool>(
  future: flutterGoogleWalletPlugin.getWalletApiAvailabilityStatus(),

Finally, display the button and call savePasses to save ticket in GoogleWallet.

FutureBuilder<bool>(
  future: flutterGoogleWalletPlugin.getWalletApiAvailabilityStatus(),
  builder: (BuildContext context, AsyncSnapshot<bool> available) {
    if (available.data ?? false) {
      return AddToGoogleWalletButton(
        locale: Locale('en', 'US'),
        onPress: () {
          widget.flutterGoogleWalletPlugin.savePasses(
            jsonPass: '',
            addToGoogleWalletRequestCode: 2);
        });
    } else {
      return const SizedBox.shrink();
    }
  },
),

Also add the google wallet button svg to your pubspec assets

  assets:
    - packages/flutter_google_wallet/assets/svg/button/frFR_add_to_google_wallet_wallet-button.svg
    - packages/flutter_google_wallet/assets/svg/button/enUS_add_to_google_wallet_wallet-button.svg

And add the wallet localization to your MaterialApp

  localizationsDelegates: const [
    I18nGoogleWallet.delegate,
  ],

Contribute

To maintain this repository, please first install melos & bootstrap in root directory of the project :

dart pub global activate melos
melos bs