Reference

This section is a comprehensive reference of the methods and events exposed by the Flutter SDK that you can leverage in your application.
These methods are accessible in the DidomiSdk class. Also make sure to always call the SDK after it is fully initialized (see onReady).

addEventListener

Add an event listener to catch events triggered by the SDK. Events listeners allow you to react to different events of interest. This function is safe to call before the ready event has been triggered.
Requires SDK to be initialized
No.
Parameters
Name
Type
Description
eventListener
EventListener
The event listener. An instance ofEventListener
Returns
Nothing
Example
Dart
EventListener didomiListener = EventListener();
// SDK lifecycle events
didomiListener.onReady = () {
onEvent("SDK Ready");
};
didomiListener.onError = (message) {
onEvent("Error : $message");
};
// Notice events
didomiListener.onShowNotice = () {
onEvent("Notice displayed");
};
didomiListener.onHideNotice = () {
onEvent("Notice hidden");
};
didomiListener.onShowPreferences = () {
onEvent("Preferences screen displayed");
};
didomiListener.onHidePreferences = () {
onEvent("Preferences screen hidden");
};
didomiListener.onNoticeClickAgree = () {
onEvent("Click Agree from Notice");
};
didomiListener.onNoticeClickDisagree = () {
onEvent("Click Disagree from Notice");
};
didomiListener.onNoticeClickViewVendors = () {
onEvent("Click View vendors from Notice");
};
didomiListener.onNoticeClickViewSPIPurposes = () {
onEvent("Click View SPI from Notice");
};
didomiListener.onNoticeClickMoreInfo = () {
onEvent("Click More info from Notice");
};
didomiListener.onNoticeClickPrivacyPolicy = () {
onEvent("Click Privacy policy from Notice");
};
// Preferences screen events
didomiListener.onPreferencesClickAgreeToAll = () {
onEvent("Click Agree to all from Preferences");
};
didomiListener.onPreferencesClickDisagreeToAll = () {
onEvent("Click Disagree to all from Preferences");
};
didomiListener.onPreferencesClickPurposeAgree = (purposeId) {
onEvent("Click Agree to purpose $purposeId from Preferences");
};
didomiListener.onPreferencesClickPurposeDisagree = (purposeId) {
onEvent("Click Disagree to purpose $purposeId from Preferences");
};
didomiListener.onPreferencesClickCategoryAgree = (categoryId) {
onEvent("Click Agree to category $categoryId from Preferences");
};
didomiListener.onPreferencesClickCategoryDisagree = (categoryId) {
onEvent("Click Disagree to category $categoryId from Preferences");
};
didomiListener.onPreferencesClickViewVendors = () {
onEvent("Click View vendors from Preferences");
};
didomiListener.onPreferencesClickViewSPIPurposes = () {
onEvent("Click View SPI from Preferences");
};
didomiListener.onPreferencesClickSaveChoices = () {
onEvent("Click Save choices from Preferences");
};
didomiListener.onPreferencesClickAgreeToAllPurposes = () {
onEvent("Click Agree to all purposes from Preferences");
};
didomiListener.onPreferencesClickDisagreeToAllPurposes = () {
onEvent("Click Disagree to all purposes from Preferences");
};
didomiListener.onPreferencesClickResetAllPurposes = () {
onEvent("Click Reset all purposes from Preferences");
};
// Vendors screen events
didomiListener.onPreferencesClickVendorAgree = (vendorId) {
onEvent("Click Agree to vendor $vendorId from Preferences");
};
didomiListener.onPreferencesClickVendorDisagree = (vendorId) {
onEvent("Click Disagree to vendor $vendorId from Preferences");
};
didomiListener.onPreferencesClickVendorSaveChoices = () {
onEvent("Click Save vendor choices from Preferences");
};
didomiListener.onPreferencesClickViewPurposes = () {
onEvent("Click View purposes from Preferences");
};
didomiListener.onPreferencesClickAgreeToAllVendors = () {
onEvent("Click Agree to all vendors from Preferences");
};
didomiListener.onPreferencesClickDisagreeToAllVendors = () {
onEvent("Click Disagree to all vendors from Preferences");
};
// SPI screen events
didomiListener.onPreferencesClickSPIPurposeAgree = (purposeId) {
onEvent("Click Agree to SPI purpose $purposeId from Preferences");
};
didomiListener.onPreferencesClickSPIPurposeDisagree = (purposeId) {
onEvent("Click Disagree to SPI purpose $purposeId from Preferences");
};
didomiListener.onPreferencesClickSPICategoryAgree = (categoryId) {
onEvent("Click Agree to SPI category $categoryId from Preferences");
};
didomiListener.onPreferencesClickSPICategoryDisagree = (categoryId) {
onEvent("Click Disagree to SPI category $categoryId from Preferences");
};
didomiListener.onPreferencesClickSPIPurposeSaveChoices = () {
onEvent("Click Save SPI choices from Preferences");
};
// Consent events
didomiListener.onConsentChanged = () {
onEvent("Consent has changed");
};
didomiListener.onSyncDone = (organizationUserId) {
onEvent("Sync has been done for user $organizationUserId");
};
didomiListener.onSyncError = (error) {
onEvent("Sync failed with error $error");
};
// Language change events
didomiListener.onLanguageUpdated = (languageCode) {
onEvent("Language has changed ($languageCode)");
};
didomiListener.onLanguageUpdateFailed = (reason) {
onEvent("Language has not changed: $reason");
};
DidomiSdk.addEventListener(didomiListener);
Event types
The following events are supported by the Didomi SDK:
Method
Description
onReady
When the SDK is ready.
onError
When the SDK encountered an error (message provided as parameter).
onShowNotice
When the consent notice gets displayed. If you have disabled our default consent notices to replace them with your own, you need to show your custom notice when this event gets triggered.
onHideNotice
When the consent notice is hidden. If you have disabled our default consent notice to replace it with your own, you need to hide your custom notice when this event gets triggered.
onShowPreferences
When the preferences screen is displayed.
onHidePreferences
When the preferences screen is hidden.
onNoticeClickAgree
When user clicks on agree on the notice.
onNoticeClickDisagree
When user clicks on disagree on the notice.
onNoticeClickViewVendors
When user clicks on partners on the notice.
onNoticeClickViewSPIPurposes
When user clicks on view Sensitive Personal Information on the preferences popup.
onNoticeClickMoreInfo
When user clicks on learn more on the notice.
onNoticeClickPrivacyPolicy
When user clicks on privacy policy on the notice.
onPreferencesClickAgreeToAll
When user clicks on agree to all on the preferences popup.
onPreferencesClickDisagreeToAll
When user clicks on disagree to all on the preferences popup.
onPreferencesClickPurposeAgree
When user agree to a purpose on the preferences popup (purposeId provided as parameter).
onPreferencesClickPurposeDisagree
When user disagree to a purpose on the preferences popup (purposeId provided as parameter).
onPreferencesClickCategoryAgree
When user agree to a category on the preferences popup (categoryId provided as parameter).
onPreferencesClickCategoryDisagree
When user disagree to a category on the preferences popup (categoryId provided as parameter).
onPreferencesClickViewVendors
When user clicks on view vendors on the preferences popup.
onPreferencesClickViewSPIPurposes
When user clicks on view Sensitive Personal Information on the preferences popup.
onPreferencesClickSaveChoices
When user saves his choice on the preferences popup.
onPreferencesClickAgreeToAllPurposes
When user flips ON all purposes switch on the preferences popup.
onPreferencesClickDisagreeToAllPurposes
When user flips OFF all purposes switch on the preferences popup.
onPreferencesClickResetAllPurposes
When user reset all purposes switch on the preferences popup.
onPreferencesClickVendorAgree
When user agree to a vendor on the preferences popup (vendorId provided as parameter).
onPreferencesClickVendorDisagree
When user disagree to a vendor on the preferences popup (vendorId provided as parameter).
onPreferencesClickVendorSaveChoices
When user saves his choice on the vendors view on the preferences popup.
onPreferencesClickViewPurposes
When user clicks on view purposes on the preferences popup.
onPreferencesClickAgreeToAllVendors
When user flips ON all vendors switch on the preferences popup.
onPreferencesClickDisagreeToAllVendors
When user flips OFF all vendors switch on the preferences popup.
onPreferencesClickSPIPurposeAgree
When user agree to a purpose on the Sensitive Personal Information view from the preferences popup (purposeId provided as parameter).
onPreferencesClickSPIPurposeDisagree
When user disagree to a purpose on the Sensitive Personal Information view from the preferences popup (purposeId provided as parameter).
onPreferencesClickSPICategoryAgree
When user agree to a category on the Sensitive Personal Information view from the preferences popup (categoryId provided as parameter).
onPreferencesClickSPICategoryDisagree
When user disagree to a category on the Sensitive Personal Information view from preferences popup (categoryId provided as parameter).
onPreferencesClickSPIPurposeSaveChoices
When user saves his choice on the Sensitive Personal Information view from preferences popup.
onConsentChanged
When a consent is given or withdrawn by the user. Only triggered when the consent status actually changes (ie if the user saves consents without adding/removing any consent then this does not get called).
onSyncDone
When the consent synchronization is successful (organizationUserId provided as parameter).
onSyncError
When the consent synchronization has failed (error provided as parameter).
onLanguageUpdated
When the language has changed (languageCode provided as parameter).
onLanguageUpdateFailed
When the language change has failed (reason provided as parameter).

