smile_identity_plugin 0.0.1+2 copy "smile_identity_plugin: ^0.0.1+2" to clipboard
smile_identity_plugin: ^0.0.1+2 copied to clipboard

Wraps official iOS and Android SmileIdentity SDKs.

smile_identity_plugin #

Wraps official iOS and Android SmileIdentity SDKs.

Set-up #

Android Set-up #

Please visit this link to set up Smile Identity for Android.

While setting up for Android, make sure to:

  1. Set minSdkVersion to be at-least 19
  2. In android/src/main/kotlin/com/{packageName}/MainActivity.kt extend SmileidentityMainActivity

Example:

package com.example.example

import com.smile.smile_identity_plugin.SmileIdentityMainActivity

class MainActivity : SmileIdentityMainActivity() {

}

iOS Set-up #

Please visit this link to set up Smile Identity for iOS.

While setting up for iOS, make sure to:

  1. Set NSCameraUsageDescription in your project's info.plist file

Example:

 <key>NSCameraUsageDescription</key>
 <string>Using Camera for Smile Identity</string>
  1. Add the following pods In your Podfile:
target 'Runner' do
  ...
  pod 'Smile_Identity_SDK'
  ...
end

  1. Set the platform version to be at-least 13

Getting Started #

  1. Collect user data and create a SmileData object.

Example

final data = SmileData(
    firstName: "John",
    lastName: "Smith",
    country: "KE",
    idType: "NATIONAL_ID",
    idNumber: "00000000",
    userId: "specific-user-id",
    jobType: 1,
    captureType: CaptureType.selfieAndIdCapture,
)
  1. Start the Smile Identity verification process by calling the capture method

Example

final smileIdentity = SmileIdentityPlugin()
smileIdentity.capture(data)

By default the plugin handles camera permissions for each platform. You may disable this by setting the capture method handleCameraPermission parameter to false

smileIdentity.capture(data, handleCameraPermission: false)
  1. Handle states

The entire process involves two steps: Capturing and Submitting. Hence all possible states are categorized into two groups namely CaptureState and SubmitState.

NB: After capturing necessary images, the plugin will automatically initiate the submission phase.

@freezed
sealed class CaptureState with _$CaptureState {
  const CaptureState._();

  // Have not started capturing images yet
  const factory CaptureState.none() = _None;

  const factory CaptureState.capturing() = _Capturing;

  // Captured images successfully
  const factory CaptureState.captured() = _Captured;

  // An error happened while capturing images
  const factory CaptureState.error(String error) = _Error;

  bool get didCaptureSuccessfully {
    return maybeWhen(
      captured: () => true,
      orElse: () => false,
    );
  }

  String? get error {
    return maybeWhen(
      error: (error) => error,
      orElse: () => null,
    );
  }
}


@freezed
sealed class SubmitState with _$SubmitState {
  const SubmitState._();

  // Have not started submitting data yet
  const factory SubmitState.none() = _None;

  const factory SubmitState.submitting() = _Submitting;

  const factory SubmitState.submitted() = _Submitted;

  const factory SubmitState.error(String error) = _Error;

  bool get isNone {
    return maybeWhen(
      none: () => true,
      orElse: () => false,
    );
  }

  bool get didSubmitSuccessfully {
    return maybeWhen(
      submitted: () => true,
      orElse: () => false,
    );
  }

  // An error happened while submitting data
  String? get error {
    return maybeWhen(
      error: (error) => error,
      orElse: () => null,
    );
  }
}

If the entire process goes successfully, this will be the states progression: CaptureState.none, SubmitState.none -> CaptureState.capturing, SubmitState.none -> CaptureState.captured, SubmitState.none -> CaptureState.captured, SubmitState.submitting -> CaptureState.captured, SubmitState.submitted

The plugin, however, exposes SmileState stream having both CaptureState, SubmitState as well as SmileData as properties.

class SmileState {
  final CaptureState captureState;
  final SubmitState submitState;
  final SmileData? data;

  const SmileState({
    this.captureState = const CaptureState.none(),
    this.submitState = const SubmitState.none(),
    this.data,
  });
}

Subscribe to a stream of SmileStates and handle the states however you want.

Example

smilePlugin.onStateChanged.listen((event) {
    // code here
})