flutter_idensic_mobile_sdk_plugin 1.19.5
flutter_idensic_mobile_sdk_plugin: ^1.19.5 copied to clipboard
Flutter plugin exposing Sumsub MobileSDK
example/lib/main.dart
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_idensic_mobile_sdk_plugin/flutter_idensic_mobile_sdk_plugin.dart';
SNSMobileSDK? snsMobileSDK;
void launchSDK() async {
//
// WARNING: In case your dashboard is in Flows/Levels mode,
// uncomment the line below and see `launchFlowBased()` for the details.
//
// launchFlowBased(); return;
// From your backend get an access token for the applicant to be verified.
// The token must be generated with `levelName` and `userId`,
// where `levelName` is the name of a level configured in your dashboard.
//
// The sdk will work in the production or in the sandbox environment
// depend on which one the `accessToken` has been generated on.
//
final String accessToken = "your access token";
// The access token has a limited lifespan and when it's expired, you must provide another one.
// So be prepared to get a new token from your backend.
//
final onTokenExpiration = () async {
// call your backend to fetch a new access token (this is just an example)
return Future<String>.delayed(Duration(seconds: 2), () => "your new access token");
};
final builder = SNSMobileSDK.init(accessToken, onTokenExpiration);
// builder.onTestEnv(); // use this only if you work with test-api
setupOptionalHandlers(builder);
snsMobileSDK = builder
.withLocale(Locale("en")) // https://api.flutter.dev/flutter/dart-ui/Locale-class.html
.withDebug(true) // set debug mode if required
.build();
final result = await snsMobileSDK!.launch();
print("Completed with result: $result");
}
void setupOptionalHandlers(SNSMobileSDKBuilder builder) {
if (useApplicantConf) {
builder.withApplicantConf({
"email": "test@test.com",
"phone": "123456789"
});
}
final SNSStatusChangedHandler onStatusChanged = (SNSMobileSDKStatus newStatus, SNSMobileSDKStatus prevStatus) {
print("onStatusChanged: $prevStatus -> $newStatus");
// just to show how dismiss() method works
if (useDismissTimer && prevStatus == SNSMobileSDKStatus.Ready) {
new Timer(Duration(seconds: 10), () {
snsMobileSDK?.dismiss();
});
}
};
final SNSEventHandler onEvent = (SNSMobileSDKEvent event) {
print("onEvent: $event");
};
final SNSActionResultHandler onActionResult = (SNSMobileSDKActionResult result) {
print("onActionResult: $result");
// you must return a `Future` that in turn should be completed with a value of `SNSActionResultHandlerReaction` type
// you could pass `.Cancel` to force the user interface to close, or `.Continue` to proceed as usual
return Future.value(SNSActionResultHandlerReaction.Continue);
};
builder.withHandlers(
onStatusChanged: onStatusChanged,
onActionResult: onActionResult,
onEvent: onEvent
);
}
///
/// The SDK initialization much depends on the mode your dashboard operates on.
/// Use the method below only if your dashbord is in Flows/Levels mode,
/// otherwise please refer to the launchSDK()
///
void launchFlowBased() async {
final String apiUrl = "https://api.sumsub.com"; // use the same for both the production and the sandbox
final String flowName = "msdk-basic-kyc"; // or set up your own with the dashboard
final String accessToken = "your access token"; // get the access token from your backend
final onTokenExpiration = () async {
// call your backend to fetch a new access token (this is just an example)
return Future<String>.delayed(Duration(seconds: 2), () => "your new access token");
};
final builder = SNSMobileSDK.builder(apiUrl, flowName)
.withAccessToken(accessToken, onTokenExpiration);
setupOptionalHandlers(builder);
snsMobileSDK = builder
.withSupportEmail("support@myemail.com")
.withLocale(Locale("en")) // https://api.flutter.dev/flutter/dart-ui/Locale-class.html
.withDebug(true) // set debug mode if required
.build();
final result = await snsMobileSDK!.launch();
print("Completed with result: $result");
}
// ------------------------------------------------------
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
var useDismissTimer = false;
var useApplicantConf = false;
class _MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('IdensicMobileSDK Plugin'),
),
body: Container(
alignment: Alignment.center,
child: IntrinsicWidth(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
ElevatedButton(
onPressed: () => launchSDK(),
child: Text(" Launch Sumsub SDK "),
),
]
),
SizedBox(height: 16),
Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Checkbox(materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, value: useDismissTimer, onChanged: (value) {
setState(() {
useDismissTimer = !useDismissTimer;
});
}),
Text("Dismiss in 10 secs"),
]
),
Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Checkbox(materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, value: useApplicantConf, onChanged: (value) {
setState(() {
useApplicantConf = !useApplicantConf;
});
}),
Text("Test initial email and phone"),
]
),
],
),
),
),
));
}
}