getDisabledPurposes

Deprecated, use getUserStatus instead.
The result of this method has been replaced by userStatus.purposes?.consent?.disabled.
Get the list of purposes that have been disabled by the user.
Requires SDK to be initialized
Yes.
Parameters
No parameter.
Returns
Type
Description
Future<List<Purpose>>
A list of type Purpose containing the purposes disabled by the user.
Example
Dart
await DidomiSdk.getDisabledPurposes();

getDisabledPurposeIds

Deprecated, use getUserStatus instead.
The result of this method has been replaced by userStatus.purposes?.consent?.disabled.
Get the list of purpose IDs that have been disabled by the user.
Requires SDK to be initialized
Yes.
Parameters
No parameter.
Returns
Type
Description
Future<List<String>>
A list of type String containing the IDs of purposes disabled by the user.
Example
Dart
await DidomiSdk.getDisabledPurposeIds()

getDisabledVendors

Deprecated, use getUserStatus instead.
The result of this method has been replaced by userStatus.vendors?.consent?.disabled.
Get the list of vendors that have been disabled by the user.
Requires SDK to be initialized
Yes.
Parameters
No parameter.
Returns
Type
Description
Future<List<Vendor>>
A list of type Vendor containing the vendors disabled by the user.
Example
Dart
await DidomiSdk.getDisabledVendors();

