flutter_idensic_mobile_sdk_plugin 1.18.1 copy "flutter_idensic_mobile_sdk_plugin: ^1.18.1" to clipboard
flutter_idensic_mobile_sdk_plugin: ^1.18.1 copied to clipboard

outdated

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.
  //
  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)
    .onTestEnv(); // remove this when you work with the production environment

  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) {

  final SNSStatusChangedHandler onStatusChanged = (SNSMobileSDKStatus newStatus, SNSMobileSDKStatus prevStatus) {
    print("onStatusChanged: $prevStatus -> $newStatus");

    // just to show how dismiss() method works
    if (setDismissTimer && 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://test-api.sumsub.com"; // or https://api.sumsub.com
  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 setDismissTimer = 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: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            ElevatedButton(
              onPressed: () => launchSDK(),
              child: Text("Launch Sumsub SDK"),
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                SizedBox(width: 16),
                Text("Dismiss in 10 secs"),
                Checkbox(
                  value: setDismissTimer,
                  onChanged: (value) {
                    setState(() {
                      setDismissTimer = !setDismissTimer;
                    });
                  },
                ),
              ]
            ),
          ],
        ),
      ),
    ));
  }
}
11
likes
0
pub points
92%
popularity

Publisher

verified publishersumsub.com

Flutter plugin exposing Sumsub MobileSDK

Homepage

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on flutter_idensic_mobile_sdk_plugin