skaletek_kyc 0.0.17 copy "skaletek_kyc: ^0.0.17" to clipboard
skaletek_kyc: ^0.0.17 copied to clipboard

A Flutter SDK for integrating Skaletek's eKYC verification services.

example/lib/main.dart

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

void main() {
  runApp(const MyApp());
}

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
      ),
      home: const HomeScreen(),
    );
  }
}

class HomeScreen extends StatefulWidget {
  const HomeScreen({super.key});
  @override
  State<HomeScreen> createState() => _HomeScreenState();
}

enum _VerificationOutcome { none, success, failure, awaitReview }

class _HomeScreenState extends State<HomeScreen> {
  bool _isVerifying = false;
  String _status = '';
  bool _hasVerificationResult = false;
  _VerificationOutcome _outcome = _VerificationOutcome.none;

  void _startVerification() async {
    setState(() {
      _isVerifying = true;
      _status = 'Starting verification...';
      _hasVerificationResult = false;
      _outcome = _VerificationOutcome.none;
    });

    final userInfo = KYCUserInfo(
      firstName: "Whyte",
      lastName: "Peter",
      documentType: DocumentType.passport.value,
      issuingCountry: "USA",
    );
    final customization = KYCCustomization(
      docSrc: DocumentSource.file.value,
      logoUrl: null,
      partnerName: "Your Company",
      primaryColor: null,
    );

    SkaletekKYC.instance.startVerification(
      context: context,
      token: "your-token-here",
      userInfo: userInfo,
      customization: customization,
      environment: SkaletekEnvironment.dev,
      onComplete: (result) {
        setState(() {
          _isVerifying = false;
          _hasVerificationResult = true;
          final statusStr = result['status']?.toString();
          final message = result['message']?.toString();
          final errorCode = result['error_code']?.toString();

          if (result['success'] == true) {
            _outcome = _VerificationOutcome.success;
            _status = 'Verification completed successfully!';
          } else if (statusStr == KYCStatus.awaitReview.value) {
            _outcome = _VerificationOutcome.awaitReview;
            final b = StringBuffer(
              'Under review (status: ${KYCStatus.awaitReview.value})',
            );
            if (errorCode != null && errorCode.isNotEmpty) {
              b.write('\nError code: $errorCode');
            }
            if (message != null && message.isNotEmpty) b.write('\n$message');
            _status = b.toString();
          } else {
            _outcome = _VerificationOutcome.failure;
            final b = StringBuffer(
              'Verification failed (status: ${statusStr ?? 'Unknown'})',
            );
            if (errorCode != null && errorCode.isNotEmpty) {
              b.write('\nError code: $errorCode');
            }
            if (message != null && message.isNotEmpty) {
              b.write('\n$message');
            } else if (errorCode == null || errorCode.isEmpty) {
              b.write('\nNo additional details.');
            }
            _status = b.toString();
          }
        });
      },
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Skaletek KYC'),
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
      ),
      body: Padding(
        padding: const EdgeInsets.all(24.0),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            const Icon(Icons.verified_user, size: 80, color: Color(0xFF1261C1)),
            const SizedBox(height: 24),
            const Text(
              'Skaletek KYC SDK Demo',
              style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
            ),
            const SizedBox(height: 16),
            const Text(
              'This demo shows how to integrate the Skaletek KYC Flutter SDK for identity verification.',
              textAlign: TextAlign.center,
              style: TextStyle(fontSize: 16, color: Colors.grey),
            ),
            const SizedBox(height: 32),
            if (_isVerifying)
              const Column(
                children: [
                  CircularProgressIndicator(),
                  SizedBox(height: 16),
                  Text('Verification in progress...'),
                ],
              )
            else
              SizedBox(
                width: double.infinity,
                child: ElevatedButton(
                  onPressed: _startVerification,
                  style: ElevatedButton.styleFrom(
                    backgroundColor: const Color(0xFF1261C1),
                    foregroundColor: Colors.white,
                    padding: const EdgeInsets.symmetric(vertical: 16),
                    shape: RoundedRectangleBorder(
                      borderRadius: BorderRadius.circular(8),
                    ),
                  ),
                  child: const Text('Start Identity Verification'),
                ),
              ),

            const SizedBox(height: 20),
            if (_hasVerificationResult && _status.isNotEmpty)
              Container(
                width: double.infinity,
                padding: const EdgeInsets.all(16),
                decoration: BoxDecoration(
                  color: switch (_outcome) {
                    _VerificationOutcome.success => Colors.green[50],
                    _VerificationOutcome.awaitReview => Colors.amber[50],
                    _ => Colors.red[50],
                  },
                  borderRadius: BorderRadius.circular(8),
                  border: Border.all(
                    color: switch (_outcome) {
                      _VerificationOutcome.success => Colors.green,
                      _VerificationOutcome.awaitReview => Colors.amber.shade700,
                      _ => Colors.red,
                    },
                  ),
                ),
                child: Text(
                  _status,
                  textAlign: TextAlign.center,
                  style: TextStyle(
                    color: switch (_outcome) {
                      _VerificationOutcome.success => Colors.green[700],
                      _VerificationOutcome.awaitReview => Colors.amber.shade900,
                      _ => Colors.red[700],
                    },
                  ),
                ),
              ),
          ],
        ),
      ),
    );
  }
}