getDisabledVendorIds

Deprecated, use getUserStatus instead.
The result of this method has been replaced by userStatus.vendors?.consent?.disabled.
Get the list of vendor IDs that have been disabled by the user.
Requires SDK to be initialized
Yes.
Parameters
No parameter.
Returns
Type
Description
Future<List<String>>
A list of type String containing the IDs of vendors disabled by the user.
Example
Dart
await DidomiSdk.getDisabledVendorIds();

getEnabledPurposes

Deprecated, use getUserStatus instead.
The result of this method has been replaced by userStatus.purposes?.global?.enabled.
Get the list of purposes that have been enabled by the user.
Requires SDK to be initialized
Yes.
Parameters
No parameter.
Returns
Type
Description
Future<List<Purpose>>
A list of type Purpose containing the purposes enabled by the user.
Example
Dart
await DidomiSdk.getEnabledPurposes();

getEnabledPurposeIds

Deprecated, use getUserStatus instead.
The result of this method has been replaced by userStatus.purposes?.global?.enabled.
Get the list of purpose IDs that have been enabled by the user.
Requires SDK to be initialized
Yes.
Parameters
No parameter.
Returns
Type
Description
Future<List<String>>
A list of type String containing the IDs of purposes enabled by the user.
Example
Dart
await DidomiSdk.getEnabledPurposeIds();

getEnabledVendors

Deprecated, use getUserStatus instead.
The result of this method has been replaced byuserStatus.vendors?.consent?.enabled.
Get the list of vendors that have been enabled by the user.
Requires SDK to be initialized
Yes.
Parameters
No parameter.
Returns
Type
Description
Future<List<Vendor>>
A list of type Vendor containing the vendors enabled by the user.
Example
Dart
await DidomiSdk.getEnabledVendors();

getEnabledVendorIds

Deprecated, use getUserStatus instead.
The result of this method has been replaced by userStatus.vendors?.consent?.enabled.
Get the list of vendor IDs that have been enabled by the user.
Requires SDK to be initialized
Yes.
Parameters
No parameter.
Returns
Type
Description
Future<List<String>>
A list of type String containing the IDs of vendors enabled by the user.
Example
Dart
await DidomiSdk.getEnabledVendorIds();

getJavaScriptForWebView

Get JavaScript to embed into a WebView to pass the consent status from the app to the Didomi Web SDK embedded into the WebView.
Inject the returned tag into a WebView with evaluateJavaScript.
Requires SDK to be initialized
Yes.
Parameters
No parameter.
Returns
Type
Description
Future<String>
JavaScript code to embed in a WebView
Example
Dart
await DidomiSdk.javaScriptForWebView;

