Implement Flutter SDK in your Project

After setting up the working environment for developing the Flutter app primarily in Android or iOS and creating the Flutter project in the IDE, you can now proceed to implement the Catalyst Flutter SDK in your Flutter project. When you create a Flutter project, a basic pubspec.yaml file is generated and located at the top of the project tree. This file contains the metadata about the project and specifies the dependencies that the project requires.

Install the SDK

You will need to add the following configurations to implement the Catalyst Flutter SDK to the pubspec.yaml of your Flutter project:

    
copy
dependencies: zc_flutter_sdk: ^1.1.0

To install the Flutter SDK in your project, you will need to execute the following command from your IDE’s terminal: flutter pub get

Note: You can also get this package in the following ways in your IDE: * VS Code: Click **Get Packages** located in right side of the action ribbon at the top of pubspec.yaml indicated by the Download icon. * Android Studio/IntelliJ: Click **Pub get** in the action ribbon at the top of pubspec.yaml.

Import the SDK

To import the SDK in the Dart code, you will need to add the following line of code in the the lib/main.dart file in your Flutter project directory:

    
copy
import 'package:zc_flutter_sdk/zc_flutter_sdk.dart';

Initialize the SDK

You must initialize the Catalyst SDK to enable the functioning of the methods and features defined in the SDK package.

Therefore, before you configure your app to consume the SDK methods, you must initialize the SDK in your main() function using the ZCatalystApp.init() method in any one of the following methods:

1. Using the Catalyst Configuration File:

The configuration function that you downloaded previously for Android or iOS will indicate the environment of the app. Similar to including the appropriate configuration file (app_configuration_development.properties / app_configuration_production.properties for Android and AppConfigurationDevelopment.plist / AppConfigurationProduction.plist for iOS) based on the environment in your app’s project, you must initialize the SDK for the appropriate environment.


By specifying the environment:

In this method, you must set the required configuration and specify the environment of your app as either DEVELOPMENT or PRODUCTION, and pass it to the init() method through the ZCatalystApp class as shown below:

    
copy
ZCatalystApp.init({ ZCatalystEnvironment? environment, });

A sample code snippet is shown below:

    
copy
void main() async { try { await ZCatalystApp.init(environment: ZCatalystEnvironment.DEVELOPMENT); } on ZCatalystException catch (ex) { print('Initialized Failed: ${ex.toString()}'); } }

Without specifying the environment:

If the environment is not specified in the SDK initialization, it would be considered as PRODUCTION by default. Therefore, if your app is operating in the Production environment, you can initialize the SDK directly in the following way:

    
copy
await ZCatalystApp.init();

A sample code snippet is shown below:

    
copy
void main() async { try { await ZCatalystApp.init(); } on ZCatalystException catch (ex) { print('Initialized Failed: ${ex.toString()}'); } }
Note: If you make any changes to the Android or iOS configuration file, you must reinitialize the SDK.

2. By passing the custom SDK Configuration Object:

Alternatively, you can initialize the Flutter SDK by building a custom ZCatalystSDKConfigs object that you can pass using the ZCatalystSDKConfigsBuilder class.

ZCatalystSDKConfigs Object

The ZCatalystSDKConfigsBuilder class has the following configuration properties:

Properties Datatype Description
environment ZCatalystEnvironment The environment under which the app is currently running
apiBaseURL String The URL of the Catalyst server through which the internal API is called. You must use the appropriate URL (development URL or production URL), based on the environment you are working in.
clientID String Unique identifier of your app client registered in Catalyst. This is received in the configuration file.
clientSecret String Secret value generated for a specific clientID, which is passed along with the API hits. This is received in the configuration file.
projectID int The unique ID of your Catalyst Project
redirectURL String The callback URL of your app that you provided while creating a package for Android or iOS in the console
portalID String Unique identifier received in the configuration file
oauthScopes String The scopes that would be used by the app to access the Catalyst APIs from your project. You can find the available OAuth scopes here.
JWTClientID String The client ID property of the custom server token (JSON Web Token token) generated for third-party authentication to be passed to the client
JWTClientSecret String The client secret property of the custom server token (JSON Web Token token) generated for third-party authentication to be passed to the client

This ZCatalystSDKConfigs object can now be passed using the ZCatalystSDKConfigsBuilder class as shown below:

    
copy
ZCatalystSDKConfigs sdkConfigs = ZCatalystSDKConfigsBuilder( apiBaseURL: 'https://api.catalyst.zoho.com', clientID: '100****************************FX', clientSecret: '19ed***************************2s', environment: ZCatalystEnvironment.DEVELOPMENT, oauthScopes: 'ZOHOCATALYST.tables.rows.ALL, ZOHOCATALYST.tables.columns.ALL', portalID: '10******79', projectID: 28*******90, redirectURL: '*****') .setAccountsPortalBaseURL('https://accounts.zohoportal.com') .setUserAgent("ZCatalyst Sample App") .addRequestHeaders('PORTAL_ID', '*********') .build(); try { await ZCatalystApp.init(sdkConfigs: sdkConfigs); } on ZCatalystException catch (ex) { print('Initialized Failed: ${ex.toString()}'); }

If the SDK is successfully initialized, the app will invoke the component methods and function as intended.

Last Updated 2023-09-22 20:48:20 +0530 +0530