smile_identity_plugin 0.0.1+1
smile_identity_plugin: ^0.0.1+1 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:
- Set
minSdkVersionto be at-least 19 - In
android/src/main/kotlin/com/{packageName}/MainActivity.ktextendSmileidentityMainActivity
Example:
package com.example.example
import com.tembo_plus.smile_identity_plugin.SmileIdentityMainActivity
import io.flutter.embedding.android.FlutterActivity
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:
- Set
NSCameraUsageDescriptionin your project'sinfo.plistfile
Example:
<key>NSCameraUsageDescription</key>
<string>Using Camera for Smile Identity</string>
- Add the following pods In your
Podfile:
target 'Runner' do
...
pod 'Smile_Identity_SDK'
pod 'MaterialComponents/Snackbar'
...
end
- Set the platform version to be at-least 13
Getting Started #
- Collect user data and create a
SmileDataobject.
Example
final data = SmileData(
firstName: "John",
lastName: "Smith",
country: "KE",
idType: "NATIONAL_ID",
idNumber: "00000000",
userId: "specific-user-id",
jobType: 1,
captureType: CaptureType.selfieAndIdCapture,
)
- Start the Smile Identity verification process by calling the
capturemethod
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)
- 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
})