getQueryStringForWebView

Get a query string parameter to append to the URL of a WebView to pass the consent status from the app to the Didomi Web SDK embedded into the WebView.
Read our article on sharing consent with WebViews for more information.
This method is currently available on Android platform only. Calling getQueryStringForWebView on iOS platform will return an empty String.
Requires SDK to be initialized
Yes.
Parameters
No parameter.
Returns
Type
Description
Future<String>
Query string parameter with the format didomiConfig.user.externalConsent.value=.... It can be appended to your URL after a ? or a & if your URL already contains a query string.
Example
Dart
await DidomiSdk.queryStringForWebView;

getPurpose

Get a purpose based on its ID.
Requires SDK to be initialized
Yes.
Parameters
Name
Type
Description
purposeId
String
ID of the purpose we want to get.
Returns
Type
Description
Future<Purpose?>
A Purpose with ID purposeId found in the array of required purposes, or null.
Example
Dart
await DidomiSdk.getPurpose("purpose-id");

getRequiredPurposes

Get the list of purpose that are required (automatically determined from the list of required vendors).
Requires SDK to be initialized
Yes.
Parameters
No parameter.
Returns
Type
Description
Future<List<Purpose>>
A list of type Purpose containing the required purposes.
Example
Dart
await DidomiSdk.requiredPurposes;

getRequiredPurposeIds

Get the list of purpose IDs that are required (automatically determined from the list of required vendors).
Requires SDK to be initialized
Yes.
Parameters
No parameter.
Returns
Type
Description
Future<List<String>>
A list of type String containing the IDs of required purposes.
Example
Dart
await DidomiSdk.requiredPurposeIds;

getRequiredVendors

Get the list of vendors that are required (determined from the configuration).
Requires SDK to be initialized
Yes.
Parameters
No parameter.
Returns
Type
Description
Future<List<Vendor>>
A list of type Vendor containing the required vendors.
Example
Dart
await DidomiSdk.requiredVendors;

getRequiredVendorIds

Get the list of vendor IDs that are required (determined from the configuration).
Requires SDK to be initialized
Yes.
Parameters
No parameter.
Returns
Type
Description
Future<List<String>>
A list of type String containing the IDs of required vendors.
Example
Dart
await DidomiSdk.requiredVendorIds;

getText

Method used to get a dictionary/map based on the key being passed. These keys and texts are extracted from the notice content, preferences content and the texts property specified in the didomi_config.json file as described here https://developers.didomi.io/cmp/mobile-sdk/consent-notice/customize-the-theme#translatable-texts-for-custom-notices.
Requires SDK to be initialized
Yes.
Parameters
Name
Type
Description
key
String
key associated to the dictionary that we want to get.
Returns
Type
Description
Dictionary/map: Future<Map<String, String>>
Dictionary/map containing the translations for an specific key in different languages, with the form { "en:" "text in English", "fr": "texte en Français" }
Example
Dart
await DidomiSdk.getText("key");

getTranslatedText

Method used to get a translated text based on the key being passed.
The language and the source of this translated text will depend on the availability of the translation for the specific key.
The language being used will be either the selected language of the SDK (based on device Locale and other parameters) or the language specified by app developers as the default language being used by the SDK. The source can be either the didomi_config.json file, which can be either local or remote, or a file that is bundled within the SDK.
These are the attempts performed by the SDK to try to find a translation for the specific key:
  • Get translated value in user locale (selected language) from didomi_config.json (either local or remote).
  • Get translated value in default locale (from the config) from didomi_config.json (either local or remote).
  • Get translated value in user locale (selected language) from the Didomi-provided translations (bundled within the Didomi SDK).
  • Get translated value in default locale (from the config) from the Didomi-provided translations (bundled within the Didomi SDK).
If no translation can be found after these 4 attempts, the key will be returned.
App developers can provide these translated texts through the didomi_config.json file (locally or remotely) in 3 different ways:
Requires SDK to be initialized
Yes.
Parameters
Name
Type
Description
key
String
key associated to the text that we want to get translated.
Returns
Translated text.
Example
Dart
await DidomiSdk.getTranslatedText("key");

getUserConsentStatusForPurpose

