asim_kyc 0.0.84 copy "asim_kyc: ^0.0.84" to clipboard
asim_kyc: ^0.0.84 copied to clipboard

Package Flutter để tích hợp chức năng xác thực KYC với nhận diện khuôn mặt, phát hiện ảnh giả và xác minh danh tính.

example/lib/main.dart

import 'dart:io';

import 'package:asim_kyc/asim_kyc.dart';
import 'package:camera/camera.dart';
import 'package:flutter/material.dart';

late List<CameraDescription> cameras;

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  cameras = await availableCameras();
  runApp(
    const MaterialApp(
      home: MyApp(),
    ),
  );
}

enum DocumentStep {
  CAMERA_FRONT('camera_front'),
  CAMERA_BACK('camera_back'),
  CAMERA_PASSPORT('camera_passport'),
  CAMERA_SELFIE('camera_selfie'),
  ;

  const DocumentStep(this.value);

  final String value;

  static DocumentStep getByValue(String i) {
    return DocumentStep.values.firstWhere((x) => x.value == i,
        orElse: () => DocumentStep.CAMERA_FRONT);
  }
}

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

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final controller = KycCameraController();

  DocumentStep doc = DocumentStep.CAMERA_SELFIE;

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'camerAwesome App',
      home: Scaffold(
        backgroundColor: Colors.black,
        extendBodyBehindAppBar: true,
        // appBar: AppBar(
        //   title: Text('Asim KYC Example - ${doc.value}'),
        // ),
        body: Stack(
          children: [
            StatefulBuilder(
              builder: (context, setState) {
                return AsimKYC(
                  cameras: cameras,
                  controller: controller,
                  cardIdDirection: getCardIdDirection(doc),
                  singleFaceMode: false,
                  onTakePhoto: (File file) {
                    // controller.onTakePhoto(
                    //     controller.currentDocumentStep.value, file);

                    // doc = DocumentStep.CAMERA_SELFIE;
                    showDialog(
                      context: context,
                      builder: (context) => AlertDialog(
                        title: const Text("Test"),
                        content: Image.file(
                          file,
                          fit: BoxFit.contain,
                        ),
                      ),
                    );
                    setState(() {});
                  },
                  // singleFaceMode: true,
                  setupString: AsimKYCSetup(),
                  onFaceDetection: (List<File>? files) async {
                    if ((files ?? []).length == 1) {
                      final imgFront = files![0];
                      showDialog(
                        context: context,
                        builder: (context) => AlertDialog(
                          title: const Text("Test"),
                          content: Row(
                            children: [
                              Expanded(
                                child: Image.file(
                                  imgFront,
                                  fit: BoxFit.contain,
                                ),
                              ),
                            ],
                          ),
                        ),
                      );
                      doc = DocumentStep.CAMERA_FRONT;
                      setState(() {});
                      return;
                    }
                    final imgL = files![0];
                    final imgFront = files![1];
                    final imgR = files![2];
                    // controller.disposeCameraAwesome();
                    showDialog(
                      context: context,
                      builder: (context) => AlertDialog(
                        title: const Text("Test"),
                        content: Row(
                          children: [
                            Expanded(
                              child: Image.file(
                                imgL,
                                fit: BoxFit.contain,
                              ),
                            ),
                            Expanded(
                              child: Image.file(
                                imgFront,
                                fit: BoxFit.contain,
                              ),
                            ),
                            Expanded(
                              child: Image.file(
                                imgR,
                                fit: BoxFit.contain,
                              ),
                            ),
                          ],
                        ),
                      ),
                    );
                    doc = DocumentStep.CAMERA_FRONT;
                    setState(() {});
                  },
                  onFaceProgress: (value) {
                    // controller.faceProgress(value);
                  },
                );
              },
            ),
            // Positioned(
            //   bottom: 0,
            //   left: 0,
            //   right: 0,
            //   child: Container(
            //     color: Colors.red,
            //     child: TextButton(
            //         onPressed: () {
            //           // controller.resetCamera();
            //           // controllerCamera = null;
            //
            //           doc = DocumentStep.CAMERA_SELFIE;
            //           setState(() {});
            //         },
            //         child: const Text('CAMERA_SELFIE')),
            //   ),
            // ),
            // Positioned(
            //   bottom: 30,
            //   left: 0,
            //   right: 0,
            //   child: Container(
            //     color: Colors.red,
            //     child: TextButton(
            //         onPressed: () async {
            //           controller.switchCameraAwesome();
            //           await Future.delayed(const Duration(milliseconds: 100));
            //           doc = DocumentStep.CAMERA_FRONT;
            //           setState(() {});
            //         },
            //         child: const Text('CAMERA_FRONT')),
            //   ),
            // ),
            // Positioned(
            //   bottom: 60,
            //   left: 0,
            //   right: 0,
            //   child: Container(
            //     color: Colors.red,
            //     child: TextButton(
            //         onPressed: () {
            //           // controller.disposeCameraAwesome();
            //           doc = DocumentStep.CAMERA_BACK;
            //           setState(() {});
            //         },
            //         child: const Text('CAMERA_BACK')),
            //   ),
            // )
          ],
        ),
        // body: CameraView(),
      ),
    );
  }

  CardIdDirection getCardIdDirection(DocumentStep currentDocumentStep) {
    switch (currentDocumentStep) {
      case DocumentStep.CAMERA_FRONT:
        return CardIdDirection.front;
      case DocumentStep.CAMERA_BACK:
        return CardIdDirection.back;
      case DocumentStep.CAMERA_PASSPORT:
        return CardIdDirection.front;
      case DocumentStep.CAMERA_SELFIE:
        return CardIdDirection.face;
    }
  }
}
1
likes
120
points
108
downloads

Publisher

unverified uploader

Weekly Downloads

Package Flutter để tích hợp chức năng xác thực KYC với nhận diện khuôn mặt, phát hiện ảnh giả và xác minh danh tính.

Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

camera, flutter, flutter_screenutil, flutter_svg, google_mlkit_face_detection, image, just_audio, path, path_provider

More

Packages that depend on asim_kyc