validatePassport method

Future<void> validatePassport(
  1. String base64Image
)

Implementation

Future<void> validatePassport(String base64Image) async {
  setState(() {
    loading = true;
    progress = 0.0;
    percentage = 0.0;
  });

  final data = {
    'image': base64Image,
    'profile': widget.profile,
    'simulate_success': true,
    'email': widget.email,
    'phonenumber': widget.phonenumber,
    'name': widget.name,
    'id_number': widget.idNumber,
  };

  // Simulate progress for demonstration purposes
  Timer.periodic(const Duration(milliseconds: 100), (timer) {
    setState(() {
      progress += 0.1;
      percentage = progress * 100;
    });

    if (progress >= 1.0) {
      timer.cancel();
    }
  });

  try {
    final url = Uri.parse('${AppConfig.apiBaseUrl}${Endpoints.idVerify}');
    final response = await http.post(
      url,
      headers: {
        'Content-Type': 'application/json',
        'Authorization': 'Bearer ${widget.apiKey}',
      },
      body: jsonEncode(data),
    );

    if (response.statusCode == 200) {
      setState(() {
        isSuccess = true;
        successData = response.body;
      });
    } else {
      final responseData = jsonDecode(response.body);
      setState(() {
        isError = true;
        errorMessage = responseData["message"];
      });
    }
  } catch (e) {
    setState(() {
      isError = true;
      errorMessage =
          "Please ensure you're connected to the internet and retry.";
    });
  } finally {
    setState(() {
      selected = false;
      loading = false;
      imagePath = "";
    });
  }
}