objectScannedV5 method

  1. @override
Future<Either<Failure, ScanResponseModel>> objectScannedV5(
  1. XFile photo,
  2. String accessToken, {
  3. String? email,
})
override

Implementation

@override
Future<Either<Failure, ScanResponseModel>> objectScannedV5(
    XFile photo, String accessToken,
    {String? email}) async {
  try {
    final formData = FormData.fromMap({
      'file': await MultipartFile.fromFile(photo.path, filename: photo.name),
    });
    final options = Options(headers: {
      "Authorization": "Bearer $accessToken",
      "X-GATHERER-USER-EMAIL": email ?? ""
    });
    final response = await dio.post(
      '$baseUrl/v5/scanner/scan_image',
      options: options,
      data: formData,
    );
    if (response.statusCode == 201) {
      return Right(ScanResponseModel.fromJson(response.data));
    } else if (response.statusCode == 200) {
      return Right(ScanResponseModel.fromJson(jsonDecode(response.data)));
    } else {
      return Left(GetItemByIDRemoteFailure());
    }
  } catch (e) {
    return Left(GetItemByIDRemoteFailure());
  }
}