ekyc_plugin 1.0.6 copy "ekyc_plugin: ^1.0.6" to clipboard
ekyc_plugin: ^1.0.6 copied to clipboard

A Flutter plugin that provides native eKYC functionality for Android and iOS. Features include face liveness detection, camera flash support, and document verification with seamless integration into F [...]

example/lib/main.dart

// main.dart
import 'dart:io';

import 'package:ekyc_plugin_example/face_authentications.dart';
import 'package:ekyc_plugin_example/face_ekyc_page.dart';
import 'package:ekyc_plugin_example/card_ekyc_page.dart';
import 'package:ekyc_plugin_example/helpers/permission_helper.dart';
import 'package:flutter/material.dart';

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      routes: {
        '/': (context) => const HomePage(),
        '/face_ekyc': (context) => const FaceEKycPage(),
        '/card_ekyc': (context) => const CardEKycPage(),
      },
      onGenerateRoute: (settings) {
        if (settings.name == '/face_authentications') {
          final args = settings.arguments as Map<String, dynamic>?;
          final userId = args?['userId'] as String?;
          return MaterialPageRoute(
            builder: (_) => FaceAuthentications(userId: userId ?? ''),
          );
        }
        return null;
      },
      initialRoute: '/',
    );
  }
}

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

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

class _HomePageState extends State<HomePage> {
  final TextEditingController _controller = TextEditingController();

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  void _navigateToFaceAuth() async {
    // Unfocus keyboard first
    FocusScope.of(context).unfocus();

    final userId = _controller.text.trim();
    if (userId.isEmpty) {
      ScaffoldMessenger.of(context).showSnackBar(
        const SnackBar(
          content: Text('Please enter a user ID'),
        ),
      );
      return;
    }

    // Navigate và chờ quay lại
    await Navigator.of(context).pushNamed(
      '/face_authentications',
      arguments: {'userId': userId},
    );

    // Unfocus khi quay lại từ màn FaceAuthentications
    if (mounted) {
      FocusScope.of(context).unfocus();
    }
  }

  Future<void> _navigateToFaceEKyc() async {
    // Check camera permission first
    if (Platform.isAndroid) {
      final hasPermission =
          await PermissionHelper.requestCameraPermission(context);
      if (!hasPermission) return;
    }

    if (mounted) {
      Navigator.of(context).pushNamed('/face_ekyc');
    }
  }

