Skip to main content

Flutter Integration Guide

This document provides a step-by-step guide on how to install, integrate and initialize the BlockID SDK into any Flutter iOS application.

Prerequisites

tip

Please visit how to install Flutter for information on installing Flutter on you machine

Below are a few general and platform-specific dependencies required to integrate BlockID SDK into a Flutter-iOS application.

General

  • An understanding of how to develop iOS applications using Flutter
  • At least one compatible iOS mobile device

Technical

  • Flutter should be installed on your machine
  • Any updated IDE to run flutter projects
  • iOS 13.0 or higher
  • Device support - all the devices running iOS 13.0 and above
  • Existing Flutter project to integrate with the BlockID SDK
info

The BlockID SDK currently supports up to iOS 16.x

Integration Overview

This section explains how to set up and integrate the BlockID SDK into a Flutter application for iOS.

The examples below show the integration of the BlockID SDK into an existing application.

Step 1: Add BlockID SDK into the existing flutter project

tip

Please request access to our SDK and demo applications by sending us an email at developers@1kosmos.com

  • Download the latest version of BlockIDSDK.xcframework, or clone the latest release tag - send us an email at the address above for details
  • Navigate to the project directory and open the iOS folder
  • Add the .xcframework file from the BlockIDSDK into the iOS folder
  • Sync the changes and build the project. The application must be built successfully for the integration to continue

Integration Steps

tip

Refer to the API Reference Guide for iOS for more details on the methods used in this section

Step 1: Create a Method Channel

To access the APIs from the BlockIDSDK, we have to create a method channel that will help communicate between the iOS codebase and Dart.

  • First, we need to define the name of the channel in the AppDelegate class as shown below:
    private let CHANNEL = "AccessBlockIDSDK"
  • Import the Flutter plugin that will help to access FlutterEngine and MethodChannel:
import Flutter
  • Next, add the following code block to configure the Flutter engine and set a method call handler to call functions from the dart codebase, and view responses:
 let controller : FlutterViewController = window?.rootViewController as! FlutterViewController
let batteryChannel = FlutterMethodChannel(name: CHANNEL,
binaryMessenger: controller as! FlutterBinaryMessenger)
batteryChannel.setMethodCallHandler({
(call: FlutterMethodCall, result: @escaping FlutterResult) -> Void in
// Note: this method is invoked on the UI thread.

})
  • In your Dart file, create a const using the same channel name that we defined in AppDelegate*:
  static const methodChannel = MethodChannel('AccessBlockIDSDK');

Step 2: BlockID SDK Setup

caution

In order to use the features of the BlockID SDK, you must add your License Key, Wallet, and Tenant details as documented in the iOS Mobile SDK Integration Guide, under Initial SDK Setup.

This information will be provided with access to the Mobile SDK. Please contact us at developers@1kosmos.com for access to the Mobile SDK.

The credentials listed on your Developer Dashboard will not work with the BlockID Mobile SDK

Step 3: Test Integration - Display SDK Version in Application

We can test the Flutter integration by creating a function to display the BlockIDSDK version in our application.

  • Create a function in the AppDelegate class to access the version of the BlockIDSDK:
private func getSDKVersion() -> String {
return BlockIDSDK.sharedInstance.getVersion() ?? "<default_value>"
}
  • Invoke the function from iOS using the methodChannel constant defined above in Dart:
Future<void> getSDKVersion() async {
String response = "";
try {
final String result = await methodChannel.invokeMethod('getSDKVersion');
response = result;
} on PlatformException catch (e) {
response = "Failed to Invoke: '${e.message}'.";
}
setState(() {
_sdkVersion = response;
});
}

We can now use the getSDKVersion() function we added anywhere in your Dart class to retrieve the version of the BlockIDSDK, confirming that the iOS Flutter integration is sucessfully working.