exec method

Future<DateTime?> exec(
  1. {required XFile photo}
)

Implementation

Future<DateTime?> exec({
  required XFile photo,
}) async {
  try {
    final photoData = await photo.readAsBytes();

    final tags = await readExifFromBytes(photoData);
    final dateTimeTag = tags['Image DateTime'];

    if (dateTimeTag == null) {
      return null;
    }

    final dateTimeString =
        _convertExifToStandardFormat(dateTimeTag.toString());

    final dateTime = DateTime.parse(dateTimeString);

    return dateTime;
  } catch (_) {
    throw ServiceException(
      ServiceErrorType.invalidImageFormat,
      ServiceErrorType.invalidImageFormat.message,
    );
  }
}