Deprecated, use getUserStatus instead.
Search the purposeId in userStatus.purposes?.consent?.enabled or userStatus.purposes?.consent?.disabled.
Get the user consent status for a given purpose. You must also check that the user has given consent to a vendor before being able to load a vendor.
Parameters
Name
Type
Description
purposeId
String
The ID of the purpose to check the user consent for
Returns
A ConsentStatus that indicates if the user has given consent or not to the specific purpose.
enum ConsentStatus { disable, enable, unknown }
unknown is returned if the consent status is not known yet. From a GDPR perspective, you'll want to treat unknown as disable (ie no consent given) but it is helpful to know that the user has not interacted with the consent UI yet so that you can subscribe to events and wait for consent information to be collected.
If consent is not required because GDPR does not apply to that user, this function will return enable.
Example
Dart
await DidomiSdk.getUserConsentStatusForPurpose("analytics");

getUserConsentStatusForVendor

Deprecated, use getUserStatus instead.
Search the vendorId in userStatus.vendors?.consent?.enabled or userStatus.vendors?.consent?.disabled.
Get the user consent status for a given vendor. You must also check that the user has given consent to some or all of the purposes required by a vendor before loading the vendor. The function getUserConsentStatusForVendorAndRequiredPurposes does all the required checks for you so it might be a better choice.
Parameters
Name
Type
Description
vendorId
String
The ID of the vendor to check the user consent for. If you are checking an IAB vendor, pass the number as a String. If you are checking a custom vendor, prefix your vendor ID with c:.
Returns
A ConsentStatus that indicates if the user has given consent or not to the specific vendor.
enum ConsentStatus { disable, enable, unknown }
unknown is returned if the consent status is not known yet. From a GDPR perspective, you'll want to treat unknown as disable (ie no consent given) but it is helpful to know that the user has not interacted with the consent UI yet so that you can subscribe to events and wait for consent information to be collected.
If consent is not required because GDPR does not apply to that user, this function will return enable.
Example
Dart
// IAB vendors
await DidomiSdk.getUserConsentStatusForVendor("1");
// Didomi vendors
await DidomiSdk.getUserConsentStatusForVendor("google");
// Custom vendors (prefix vendor ID with c:)
await DidomiSdk.getUserConsentStatusForVendor("c:custom-vendor-id");

getUserConsentStatusForVendorAndRequiredPurposes

Deprecated, use getUserStatus instead.
Search the vendorId in userStatus.vendors?.globalConsent?.enabled or userStatus.vendors?.globalConsent?.disabled.
Get the user consent status for a given vendor. We use the list of purposes declared for the vendor to make sure that it has consent for all of them. The required purposes are automatically setup for IAB or Didomi vendors and you must specify the required purposes for your custom vendors when configuring the tag.
Parameters
Name
Type
Description
vendorId
String
The ID of the vendor to check the user consent for.
If you are checking an IAB vendor, pass the number as a String.
If you are checking a custom vendor, prefix your vendor ID with c:.
Returns
A ConsentStatus that indicates if the user has given consent or not to the specific vendor and all the purposes that require consent for that vendor.
enum ConsentStatus { disable, enable, unknown }
unknown is returned if the consent status is not known yet. From a GDPR perspective, you'll want to treat unknown as disable (ie no consent given) but it is helpful to know that the user has not interacted with the consent UI yet so that you can subscribe to events and wait for consent information to be collected.
If consent is not required because GDPR does not apply to that user, this function will return enable.
Example
Dart
// IAB vendors
await DidomiSdk.getUserConsentStatusForVendorAndRequiredPurposes("1");
// Didomi vendors
await DidomiSdk.getUserConsentStatusForVendorAndRequiredPurposes("google");
// Custom vendors (prefix vendor ID with c:)
await DidomiSdk.getUserConsentStatusForVendorAndRequiredPurposes("c:custom-vendor-id");

getUserLegitimateInterestStatusForPurpose

Deprecated, use getUserStatus instead.
Search the purposeId in userStatus.purposes?.legitimateInterest?.enabled or userStatus.purposes?.legitimateInterest?.getDisabled.
Get the user legitimate interest status for a given purpose.
Parameters
Name
Type
Description
purposeId
String
The ID of the purpose to check the user legitimate interest for.
Returns
A ConsentStatus that indicates if the user has allowed legitimate interest data processing to the specific purpose.
enum ConsentStatus { disable, enable, unknown }
unknown is returned if the legitimate interest status is not known yet. From a GDPR perspective, you'll want to treat unknown as disable (ie no legitimate interest status given) but it is helpful to know that the user has not interacted with the legitimate interest UI yet so that you can subscribe to events and wait for legitimate interest information to be collected.
Example
Dart
await DidomiSdk.getUserLegitimateInterestStatusForPurpose("measure_ad_performance);

getUserLegitimateInterestForVendor

Deprecated, use getUserStatus