Skip to main content

smartverify_biometric 1.0.7 copy "smartverify_biometric: ^1.0.7" to clipboard
smartverify_biometric: ^1.0.7 copied to clipboard

Flutter biometric facial capture and anti-spoofing liveness verification SDK for SmartVerifyNG. Guides users through on-device liveness checks and validates captured faces against the SmartVerify liveness API.

example/lib/main.dart

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

void main() {
  WidgetsFlutterBinding.ensureInitialized();

  // Initialize once with your SmartVerifyNG PUBLIC key (never your secret key).
  SmartVerifyBiometric.initialize(
    publicKey: 'pk_live_replace_with_your_public_key',
    defaultThreshold: 65.0,
  );

  runApp(const SmartVerifyExampleApp());
}

/// Example application demonstrating [SmartVerifyBiometric].
class SmartVerifyExampleApp extends StatelessWidget {
  /// Creates a [SmartVerifyExampleApp].
  const SmartVerifyExampleApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'SmartVerify Biometric Demo',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: const Color(0xFF059669)),
        useMaterial3: true,
      ),
      home: const BiometricDemoHomePage(),
    );
  }
}

/// Home screen allowing developers to test biometric liveness capture.
class BiometricDemoHomePage extends StatefulWidget {
  /// Creates a [BiometricDemoHomePage].
  const BiometricDemoHomePage({super.key});

  @override
  State<BiometricDemoHomePage> createState() => _BiometricDemoHomePageState();
}

class _BiometricDemoHomePageState extends State<BiometricDemoHomePage> {
  final TextEditingController _publicKeyController = TextEditingController(
    text: 'pk_live_replace_with_your_public_key',
  );
  final TextEditingController _referenceController = TextEditingController(
    text: 'TXN_LIVE_DEMO_001',
  );

  SmartVerifyLivenessResult? _lastResult;
  String? _statusBanner;

  @override
  void dispose() {
    _publicKeyController.dispose();
    _referenceController.dispose();
    super.dispose();
  }

  Future<void> _launchBiometricCheck() async {
    final publicKey = _publicKeyController.text.trim();
    final reference = _referenceController.text.trim();

    try {
      SmartVerifyBiometric.initialize(
        publicKey: publicKey,
        defaultThreshold: 65.0,
      );
    } on ArgumentError catch (e) {
      setState(() {
        _statusBanner = e.message?.toString() ?? e.toString();
      });
      return;
    }

    setState(() => _statusBanner = null);

    await SmartVerifyBiometric.instance.startLivenessCheck(
      context: context,
      reference: reference.isEmpty ? null : reference,
      options: const SmartVerifyCaptureOptions(
        title: 'Face capture',
        allowRetryOnError: true,
      ),
      onComplete: (SmartVerifyLivenessResult result) {
        if (!mounted) return;
        setState(() {
          _lastResult = result;
          _statusBanner = result.message;
        });

        // Perform any follow-up actions in your app here (e.g. poll your
        // backend using result.reference). The full liveness verdict & score
        // are delivered exclusively to your server-side SmartVerify webhook.
      },
      onCancel: () {
        if (!mounted) return;
        setState(() {
          _statusBanner = 'Biometric capture was cancelled by the user.';
        });
      },
    );
  }

  @override
  Widget build(BuildContext context) {
    final theme = Theme.of(context);
    final result = _lastResult;

    return Scaffold(
      appBar: AppBar(
        title: const Text('SmartVerify Biometric Demo'),
        centerTitle: true,
      ),
      body: ListView(
        padding: const EdgeInsets.all(20),
        children: [
          TextField(
            controller: _publicKeyController,
            decoration: const InputDecoration(
              labelText: 'SmartVerify Public Key (pk_...)',
              border: OutlineInputBorder(),
              helperText: 'Use your public key only — secret keys are rejected.',
            ),
          ),
          const SizedBox(height: 16),
          TextField(
            controller: _referenceController,
            decoration: const InputDecoration(
              labelText: 'Custom Reference (optional)',
              border: OutlineInputBorder(),
              helperText:
                  'Use this reference to match the full result sent to your webhook.',
            ),
          ),
          const SizedBox(height: 20),
          SizedBox(
            height: 52,
            child: FilledButton.icon(
              onPressed: _launchBiometricCheck,
              icon: const Icon(Icons.face_retouching_natural_rounded),
              label: const Text('Start Biometric Liveness Check'),
            ),
          ),
          if (_statusBanner != null) ...[
            const SizedBox(height: 20),
            Container(
              padding: const EdgeInsets.all(14),
              decoration: BoxDecoration(
                color: (result?.isSuccess == true
                        ? Colors.green
                        : theme.colorScheme.error)
                    .withValues(alpha: 0.10),
                borderRadius: BorderRadius.circular(12),
                border: Border.all(
                  color: result?.isSuccess == true
                      ? Colors.green
                      : theme.colorScheme.error,
                ),
              ),
              child: Text(
                _statusBanner!,
                style: theme.textTheme.bodyMedium?.copyWith(
                  fontWeight: FontWeight.w600,
                ),
              ),
            ),
          ],
          if (result != null) ...[
            const SizedBox(height: 20),
            Card(
              child: Padding(
                padding: const EdgeInsets.all(16),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Text(
                      'Submission Status',
                      style: theme.textTheme.titleMedium?.copyWith(
                        fontWeight: FontWeight.bold,
                      ),
                    ),
                    const Divider(height: 20),
                    if (result.capturedImageBytes != null) ...[
                      Center(
                        child: ClipOval(
                          child: Image.memory(
                            result.capturedImageBytes!,
                            width: 112,
                            height: 112,
                            fit: BoxFit.cover,
                          ),
                        ),
                      ),
                      const SizedBox(height: 16),
                    ],
                    _kvRow('Status', result.status),
                    _kvRow('Submitted', '${result.isSuccess}'),
                    _kvRow('Provider Message', result.message),
                    if (result.reference != null)
                      _kvRow('Reference', result.reference!),
                    const SizedBox(height: 12),
                    Text(
                      'Full liveness verdict & score are delivered exclusively '
                      'to your server-side SmartVerify webhook.',
                      style: theme.textTheme.bodySmall?.copyWith(
                        color: theme.colorScheme.onSurfaceVariant,
                      ),
                    ),
                  ],
                ),
              ),
            ),
          ],
        ],
      ),
    );
  }

  Widget _kvRow(String label, String value) {
    return Padding(
      padding: const EdgeInsets.symmetric(vertical: 4),
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          SizedBox(
            width: 130,
            child: Text(
              label,
              style: const TextStyle(fontWeight: FontWeight.w600),
            ),
          ),
          Expanded(child: Text(value)),
        ],
      ),
    );
  }
}
2
likes
130
points
246
downloads
screenshot

Documentation

Documentation
API reference

Publisher

unverified uploader

Weekly Downloads

Flutter biometric facial capture and anti-spoofing liveness verification SDK for SmartVerifyNG. Guides users through on-device liveness checks and validates captured faces against the SmartVerify liveness API.

Homepage

Topics

#biometric #liveness #kyc #face-detection #verification

License

MIT (license)

Dependencies

camera, flutter, flutter_tts, google_mlkit_face_detection, http, image

More

Packages that depend on smartverify_biometric