voucher_sdk

voucher_sdk is a Flutter SDK that allows host applications to integrate and display the voucher experience. You can open the complete voucher experience or navigate directly to a specific SKU.

Features

  • Initialize the SDK with user details and client credentials.
  • Open the complete voucher experience.
  • Open a specific voucher using its SKU ID.
  • Integrate Firebase Analytics through a custom VoucherAnalytics implementation.
  • Check whether the SDK is currently open.

Getting started

Add the SDK dependency to your application's pubspec.yaml:

dependencies:
  voucher_sdk: ^YOUR_VERSION

Replace YOUR_VERSION with the version you want to integrate.

Import the SDK using its public entry point:

import 'package:voucher_sdk/voucher_sdk.dart';

Ensure that the public import path matches your package's actual entry point.

Usage

1. Initialize the SDK

Initialize the SDK before opening it. Pass your navigator key, client credentials, and user details.

await VoucherSdk.initialize(
  navigatorKey: navigatorKey,
  clientId: "YOUR_CLIENT_ID",
  secret: "YOUR_CLIENT_SECRET",
  name: "John Doe",
  mobile: "9876543210",
  email: "john@example.com",
  clientConsumerId: "USER_123",
);

Initialization parameters

Initialization parameters

Parameter Required Description
navigatorKey Yes Navigator key from the host application.
clientId Yes Client ID provided for the integration.
secret Yes Client secret provided for the integration.
name Yes Full name of the user.
clientConsumerId Yes Unique user identifier from the host application.
mobile Conditional User's mobile number. Provide either mobile or email; at least one is required.
email Conditional User's email address. Provide either email or mobile; at least one is required.
analytics No Optional implementation of VoucherAnalytics.

Note: You must provide at least one of mobile or email when initializing the SDK. Both can be provided, but neither can be omitted at the same time.

2. Open the complete voucher experience

Call VoucherSdk.open() without parameters to open the default voucher experience.

await VoucherSdk.open();

3. Open a specific SKU

Pass the SKU ID to open a particular voucher.

const String skuId = "YOUR_SKU_ID";

await VoucherSdk.open(sku: skuId);

The sku parameter is optional and defaults to an empty string. If omitted, the SDK opens the default voucher experience.

Analytics integration

The Voucher SDK supports custom analytics through the VoucherAnalytics interface.

If you want to use Firebase Analytics, you must integrate and initialize Firebase in your host application. The host application must implement VoucherAnalytics and pass an instance to VoucherSdk.initialize().

1. Add Firebase dependencies

Add Firebase Core and Firebase Analytics to your host application's pubspec.yaml:

dependencies:
  firebase_core: ^LATEST_VERSION
  firebase_analytics: ^LATEST_VERSION

Replace LATEST_VERSION with compatible versions for your project.

Configure Firebase by following the official FlutterFire setup guide.

2. Create the analytics provider

Create a file named voucher_analytics_provider.dart in your host application.

Implement the VoucherAnalytics interface:

import 'package:firebase_analytics/firebase_analytics.dart';
import 'package:voucher_sdk/app/analytics/voucher_analytics.dart';

class VoucherAnalyticsProvider extends VoucherAnalytics {
  static FirebaseAnalytics? firebaseAnalytics;

  @override
  Future<void> logEvent({
    required String eventName,
    Map<String, Object>? parameters,
  }) async {
    await firebaseAnalytics?.logEvent(
      name: eventName,
      parameters: parameters,
    );
  }

  @override
  Future<void> logPurchase({
    Map<String, Object>? parameters,
  }) async {
    final rawItems = parameters?['items'];
    final analyticsItems = <AnalyticsEventItem>[];

    if (rawItems is List) {
      for (final item in rawItems) {
        if (item is Map) {
          analyticsItems.add(
            AnalyticsEventItem(
              itemId: item['sku']?.toString(),
              itemName: item['productName']?.toString(),
              quantity: item['quantity'] is num
                  ? (item['quantity'] as num).toInt()
                  : int.tryParse(
                      item['quantity']?.toString() ?? '',
                    ),
            ),
          );
        }
      }
    }

    await firebaseAnalytics?.logPurchase(
      items: analyticsItems,
    );
  }
}

This implementation forwards SDK analytics events to Firebase Analytics. Purchase events convert the SDK's item data into Firebase AnalyticsEventItem objects.

3. Initialize Firebase in the host application

Initialize Firebase before initializing the Voucher SDK.

import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_analytics/firebase_analytics.dart';

