The minSdk or minSdkVersion of the Flutter project must be identical to that of our Android SDK.
Respect all the parameters and requirements of the iOS SDK so that Flutter can function fully.
Signing & Capabilities
Before running your Flutter app with the ShareID SDK, you must configure Signing & Capabilities in Xcode to avoid build errors.
2. Get a token
Use the credentials you received from ShareID's team to get an authenticate token and launch an onboarding or authenticate workflow.
Depending on the SDK you are integrating (Onboarding/Authenticate), you may use an API here Get a Token
3. Start an onboarding or authenticate flow
Use your token to start an onboarding or an authenticate.
Step 1: Create the ShareID service
The purpose of this service is to act as a bridge between your Dart code and the native Android/iOS code. It relies on MethodChannel, which enables Flutter to call platform-specific features and receive results, since Flutter runs in a separate engine that cannot directly access native functionalities.
Step 2: Update the service to listen to all events
Connect the channel with your ShareID messageHandler by adding the following lines to your MainActivity.
Kotlin
import io.flutter.plugin.common.EventChannel
class MainActivity : FlutterActivity() {
private val EVENT_CHANNEL = "shareid_sdk_event_channel"
private var eventSink: EventChannel.EventSink? = null
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
super.configureFlutterEngine(flutterEngine)
/// Your Method channel
EventChannel(flutterEngine.dartExecutor.binaryMessenger, EVENT_CHANNEL).setStreamHandler(object : EventChannel.StreamHandler {
override fun onListen(arguments: Any?, events: EventChannel.EventSink?) {
eventSink = events
}
override fun onCancel(arguments: Any?) {
eventSink = null
}
})
ShareID.shared.messageHandler = { result ->
when (result.type) {
ShareID.ResultType.success -> {
eventSink?.success(mapOf("type" to "success", "message" to result.code))
}
ShareID.ResultType.exit -> {
eventSink?.success(mapOf("type" to "exit", "message" to result.code))
}
ShareID.ResultType.failure -> {
eventSink?.success(mapOf("type" to "failure", "message" to result.code))
}
else -> {
eventSink?.error("UNKNOWN", "Unknown result type", null)
}
}
}
}
}
Java
import io.flutter.plugin.common.EventChannel;
import java.util.HashMap;
import java.util.Map;
public class MainActivity extends FlutterActivity {
private static final String EVENT_CHANNEL = "shareid_sdk_event_channel";
private EventChannel.EventSink eventSink;
@Override
public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
super.configureFlutterEngine(flutterEngine);
new EventChannel(flutterEngine.getDartExecutor().getBinaryMessenger(), EVENT_CHANNEL)
.setStreamHandler(new EventChannel.StreamHandler() {
@Override
public void onListen(Object arguments, EventChannel.EventSink events) {
eventSink = events;
}
@Override
public void onCancel(Object arguments) {
eventSink = null;
}
});
ShareID.Companion.getShared().setMessageHandler(result -> {
if (eventSink == null) return null;
Map<String, Object> response = new HashMap<>();
response.put("message", result.getCode());
switch (result.getType()) {
case success:
response.put("type", "success");
eventSink.success(response);
break;
case exit:
response.put("type", "exit");
eventSink.success(response);
break;
case failure:
response.put("type", "failure");
eventSink.success(response);
break;
default:
eventSink.error("UNKNOWN", "Unknown result type", null);
}
return null;
});
}
}
Connect the channel with your ShareID messageHandler by adding the following lines to your AppDelegate.
@UIApplicationMain
class AppDelegate: FlutterAppDelegate {
private let eventChannelName = "shareid_sdk_event_channel"
private var eventSink: FlutterEventSink?
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
let controller: FlutterViewController = window?.rootViewController as! FlutterViewController
// Your Method channel
let eventChannel = FlutterEventChannel(name: eventChannelName, binaryMessenger: controller.binaryMessenger)
eventChannel.setStreamHandler(self)
setupMessageHandler()
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
/// **Sets up a single persistent listener for ShareID events**
private func setupMessageHandler() {
ShareID.shared.messageHandler = { result in
guard let eventSink = self.eventSink else { return }
var response: [String: Any] = [
"message": result.code
]
switch result.type {
case .success:
response["type"] = "success"
case .failure:
response["type"] = "failure"
case .exit:
response["type"] = "exit"
@unknown default:
fatalError()
}
eventSink(response)
}
}
}
extension AppDelegate: FlutterStreamHandler {
func onListen(withArguments arguments: Any?, eventSink events: @escaping FlutterEventSink) -> FlutterError? {
self.eventSink = events
return nil
}
func onCancel(withArguments arguments: Any?) -> FlutterError? {
self.eventSink = nil
return nil
}
}
To view all possible end-of-process results in our SDK, please refer to the Message Handler for all success, exit and failure states.
5. Get the Analysis result
When the processing of an onboarding request is finished, you may receive the result through the callback if you provided it. You may also, fetch yourself the result by calling our API.
The ShareID SDK is designed to be highly customisable, allowing great flexibility through various configuration options or the application of themes to adapt the user interface to your needs. To do this, simply follow this same section in the Android and iOS documentation and add them to your code.
FAQ
Why does my IDE display "Code insight unavailable (related Gradle project not linked)" ?
This error appear in your IDE (probably Android Studio or IntelliJ IDEA) means that the Gradle project is not properly linked to the IDE. This issue prevents features like autocompletion, syntax highlighting, and code navigation from working properly.
There are several solutions to this problem. The most coherent would be to open the Android file directly to modify your Java or Kotlin files, and to open your Flutter project for the other modifications.
So, File > Open... > <your-flutter-app> > Select android file and press Open