Skip to main content

videokyc_flutter 1.0.2 copy "videokyc_flutter: ^1.0.2" to clipboard
videokyc_flutter: ^1.0.2 copied to clipboard

A Flutter SDK for integrating SurePass Video KYC verification.

example/lib/main.dart

// Minimal example for the SurePass Video KYC Flutter SDK.
//
// Replace `your_surepass_api_token` and `your_workflow_id` with your SurePass
// credentials, then run the app. See the package README for the required
// Android/iOS platform setup (manifest permissions, Info.plist keys, and the
// permission_handler Podfile macros).

import 'package:flutter/material.dart';
import 'package:videokyc_flutter/videokyc_flutter.dart';

void main() => runApp(const ExampleApp());

class ExampleApp extends StatelessWidget {
  const ExampleApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Video KYC Example',
      home: const HomePage(),
    );
  }
}

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

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  String _status = 'Not started';

  Future<void> _startKyc() async {
    final messenger = ScaffoldMessenger.of(context);

    final result = await startSurepassVideoKyc(
      context: context,
      token: 'your_surepass_api_token',
      env: Env.sandbox, // or Env.prod
      workflowId: 'your_workflow_id',
      email: 'user@example.com',
      fullName: 'John Doe',
      mobileNumber: '9876543210', // 10-digit number, no country-code prefix
      onInitialized: (VideoKycModel model) {
        debugPrint(
            'Initialized: user=${model.userId} session=${model.sessionId}');
      },
    );

    final outcome = switch (result?.status) {
      VideoKycStatus.success => 'success (session ${result!.sessionId})',
      VideoKycStatus.cancelled => 'cancelled by the user',
      VideoKycStatus.failed => 'failed',
      VideoKycStatus.error => 'error: ${result!.errorMessage}',
      null => 'dismissed before a terminal status',
    };

    if (!mounted) return;
    setState(() => _status = outcome);
    messenger.showSnackBar(SnackBar(content: Text('Result: $outcome')));
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Video KYC Example')),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Text('Status: $_status'),
            const SizedBox(height: 16),
            FilledButton(
              onPressed: _startKyc,
              child: const Text('Start Video KYC'),
            ),
          ],
        ),
      ),
    );
  }
}