import 'firebase_options.dart';
import 'voucher_analytics_provider.dart';

Future<void> initializeFirebaseAnalytics() async {
  await Firebase.initializeApp(
    options: DefaultFirebaseOptions.currentPlatform,
  );

  VoucherAnalyticsProvider.firebaseAnalytics =
      FirebaseAnalytics.instance;
}

Ensure firebase_options.dart is generated and configured for your host application's Firebase project. If your app already initializes Firebase, do not initialize it again unnecessarily; set the analytics instance instead.

4. Pass the analytics provider to the Voucher SDK

After Firebase initialization, pass a VoucherAnalyticsProvider instance through the analytics parameter.

await VoucherSdk.initialize(
  navigatorKey: navigatorKey,
  clientId: "YOUR_CLIENT_ID",
  secret: "YOUR_CLIENT_SECRET",
  name: "John Doe",
  mobile: "9876543210",
  email: "john@example.com",
  clientConsumerId: "USER_123",
  analytics: VoucherAnalyticsProvider(),
);

If analytics is not required, you can omit the analytics parameter.

Important: Firebase initialization and configuration are the responsibility of the host application. The Voucher SDK does not initialize Firebase itself.

Check SDK state

Use VoucherSdk.isOpen to check whether the SDK is currently open.

if (VoucherSdk.isOpen) {
  // The SDK is currently open.
}

The SDK prevents opening another SDK screen while one is already open.

Additional information

  • Always initialize the SDK before calling VoucherSdk.open().
  • Use VoucherSdk.open() to open the default voucher experience.
  • Use VoucherSdk.open(sku: skuId) to open a specific SKU.
  • Ensure the supplied navigator key is attached to the host application's navigator.
  • Initialize Firebase in the host application before using Firebase Analytics through the SDK.
  • Pass an instance of VoucherAnalyticsProvider to the analytics parameter when analytics is required.
  • Keep client credentials secure and avoid committing production secrets to source control.

For integration support or to report an issue, contact the SDK development team.

Libraries

