MetricWebviewSDK Documentation

Overview

MetricWebviewSDK is a flutter package designed to facilitate token-based identity verification through the Metric Africa service. The SDK provides methods to initiate token verification and check the status of a verification token, as well as a Verification modal for displaying the verification process.

--

Installation

To use the MetricWebviewSDK, you need to add the package to your pubspec.yaml file:

dependencies:
  metric_webview_sdk: ^0.0.1

Then, run flutter pub get to install the package.

or

Run this command in your terminal:

flutter pub add metric_webview_sdk

--

Features

  • Token Verification: Initiate token-based verification processes with configurable parameters.
  • Token Status Check: Retrieve the status of verification tokens.
  • Verification Modal: Seamless integration with a modal for user interactions.

Prerequisites

Before you begin, ensure your development environment meet the following requirements:

  • Flutter SDK - Version 1.17.0 or higher
  • Dart SDK - Version 3.6.0 or higher
  • Android SDK - Version 24 or higher

After these have been configured, ensure your camera permissions have been set in your info.plist and AndroidManifest.xml files in your iOS and android folders respectively.

iOS Permissions

<key>NSCameraUsageDescription</key>
<string>Camera access is required for verification</string>
<key>NSMicrophoneUsageDescription</key>
<string>Microphone access is required for verification</string>

Android Permissions

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />

Usage

For a full example on how to use the package, check the example.dart file in the example directory.

Initialization

To use the SDK, initialize it with your client ID and secret key:

import 'package:metric_webview_sdk/metric_sdk.dart';

final metric = MetricSdk(publicKey: '', secretKey: '');

Methods

initiateTokenVerification

Initiates the token verification process.

Parameters:

  • token (String): Required token for verification.
  • onClose (Function(VerificationData?)): Callback executed with the result of the verification when the modal is closed.

Returns:

  • A webview modal.

Example:

metric.initiateTokenVerification(
    token: 'your_token',
    onClose: (result) {
        return result;
    },
);

--

checkTokenStatus

Checks the status of a unused token.

Parameters:

  • token (String): Required token for verification.

Returns:

  • A Future<String> containing the status of the token.

Example:

metric.checkTokenStatus(token: 'your_token');

--

checkUsedTokenStatus

Checks the status of a used token.

Parameters:

  • token (String): Required token for verification.

Returns:

  • A Future<String> containing the status of the used token.

Example:

metric.checkUsedTokenStatus(token: 'your_token');

--

Example

Below is a complete example of using the SDK in a Flutter application:

Example:

import 'package:flutter/material.dart';
import 'package:metric_webview_sdk/metric_sdk.dart';
import 'package:metric_webview_sdk/models/models.dart';

class WebviewExample extends StatefulWidget {
  const WebviewExample({super.key});

  @override
  State<WebviewExample> createState() => _WebviewExampleState();
}

class _WebviewExampleState extends State<WebviewExample> {
  VerificationData? verificationResult;
  TextEditingController tokenController = TextEditingController();
  bool data = false;

  @override
  Widget build(BuildContext context) {
    final metric = MetricSdk(publicKey: '', secretKey: '');

    Future<void> handleVerification() async {
      try {
        final verificationData = await Navigator.push(
          context,
          MaterialPageRoute(
            builder: (context) => FutureBuilder(
              future: metric.initiateTokenVerification(
                  token: tokenController.text,
                  onClose: (verificationData) {
                    Navigator.pop(context, verificationData);
                  }),
              builder: (context, snapshot) {
                if (snapshot.hasData) {
                  return snapshot.data!;
                }
                return const Center(child: CircularProgressIndicator());
              },
            ),
          ),
        );
        if (verificationData != null) {
          setState(() {
            verificationResult = verificationData;
            data = true;
          });
        }
      } catch (e) {
        debugPrint('Verification error: $e');
      }
    }

    return Scaffold(
        body: Center(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          data
              ? Column(
                  children: [
                    Text('Status: ${verificationResult!.status}'),
                    Text('Customer Name: ${verificationResult!.customerName}'),
                    Text('SUID: ${verificationResult!.suid}')
                  ],
                )
              : Text('No Verification Result'),
          SizedBox(height: 30),
          Text('Enter Token:'),
          SizedBox(
            width: 90,
            child: TextField(controller: tokenController),
          ),
          SizedBox(
            height: 30,
          ),
          ElevatedButton(
            onPressed: handleVerification,
            child: Text(
              'Verify Token',
            ),
          )
        ],
      ),
    ));
  }
}

--

Note: Ensure valid tokens and configurations are provided to avoid errors and ensure smooth operation.