process method

Future<List<Map<String, String?>>> process({
  1. required String text,
  2. required XFile file,
  3. required BuildContext context,
  4. required dynamic png,
  5. required dynamic confidenceMap,
  6. String? cardType,
})

Implementation

Future<List<Map<String, String?>>> process(
    {required String text,
    required XFile file,
    required BuildContext context,
    required final png,
    required confidenceMap,
    String? cardType}) async {
  Map<String, String?> idCardData = idCardModel.textToIdCard(
    text,
    inputName: name,
    inputFatherName: fatherName,
    inputCountry: country,
    inputGender: gender,
    inputIdCardNumber: idCardNumber,
    inputBirthDate: birthDate,
    inputExpiryDate: expiryDate,
    inputIssueDate: issueDate,
  );

  // Map<String, String?> idCardDataClone = Map.from(idCardData);

  name = idCardData['name'] ?? name;
  fatherName = idCardData['father_name'] ?? fatherName;
  idCardNumber = idCardData['id_card_number'] ?? idCardNumber;
  expiryDate = idCardData['date_of_expiry'] ?? expiryDate;
  issueDate = idCardData['date_of_issue'] ?? issueDate;
  birthDate = idCardData['date_of_birth'] ?? birthDate;
  gender = idCardData['gender'] ?? gender;
  country = idCardData['country'] ?? country;

  List<Map<String, String?>> idCardDataWithConfidence = [
    {
      'name': idCardData['name'] ?? name,
      'confidence':
          getConfidence(confidenceMap, idCardData['name'] ?? name ?? '')
              .toString()
    },
    {
      'father_name': idCardData['father_name'] ?? fatherName,
      'confidence': getConfidence(
              confidenceMap, idCardData['father_name'] ?? fatherName ?? '')
          .toString()
    },
    {
      'id_card_number': idCardData['id_card_number'] ?? idCardNumber,
      'confidence': getConfidence(confidenceMap,
              idCardData['id_card_number'] ?? idCardNumber ?? '')
          .toString()
    },
    {
      'date_of_expiry': idCardData['date_of_expiry'] ?? expiryDate,
      'confidence': getConfidence(
              confidenceMap, idCardData['date_of_expiry'] ?? expiryDate ?? '')
          .toString()
    },
    {
      'date_of_issue': idCardData['date_of_issue'] ?? issueDate,
      'confidence': getConfidence(
              confidenceMap, idCardData['date_of_issue'] ?? issueDate ?? '')
          .toString()
    },
    {
      'date_of_birth': idCardData['date_of_birth'] ?? birthDate,
      'confidence': getConfidence(
              confidenceMap, idCardData['date_of_birth'] ?? birthDate ?? '')
          .toString()
    },
    {
      'gender': idCardData['gender'] ?? gender,
      'confidence':
          getConfidence(confidenceMap, idCardData['gender'] ?? gender ?? '')
              .toString()
    },
    {
      'country': idCardData['country'] ?? country ?? '',
      'confidence':
          getConfidence(confidenceMap, idCardData['country'] ?? country ?? '')
              .toString()
    }
  ];

  // if (idCardData.values.any((element) => element == null)) {
  //   return 0;
  // } else {
  //   return 1;
  // }
  return idCardDataWithConfidence;

  // if (idCardData.values.any((element) => element == null)) {
  //   return 0;
  // } else {
  //   // final contours = dylib.lookupFunction<Void Function(Pointer<Utf8>),
  //   //     void Function(Pointer<Utf8>)>('Contours');
  //   try {
  //     if (!(text.toLowerCase().contains('name') ||
  //         text.toLowerCase().contains('father') ||
  //         text.toLowerCase().contains('gender') ||
  //         text.toLowerCase().contains('country'))) {
  //       // profileController.message.value == null;
  //       // if (captureBackSide) {
  //       // contours(file.path.toNativeUtf8());
  //       // backImage = Image.file(File(XFile(file.path).path));
  //       if (backImage == null) {
  //         // if (contoursDetection != null) {
  //         //   contoursDetection(file.path.toNativeUtf8());
  //         // }
  //         backImage = Image.file(File(XFile(file.path).path));
  //
  //         // var png =
  //         //     img.encodePng((await utils.detectObjectsCropSaveImage(file))!);
  //         //
  //         // Uint8List bytes = Uint8List.fromList(png);
  //         // backImage = Image(
  //         //   image: MemoryImage(bytes),
  //         // );
  //       }
  //       // }
  //       // Future.delayed(const Duration(seconds: 2)).then((value) {
  //       //   captureBackSide = true;
  //       // });
  //       // return 0;
  //     } else {
  //       if (!isFrontCaptured) {
  //         // contours(file.path.toNativeUtf8());
  //         // frontImage = Image.file(File(XFile(file.path).path));
  //         // frontImage = await utils.detectObjectsCropSaveImage(file.path);
  //         // int i = 0;
  //         img.Image? cropped;
  //         // while (cropped != null || i < 3) {
  //         //   i++;
  //         cropped = await utils.detectObjectsCropSaveImage(file);
  //         if (cropped != null) {
  //           var png = img.encodePng(cropped);
  //           Uint8List bytes = Uint8List.fromList(png);
  //           // file = XFile.fromData(bytes);
  //           // XFile result = XFile.fromData(bytes).;
  //           // File res2 = File.fromRawPath(bytes);
  //           // contours(file.path.toNativeUtf8());
  //           // frontImage = Image.file(File(file.path));
  //           frontImage = Image(image: MemoryImage(bytes));
  //
  //           // frontImage = Image(image: MemoryImage(bytes));
  //           isFrontCaptured = true;
  //           Future.delayed(const Duration(milliseconds: 500));
  //         }
  //         // }
  //       }
  //       retry++;
  //       if (retry == 3) {
  //         return 3;
  //       }
  //
  //       return 2;
  //     }
  //
  //     // Navigator.pushReplacement((context), MaterialPageRoute(builder: (_) {
  //     //   return IdCardProfile(
  //     //       image: png,
  //     //       cardImage: frontImage,
  //     //       backSide: backImage,
  //     //       idCardData: idCardData,
  //     //       cardType: 'Id Card');
  //     // }));
  //   } catch (e) {
  //     print('-------------------------exception');
  //     // Navigator.pushReplacement(context, MaterialPageRoute(builder: (_) {
  //     //   return IdCardProfile(
  //     //       image: png,
  //     //       cardImage: frontImage,
  //     //       backSide: backImage,
  //     //       idCardData: idCardData,
  //     //       cardType: 'Id Card');
  //     // }));
  //   }
  // }
  // return 1;
}