  Future<void> _navigateToCardEKyc() async {
    // Check camera permission first
    if (Platform.isAndroid) {
      final hasPermission =
          await PermissionHelper.requestCameraPermission(context);
      if (!hasPermission) return;
    }

    if (mounted) {
      Navigator.of(context).pushNamed('/card_ekyc');
    }
  }

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () => FocusScope.of(context).unfocus(),
      child: Scaffold(
        body: Container(
          decoration: const BoxDecoration(
            gradient: LinearGradient(
              begin: Alignment.topLeft,
              end: Alignment.bottomRight,
              colors: [
                Color(0xFF667eea),
                Color(0xFF764ba2),
              ],
            ),
          ),
          child: SafeArea(
            child: SingleChildScrollView(
              padding: const EdgeInsets.all(24.0),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.stretch,
                children: [
                  const SizedBox(height: 40),

                  // Header
                  Column(
                    children: [
                      Container(
                        padding: const EdgeInsets.all(16),
                        decoration: BoxDecoration(
                          color: Colors.white.withOpacity(0.2),
                          shape: BoxShape.circle,
                        ),
                        child: const Icon(
                          Icons.verified_user,
                          size: 64,
                          color: Colors.white,
                        ),
                      ),
                      const SizedBox(height: 16),
                      const Text(
                        'eKYC Plugin',
                        style: TextStyle(
                          fontSize: 32,
                          fontWeight: FontWeight.bold,
                          color: Colors.white,
                          letterSpacing: 1.2,
                        ),
                      ),
                      const SizedBox(height: 8),
                      Text(
                        'Xác thực danh tính nhanh chóng & an toàn',
                        textAlign: TextAlign.center,
                        style: TextStyle(
                          fontSize: 16,
                          color: Colors.white.withOpacity(0.9),
                        ),
                      ),
                    ],
                  ),

                  const SizedBox(height: 48),

                  // Face Authentication Card
                  _buildFeatureCard(
                    title: 'Xác thực khuôn mặt',
                    subtitle: 'Nhập User ID để bắt đầu',
                    icon: Icons.face_rounded,
                    color: const Color(0xFF4A90E2),
                    child: Column(
                      children: [
                        TextField(
                          controller: _controller,
                          textInputAction: TextInputAction.done,
                          onSubmitted: (_) => _navigateToFaceAuth(),
                          style: const TextStyle(fontSize: 16),
                          decoration: InputDecoration(
                            filled: true,
                            fillColor: Colors.grey[50],
                            border: OutlineInputBorder(
                              borderRadius: BorderRadius.circular(12),
                              borderSide: BorderSide.none,
                            ),
                            labelText: 'User ID',
                            hintText: 'Ví dụ: son',
                            prefixIcon: const Icon(Icons.person_outline),
                            contentPadding: const EdgeInsets.symmetric(
                              horizontal: 16,
                              vertical: 16,
                            ),
                          ),
                        ),
                        const SizedBox(height: 16),
                        SizedBox(
                          width: double.infinity,
                          height: 52,
                          child: ElevatedButton(
                            onPressed: _navigateToFaceAuth,
                            style: ElevatedButton.styleFrom(
                              backgroundColor: const Color(0xFF4A90E2),
                              foregroundColor: Colors.white,
                              elevation: 0,
                              shape: RoundedRectangleBorder(
                                borderRadius: BorderRadius.circular(12),
                              ),
                            ),
                            child: const Text(
                              'Bắt đầu xác thực',
                              style: TextStyle(
                                fontSize: 16,
                                fontWeight: FontWeight.w600,
                              ),
                            ),
                          ),
                        ),
                      ],
                    ),
                  ),

                  const SizedBox(height: 24),

                  // eKYC Features Section
                  const Text(
                    'Tính năng eKYC',
                    style: TextStyle(
                      fontSize: 20,
                      fontWeight: FontWeight.bold,
                      color: Colors.white,
                    ),
                  ),
                  const SizedBox(height: 16),

                  // Face eKYC Card
                  _buildActionCard(
                    title: 'Face eKYC',
                    subtitle: 'Xác thực khuôn mặt thông minh',
                    icon: Icons.face_retouching_natural,
                    gradient: const LinearGradient(
                      colors: [Color(0xFF11998e), Color(0xFF38ef7d)],
                    ),
                    onTap: _navigateToFaceEKyc,
                  ),

                  const SizedBox(height: 16),

                  // Card eKYC Card
                  _buildActionCard(
                    title: 'Card eKYC',
                    subtitle: 'Quét CCCD/Passport tự động',
                    icon: Icons.credit_card_rounded,
                    gradient: const LinearGradient(
                      colors: [Color(0xFFFF6B6B), Color(0xFFFFE66D)],
                    ),
                    onTap: _navigateToCardEKyc,
                  ),

                  const SizedBox(height: 32),
                ],
              ),
            ),
          ),
        ),
      ),
    );
  }

  Widget _buildFeatureCard({
    required String title,
    required String subtitle,
    required IconData icon,
    required Color color,
    required Widget child,
  }) {
    return Container(
      padding: const EdgeInsets.all(24),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(20),
        boxShadow: [
          BoxShadow(
            color: Colors.black.withOpacity(0.1),
            blurRadius: 20,
            offset: const Offset(0, 10),
          ),
        ],
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Row(
            children: [
              Container(
                padding: const EdgeInsets.all(12),
                decoration: BoxDecoration(
                  color: color.withOpacity(0.1),
                  borderRadius: BorderRadius.circular(12),
                ),
                child: Icon(icon, color: color, size: 28),
              ),
              const SizedBox(width: 16),
              Expanded(
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Text(
                      title,
                      style: const TextStyle(
                        fontSize: 18,
                        fontWeight: FontWeight.bold,
                        color: Colors.black87,
                      ),
                    ),
                    const SizedBox(height: 4),
                    Text(
                      subtitle,
                      style: const TextStyle(
                        fontSize: 14,
                        color: Colors.black54,
                      ),
                    ),
                  ],
                ),
              ),
            ],
          ),
          const SizedBox(height: 24),
          child,
        ],
      ),
    );
  }

  Widget _buildActionCard({
    required String title,
    required String subtitle,
    required IconData icon,
    required Gradient gradient,
    required VoidCallback onTap,
  }) {
    return Material(
      color: Colors.transparent,
      child: InkWell(
        onTap: onTap,
        borderRadius: BorderRadius.circular(16),
        child: Container(
          padding: const EdgeInsets.all(20),
          decoration: BoxDecoration(
            gradient: gradient,
            borderRadius: BorderRadius.circular(16),
            boxShadow: [
              BoxShadow(
                color: Colors.black.withOpacity(0.15),
                blurRadius: 15,
                offset: const Offset(0, 8),
              ),
            ],
          ),
          child: Row(
            children: [
              Container(
                padding: const EdgeInsets.all(12),
                decoration: BoxDecoration(
                  color: Colors.white.withOpacity(0.3),
                  borderRadius: BorderRadius.circular(12),
                ),
                child: Icon(icon, color: Colors.white, size: 32),
              ),
              const SizedBox(width: 16),
              Expanded(
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Text(
                      title,
                      style: const TextStyle(
                        fontSize: 18,
                        fontWeight: FontWeight.bold,
                        color: Colors.white,
                      ),
                    ),
                    const SizedBox(height: 4),
                    Text(
                      subtitle,
                      style: TextStyle(
                        fontSize: 14,
                        color: Colors.white.withOpacity(0.9),
                      ),
                    ),
                  ],
                ),
              ),
              Icon(
                Icons.arrow_forward_ios,
                color: Colors.white.withOpacity(0.8),
                size: 20,
              ),
            ],
          ),
        ),
      ),
    );
  }
}
0
likes
130
points
210
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter plugin that provides native eKYC functionality for Android and iOS. Features include face liveness detection, camera flash support, and document verification with seamless integration into Flutter apps.

Repository (GitHub)
View/report issues

Topics

#ekyc #kyc #face-detection #liveness-detection #biometric

Documentation

Documentation
API reference

License

MIT (license)

Dependencies

bridge_native, flutter, plugin_platform_interface

More

Packages that depend on ekyc_plugin

Packages that implement ekyc_plugin