Flutter Integration

Integrate smallcase Gateway Flutter SDK to allow your users to transact in stocks, ETFs & smallcases, and much more

Step 1 - Install and Configure

Gateway Flutter SDK is available on pub.dev. To install the SDK:

  1. Add scgateway_flutter_plugin/scloans as dependencies of your app.
flutter pub add scgateway_flutter_plugin
flutter pub add scloans // for loans
  1. Run the following command from the terminal:
flutter pub get
  1. The plugin exports all its methods with one default import. Import it using:
import 'package:scgateway_flutter_plugin.dart';
import 'package:scloans.dart'; // in case of Loans SDK

A. Android

  1. Configure smallcase Gateway Android SDK via AndroidManifest.xml:
<activity
    android:name="com.smallcase.gateway.screens.mutualfunds.activity.MFHoldingsActivity"
    android:exported="true">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />

        <category android:name="android.intent.category.BROWSABLE" />
        <category android:name="android.intent.category.DEFAULT" />

        <!-- Use the same unique host provided for your integration -->
        <data
            android:scheme="scgatewaymfhi"
            android:host="{YOUR_GATEWAY_NAME}" />
    </intent-filter>
</activity>

<activity
    android:name="com.smallcase.gateway.screens.transaction.activity.TransactionProcessActivity"
    android:exported="true">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />

        <category android:name="android.intent.category.BROWSABLE" />
        <category android:name="android.intent.category.DEFAULT" />

        <data
            android:host="<YOUR_GATEWAY_NAME>"
            android:scheme="scgateway" />
    </intent-filter>
</activity>

<activity
    android:name="com.smallcase.gateway.screens.common.RedirectActivity"
    android:exported="true">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />

        <category android:name="android.intent.category.BROWSABLE" />
        <category android:name="android.intent.category.DEFAULT" />

        <data
            android:host="<YOUR_GATEWAY_NAME>"
            android:scheme="scgatewayredirect" />
    </intent-filter>
</activity>

Replace <YOUR_GATEWAY_NAME> with the unique gateway name provided to every integration partner.

Add this to your app-level build.gradle file:

// Include Maven repository URL and authentication details
repositories {
    maven {
        url "https://artifactory.smallcase.com/artifactory/SCGateway"
    }
}
🚧

Note

If your app targets Android 12 or higher, you must explicitly declare the android:exported attribute for these activities. If an activity does not have an explicitly declared value for android:exported, your app cannot be installed on a device running Android 12 or higher.


  1. Add the following configuration to android/app/proguard-rules.pro to use Flutter plugins in release mode:
# Flutter Wrapper
-keep class io.flutter.app.** { *; }
-keep class io.flutter.plugin.**  { *; }
-keep class io.flutter.util.**  { *; }
-keep class io.flutter.view.**  { *; }
-keep class io.flutter.**  { *; }
-keep class io.flutter.plugins.**  { *; }

# Add project-specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /usr/local/google/home/samstern/android-sdk-linux/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see:
# http://developer.android.com/guide/developing/tools/proguard.html

# Add any project-specific keep options here.

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name of the JavaScript interface:
#
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
#   public *;
#}

# Preserve line number information for debugging stack traces.
-keepattributes SourceFile,LineNumberTable

# To hide the original source file name, uncomment:
#-renamesourcefileattribute SourceFile

# Keep custom model classes
-keep class com.google.firebase.** { *; }

# Ignore minifyEnabled: true errors
# https://github.com/flutter/flutter/issues/19250
# https://github.com/flutter/flutter/issues/37441
-ignorewarnings

-keep class * {
    public private *;
}

B. iOS

smallcase Gateway iOS SDK is available as a private CocoaPods dependency.

Add the following code to your Podfile and run pod install within the directory containing the Podfile:

# Default source for all other pods
source 'https://cdn.cocoapods.org'

# Private podspec for smallcase (only for versions < 2.2.0)
source 'https://github.com/smallcase/cocoapodspecs.git'

iOS Photo Library Permission Configuration

To allow the app to save data, such as QR codes or files, to the user’s device, add the required photo library permission to your app’s Info.plist:

<!-- Permission to save data, such as QR codes or files, to the user's photo library -->
<key>NSPhotoLibraryAddUsageDescription</key>
<string>{YOUR_APP_NAME} requires access to your photo library to save data on your device.</string>

