applyConsent method Null safety
- String source,
- TikiSdkDestination destination,
- Function request,
- {void onBlocked(
- String
- 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);
}
}