applyConsent method Null safety

Future<void> applyConsent(
  1. String source,
  2. TikiSdkDestination destination,
  3. Function request,
  4. {void onBlocked(
    1. String
    )?,
  5. String? origin}
)

Apply consent for a given source and destination.

If consent exists for the destination and is not expired, request will be executed. Else onBlocked is called.

Implementation

Future<void> applyConsent(
    String source, TikiSdkDestination destination, Function request,
    {void Function(String)? onBlocked, String? origin}) async {
  try {
    OwnershipModel? ownership =
        _ownershipService.getBySource(source, origin: origin);
    if (ownership == null) {
      if (onBlocked != null) onBlocked('No ownership');
      return;
    }
    ConsentModel? consentModel =
        _consentService.getByOwnershipId(ownership.transactionId!);
    if (consentModel == null) {
      if (onBlocked != null) onBlocked('No consent');
      return;
    }
    if (_checkConsent(consentModel, destination)) {
      request();
    } else {
      if (onBlocked != null) onBlocked(source);
    }
  } catch (e) {
    if (onBlocked != null) onBlocked(source);
  }
}