Launch a WebView

Available in scgateway_flutter_plugin version 7.1.0 and later.

final launched = await ScgatewayFlutterPlugin.launchScWebView(
  'https://example.com',
);

Pass a trusted absolute HTTP(S) URL. No Gateway setup or user session initialization is required.

The returned Future<bool> confirms that the WebView launch was accepted; it does not indicate that the page or user journey completed.

Step 2 - Environment Setup

To start using Gateway, configure the Gateway SDK by calling the setConfigEnvironment method, which is available as a static method of the ScgatewayFlutterPlugin class:

ScgatewayFlutterPlugin.setConfigEnvironment(
    environment, // should always be GatewayEnvironment.PRODUCTION
    gateway,
    leprechaunMode,
    brokers,
    isAmoEnabled,
);

Parameters:

  1. environment (required): Defines the URL environment to which all Gateway APIs point. The value should be GatewayEnvironment.PRODUCTION.
  2. gateway (required): The unique name given to every Gateway consumer.
    Example: moneycontrol
  3. leprechaunMode (required): Used for testing purposes only. The default value is false.
  4. brokers (required): Limits the brokers supported by the integration. All brokers are shown if an empty list is passed.
    Possible values: aliceblue, angelbroking, axis, dhan, edelweiss, fisdom, fivepaisa, fundzbazar, groww, hdfc, hdfcsky, icici, iifl, kite, kotak, motilal, sbi, trustline & upstox
  5. isAmoEnabled (optional): Controls after-market order placement.
📘

Note

Call setConfigEnvironment whenever the setup changes.
setConfigEnvironment must be called before using other Gateway methods, except launchScWebView.

Step 3 - Initialise User Session

User initialization starts a session between the distributor and Gateway. Whenever the user session changes, this method must be triggered:

ScgatewayFlutterPlugin.initGateway(authToken);

Parameters:

authToken (required): A JWT containing user information, signed using the shared secret between the smallcase API and the Gateway backend. Learn more about using JWT.

Step 4 - Trigger an SDK Method

A. Transactional Flows

Transactional flows are user journeys where interaction with the user’s broker is required. Examples include placing stock or smallcase orders, importing holdings, and connecting a broker account.

smallcase Gateway assigns a unique transactionId for each user intent. The transactionId is a short-lived identifier representing a single user interaction session.

i - Create a transactionId

Create the transactionId by making a server-to-server request to the relevant transaction API. This API call must be made from your backend because secrets must not be used in the app.

When the user performs a transactional action, your app should send the relevant order configuration to your backend. Your backend should create the transactionId through smallcase Gateway and return it to the app.

Transaction API references:

ii - Call the triggerTransaction SDK method

To start the transactional flow, call triggerGatewayTransaction:

ScgatewayFlutterPlugin.triggerGatewayTransaction(transactionId);

Parameters:

transactionId (required): The unique transaction identifier received from your backend.

B. Non-transactional Flows

i - Call the relevant SDK method

DescriptionSDK method
Broker account openingtriggerLeadGen
Logout from smallcase platformlogoutUser

More details are available in the Non-transactional Flows section.

Step 5 - Save the Order Response

The order response is shared in the onSuccess() block of the triggerTransaction method and through API webhooks. See the transaction response structure.

If the transaction is not placed with the broker, the error is available in the onError block.

See the complete list of transaction errors.


Non-transactional Flows

📘

Note

To use the following methods, the Gateway session must be initialized with the relevant user data.

Broker Account Opening

Call the triggerLeadGen method to start the account-opening flow:

ScgatewayFlutterPlugin.leadGen(name, email, contact);

Parameters:

name (optional): Name of the user.

email (optional): Email address of the user.

contact (optional): Contact number of the user.

The SDK uses the relevant values passed to triggerLeadGen to pre-populate the user’s information in the signup flow.

Logout from the smallcase Platform

This method is useful when users want to switch accounts for the same broker. It logs the user out of the smallcase platform so that they are asked to sign in again the next time they interact with smallcase Gateway.

📘

Note

This flow is available only for connected users.

ScgatewayFlutterPlugin.logoutUser();

Show Orders

This method displays the user’s recent orders, including pending, successful, and failed orders:

ScgatewayFlutterPlugin.showOrders();

Did this page help you?