asim_kyc 0.0.79 copy "asim_kyc: ^0.0.79" to clipboard
asim_kyc: ^0.0.79 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';
import 'package:flutter_native_image/flutter_native_image.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;

  Future<File> resizeImage(String imgPath) async {
    File _file = File(imgPath);

    ///Resize Image
    try {
      var bytes = await _file.readAsBytes();
      print("bytes ${bytes.length}");
      if (bytes.length > 1500000) {
        ImageProperties properties =
            await FlutterNativeImage.getImageProperties(_file.path);
        var x = bytes.length / 1500000;
        _file = await FlutterNativeImage.compressImage(_file.path,
            quality: 100,
            percentage: 100,
            targetWidth: properties.width! ~/ x,
            targetHeight: properties.height! ~/ x);
        bytes = await _file.readAsBytes();

        _file.lengthSync();
      }
    } catch (e) {
      return _file;
    }
    return _file;
  }

  // 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,
        body: Stack(
          children: [
            StatefulBuilder(
              builder: (context, setState) {
                return AsimKYC(
                  cameras: cameras,
                  controller: controller,
                  cardIdDirection: getCardIdDirection(doc),
                  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(() {});
                  },
                  setupString: AsimKYCSetup(),
                  onFaceDetection: (List<File>? files) async {
                    final imgL = await resizeImage(files![0].path);
                    final imgFront = await resizeImage(files![1].path);
                    final imgR = await resizeImage(files![2].path);
                    // 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
0
points
71
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)
View/report issues

License

unknown (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