app/analytics/voucher_analytics
app/analytics/voucher_analytics_event
app/analytics/voucher_analytics_impl
app/app
app/bloc/app_bloc
app/bloc/app_event
app/bloc/app_state
app/config/app_config
app/config/env
app/config/release_env
app/data/models/dto/bottomsheet_data_dto
app/data/models/dto/payment_request
app/data/models/dto/payment_sdk_response
app/data/models/dto/response
app/data/models/dto/user_model
app/data/models/response/notification_data_response
app/data/network/network_requester
app/data/repository/app_repository_impl
app/data/values/animation
app/data/values/constants
app/data/values/images
app/data/values/strings
app/data/values/urls
app/domain/app_repository
app/modules/checkout/data/models/initiate_payment_response
app/modules/checkout/data/models/patch_payment_response
app/modules/checkout/data/repository/checkout_repository_impl
app/modules/checkout/domain/checkout_repository
app/modules/checkout/presentation/bloc/checkout_bloc
app/modules/checkout/presentation/bloc/checkout_event
app/modules/checkout/presentation/bloc/checkout_state
app/modules/checkout/presentation/views/checkout_view
app/modules/checkout/presentation/views/widgets/cart_item_widget
app/modules/help_center/data/models/chat_response
app/modules/help_center/data/models/complaint_list_response
app/modules/help_center/data/models/upload_document_resposnse
app/modules/help_center/data/repository/help_center_repository_impl
app/modules/help_center/domain/help_center_repository
app/modules/help_center/presentation/bloc/help_center_bloc
app/modules/help_center/presentation/bloc/help_center_event
app/modules/help_center/presentation/bloc/help_center_state
app/modules/help_center/presentation/views/all_ticket_view
app/modules/help_center/presentation/views/chat_support_view
app/modules/help_center/presentation/views/document_view
app/modules/help_center/presentation/views/help_center_view
app/modules/help_center/presentation/views/widgets/chat_tile_widget
app/modules/help_center/presentation/views/widgets/document_chat_tile_widget
app/modules/help_center/presentation/views/widgets/faq_widget
app/modules/help_center/presentation/views/widgets/help_header_widget
app/modules/help_center/presentation/views/widgets/input_query_widget
app/modules/help_center/presentation/views/widgets/order_selection_widget
app/modules/help_center/presentation/views/widgets/ticket_tile_widget
app/modules/offer/data/models/add_item_request
app/modules/offer/data/models/address_detail_response
app/modules/offer/data/models/apply_coupon_response
app/modules/offer/data/models/cart_response
app/modules/offer/data/models/consumer_detail_response
app/modules/offer/data/models/coupon_brand_list_response
app/modules/offer/data/models/coupon_category_name_response
app/modules/offer/data/models/coupon_detail_response
app/modules/offer/data/models/coupon_list_response
app/modules/offer/data/models/coupon_stats_response
app/modules/offer/data/models/coupon_status_response
app/modules/offer/data/models/kredcoin_redeem_response
app/modules/offer/data/models/my_coupon_detail_response
app/modules/offer/data/models/my_coupon_list_response
app/modules/offer/data/models/my_coupon_response
app/modules/offer/data/models/offer_response
app/modules/offer/data/models/order_status_response
app/modules/offer/data/repository/offer_repository_impl
app/modules/offer/domain/offer_repository
app/modules/offer/presentation/bloc/offer_bloc
app/modules/offer/presentation/bloc/offer_event
app/modules/offer/presentation/bloc/offer_state
app/modules/offer/presentation/views/offer_view
app/modules/offer/presentation/views/offer_widget
app/modules/offer/presentation/views/widgets/address_widget
app/modules/offer/presentation/views/widgets/apply_coupon_widget
app/modules/offer/presentation/views/widgets/available_coupon
app/modules/offer/presentation/views/widgets/brand_tile_widget
app/modules/offer/presentation/views/widgets/buy_now_bottomsheet
app/modules/offer/presentation/views/widgets/cart_overlay_widget
app/modules/offer/presentation/views/widgets/categories_tile_widget
app/modules/offer/presentation/views/widgets/categories_widget
app/modules/offer/presentation/views/widgets/category_header_widget
app/modules/offer/presentation/views/widgets/category_list_widget
app/modules/offer/presentation/views/widgets/category_widget
app/modules/offer/presentation/views/widgets/coupon_widget
app/modules/offer/presentation/views/widgets/discount_widget
app/modules/offer/presentation/views/widgets/explore_widget
app/modules/offer/presentation/views/widgets/header_widget
app/modules/offer/presentation/views/widgets/highlight_brand_widget
app/modules/offer/presentation/views/widgets/kredcoin_widget
app/modules/offer/presentation/views/widgets/more_widget
app/modules/offer/presentation/views/widgets/offer_card
app/modules/offer/presentation/views/widgets/offer_code_widget
app/modules/offer/presentation/views/widgets/offer_detail_card_widget
app/modules/offer/presentation/views/widgets/offer_section
app/modules/offer/presentation/views/widgets/payment_summary_widget
app/modules/offer/presentation/views/widgets/premium_brand_section
app/modules/offer/presentation/views/widgets/premium_brand_widget
app/modules/offer/presentation/views/widgets/promotional_card_widget
app/modules/offer/presentation/views/widgets/purchased_voucher_detail_bottomsheet
app/modules/offer/presentation/views/widgets/redeem_steps_widget
app/modules/offer/presentation/views/widgets/redeem_widget
app/modules/offer/presentation/views/widgets/savings_widget
app/modules/offer/presentation/views/widgets/single_banner_widget
app/modules/offer/presentation/views/widgets/success_card_widget
app/modules/offer/presentation/views/widgets/transaction_item_widget
app/modules/offer/presentation/views/widgets/update_consumer_widget
app/modules/offer/presentation/views/widgets/voucher_card
app/modules/offer/presentation/views/widgets/voucher_card_widget
app/modules/offer/presentation/views/widgets/voucher_code_pin_widget
app/modules/offer/presentation/views/widgets/voucher_details
app/modules/offer/presentation/views/widgets/voucher_details_tab
app/modules/offer/presentation/views/widgets/voucher_history_card
app/modules/offer/presentation/views/widgets/voucher_purchase_widget
app/modules/offer/presentation/views/widgets/voucher_scratch_dialog
app/modules/offer/presentation/views/widgets/voucher_shimmer_widget
app/modules/offer/presentation/views/widgets/voucher_success_dialog
app/modules/offer/presentation/views/widgets/voucher_transaction_card
app/modules/payment_status/data/repository/payment_status_repository_impl
app/modules/payment_status/domain/payment_status_repository
app/modules/payment_status/presentation/bloc/payment_status_bloc
app/modules/payment_status/presentation/bloc/payment_status_event
app/modules/payment_status/presentation/bloc/payment_status_state
app/modules/payment_status/presentation/views/payment_status_view
app/modules/payment_status/presentation/views/success_animation_view
app/modules/payment_status/presentation/views/widgets/order_items_widget
app/modules/purchase_voucher/data/repository/purchase_voucher_repository_impl
app/modules/purchase_voucher/domain/purchase_voucher_repository
app/modules/purchase_voucher/presentation/bloc/purchase_voucher_bloc
app/modules/purchase_voucher/presentation/bloc/purchase_voucher_event
app/modules/purchase_voucher/presentation/bloc/purchase_voucher_state
app/modules/purchase_voucher/presentation/views/purchase_voucher_view
app/modules/purchase_voucher/presentation/views/widgets/add_to_cart_button
app/modules/purchased_voucher/data/models/purchased_voucher_response
app/modules/purchased_voucher/data/repository/purchased_voucher_repository_impl
app/modules/purchased_voucher/domain/purchased_voucher_repository
app/modules/purchased_voucher/presentation/bloc/purchased_voucher_bloc
app/modules/purchased_voucher/presentation/bloc/purchased_voucher_event
app/modules/purchased_voucher/presentation/bloc/purchased_voucher_state
app/modules/purchased_voucher/presentation/views/purchased_voucher_detail_view
app/modules/purchased_voucher/presentation/views/purchased_voucher_view
app/modules/purchased_voucher/presentation/views/widgets/voucher_card_widget
app/modules/purchased_voucher/presentation/views/widgets/voucher_detail_widget
app/modules/search/data/repository/search_repository_impl
app/modules/search/domain/search_repository
app/modules/search/presentation/bloc/search_bloc
app/modules/search/presentation/bloc/search_event
app/modules/search/presentation/bloc/search_state
app/modules/search/presentation/views/search_view
app/modules/transaction_history/data/models/consumer_order_response
app/modules/transaction_history/data/repository/transaction_history_repository_impl
app/modules/transaction_history/domain/transaction_history_repository
app/modules/transaction_history/presentation/bloc/transaction_history_bloc
app/modules/transaction_history/presentation/bloc/transaction_history_event
app/modules/transaction_history/presentation/bloc/transaction_history_state
app/modules/transaction_history/presentation/views/transaction_history_detail_view
app/modules/transaction_history/presentation/views/transaction_history_view
app/modules/transaction_history/presentation/views/widgets/bill_detail_widget
app/modules/transaction_history/presentation/views/widgets/items_widget
app/modules/transaction_history/presentation/views/widgets/order_detail_widget
app/modules/transaction_history/presentation/views/widgets/order_item_widget
app/modules/transaction_history/presentation/views/widgets/payment_status_widget
app/modules/transaction_history/presentation/views/widgets/reason_widget
app/modules/transaction_history/presentation/views/widgets/sort_widget
app/modules/transaction_history/presentation/views/widgets/status_widget
app/route/app_pages
app/themes/app_colors
app/themes/styles
injection_container
service/analytics_service
service/cashfree_payment_service
service/device_info_service
service/easebuzz_payment_service
service/razorpay_payment_service
service/sdk_notification_service
utils/helper/animated_flip_counter
utils/helper/cached_image
utils/helper/cached_svg_image
utils/helper/common_method
utils/helper/custom_clipper
utils/helper/date_extension
utils/helper/enums
utils/helper/exception_handler
utils/helper/regrex
utils/helper/rolling_widget
utils/helper/sizedbox_extension
utils/helper/string_extension
utils/helper/svg_network_image
utils/helper/svg_preloader
utils/helper/text_field_wrapper
utils/loading/loading_utils
utils/loading/shimmer/container_shimmer
utils/loading/shimmer/custom_shimmer
utils/loading/shimmer/detail_shimmer
utils/loading/shimmer/grid_shimmer
utils/loading/shimmer/listview_shimmer
utils/loading/shimmer/payment_status_track_shimmer
utils/loading/shimmer/recharge_status_shimmer
utils/storage/bell_notification_storage_utils
utils/storage/storage_utils
voucher_sdk
widgets/app_dialog
widgets/back_widget
widgets/cart_container_widget
widgets/circular_border_container
widgets/common_widget
widgets/contact_support_bottom_sheet_widget
widgets/container_clipper
widgets/custom_bottomsheet
widgets/custom_button
widgets/custom_expansion_tile
widgets/custom_radio_tile_widget
widgets/custom_text_field
widgets/heading_arrow
widgets/html_text_widget
widgets/image_banner_widget
widgets/input_text_field
widgets/pdf_view
widgets/previous_recharge_widget
widgets/separator_widget