Skip to main content

unified_sdk 6.0.0 copy "unified_sdk: ^6.0.0" to clipboard
unified_sdk: ^6.0.0 copied to clipboard

GDPR consent management platform (CMP) by SFBX AppConsent: show the consent notice and read IAB TCF v2 and Google Consent Mode v2 consent on Android and iOS.

AppConsent Unified SDK for Flutter — GDPR consent management (CMP) #

pub package pub points platforms

unified_sdk is the official Flutter plugin of AppConsent, the consent management platform (CMP) by SFBX. It shows a GDPR-compliant consent notice in your Android and iOS app, collects the user's choices, and gives you the result as IAB TCF v2 data (purposes, vendors, features, stacks) and as Google Consent Mode v2 signals, ready for your ads and analytics SDKs.

It wraps the native AppConsent Unified SDKs (Android 6.4.2, iOS 6.2.2) behind one Dart API, and replaces the legacy appconsent_clear plugin. Screenshots of the consent notice are in the gallery at the top of the pub.dev page.

Features #

  • Consent notice (CMP UI) shown only when needed, plus "privacy settings" entry points to reopen it at any time.
  • IAB TCF v2 (v2.3 at the time of this release): allowed purposes, vendors, features, special features and stacks, written to the standard IABTCF_ keys that ad SDKs read. Most of the TCF logic runs on the AppConsent backend, so a new TCF version, such as v2.4 currently being studied and integrated by SFBX, may apply without a plugin update, depending on what the IAB changes. Current status: see the AppConsent documentation.
  • Google Consent Mode v2 state (analytics_storage, ad_storage, ad_user_data, ad_personalization).
  • Non-IAB ("extra") purposes and vendors configured in your AppConsent notice.
  • Programmatic consent: accept all, refuse all, granular override, clear.
  • External IDs and floating purposes for advanced setups.
  • Notice lifecycle events as a Dart Stream, identical on Android and iOS.
  • Zero native setup on Android, no CocoaPods source to add on iOS: the native SDKs ship with the plugin.
  • Seamless migration from appconsent_clear: users who already consented are not asked again.

Requirements #

Minimum
Android minSdk 21
iOS 15.0
Xcode 27 (see Troubleshooting)
Flutter tested with Flutter 3.32 (Dart ≥ 2.12 declared)
AppConsent your appKey, generated when you create your notice in your AppConsent dashboard

Installation #

flutter pub add unified_sdk

Android #

Nothing to do. The plugin registers the AppConsent Maven repository on your project automatically.

iOS #

  1. Set the iOS deployment target to 15.0 in ios/Podfile:

    platform :ios, '15.0'
    
  2. If your AppConsent notice uses App Tracking Transparency, add a usage description to ios/Runner/Info.plist. iOS terminates any app that requests tracking authorization without it:

    <key>NSUserTrackingUsageDescription</key>
    <string>This identifier will be used to deliver personalized ads to you.</string>
    
  3. Run pod install from the ios folder (or simply build with flutter run).

Quick start #

import 'package:unified_sdk/unified_sdk.dart';

final sdk = UnifiedSdk();

// 1. As early as possible (splash screen, app bootstrap).
//    Replace YOUR_APP_KEY with your appKey, generated when you create your notice
//    in your AppConsent dashboard.
await sdk.initialize('YOUR_APP_KEY');

// 2. Listen to the notice lifecycle BEFORE presenting it (broadcast stream).
sdk.noticeEvents.listen((event) {
  if (event.type == NoticeEventType.closed ||
      event.type == NoticeEventType.notDisplayed) {
    // Consent is now final: (re)configure your ads and analytics SDKs here.
  }
});

// 3. When your first screen is up: shows the notice only if consent is required.
await sdk.presentNotice();

// 4. Gate consent-dependent features.
if (await sdk.isIabPurposeAllowed(1)) {
  // Purpose 1: "Store and/or access information on a device".
}
final gcm = await sdk.getGCMState(); // Google Consent Mode v2 signals

Let users change their choices later, e.g. from a settings screen:

await sdk.displayLayer2(); // privacy center with per-purpose choices

Integration guide #

Initialize early, present when it makes sense #

initialize() and presentNotice() are two separate steps on purpose:

  • initialize() runs as early as possible, so the SDK is ready when you need it. Always await it before any other call.
  • presentNotice() runs from your own UI flow, typically once the home screen (or your onboarding) is visible. Showing a consent dialog before the user has seen anything of the app hurts opt-in rates. presentNotice() decides by itself whether a notice is needed (no consent yet, consent expired, notice configuration changed), so you can call it on every launch.

Notice events #

Each call to presentNotice(), displayLayer1() or displayLayer2() produces events on noticeEvents, with the same sequence on Android and iOS:

Sequence Meaning
displayed, then closed the notice was shown, then closed by the user
notDisplayed no notice was needed (consent stored and up to date, user outside the GDPR area...)
notDisplayed with error the notice could not be shown (no network, UI busy...)

Every presentation ends with exactly one closed or notDisplayed, so it is the right moment to apply the consent. event.source tells which call it answers: notice, layer1 or layer2. The stream is a broadcast stream: subscribe before presenting, events emitted with no listener are lost.

Which method to show the notice? #

Method Use it for
presentNotice() the automatic consent checkpoint, on every launch
displayLayer1() a "Privacy settings" entry point that must always open the notice, even with a valid consent
displayLayer2() opening the privacy center directly, with per-purpose and per-vendor choices

Wrap the SDK in one service #

Every method returns a Future that completes with a PlatformException when the native SDK rejects the call.

This pattern is optional: you can just as well catch PlatformException at each call site. Putting the SDK behind one small service of your own simply avoids duplicating the same try/catch around every method call. The bundled example app follows it in example/lib/services/consent_service.dart:

class ConsentService {
  ConsentService(this.sdk);

  final UnifiedSdk sdk;

  /// Runs an SDK call; never throws, logs and returns `null` on failure.
  Future<T?> run<T>(String action, Future<T> Function() call) async {
    try {
      return await call();
    } on PlatformException catch (e) {
      debugPrint('$action failed: ${e.code} ${e.message}');
      return null;
    }
  }

  Future<bool> isAdPersonalizationAllowed() async =>
      (await run('getGCMState', sdk.getGCMState))?.adPersonalization ?? false;
}

Error codes #

code When
INVALID_ARGS a required argument is missing or invalid (empty app key, unknown status...)
NOT_INITIALIZED a method was called before initialize() completed
INIT_ERROR the native initialization failed (e.g. the notice configuration could not be fetched)
SDK_ERROR (Android) the SDK is initialized, but the call failed inside it; message says why
NO_ACTIVITY (Android), NO_VIEW_CONTROLLER (iOS) a notice was requested with no foreground UI to show it on
NO_CONTEXT (Android) the plugin is not attached to a Flutter engine yet
FORCE_ERROR, SET_CONSENT_ERROR, EXTERNAL_IDS_ERROR, FLOATING_ERROR, CHECK_UPDATE_ERROR the corresponding action failed; message carries the reason
NOT_SUPPORTED_ON_IOS isLimitedTrackingEnabled() on iOS

isInitialized() lets you check readiness instead of catching. On Android it means the SDK finished its setup; on iOS it only means initialize() succeeded on this engine, as the iOS SDK has no observable initialization state. Treat it as "worth trying", and keep handling NOT_INITIALIZED.

API overview #

Statuses are strings: ALLOWED, DISALLOWED, MIXED, PENDING, UNKNOWN. Every member is documented in the API reference.

Consentable lists use numeric codes. The entries returned by getPurposes, getExtraVendors, get...ByStatus... (ACConsentable) carry the native codes as strings, on both platforms: status is '1' allowed, '-1' disallowed, '0' pending, '2' mixed; type is '0' purpose, '1' feature, '2' special feature, '3' special purpose (extra purposes and vendors report '0' too). Compare c.status == '1', not 'ALLOWED'. To filter, getPurposesByStatus('ALLOWED') takes the status name.

setLocalExternalIds replaces all local IDs. To add or change one, merge first: setLocalExternalIds({...await sdk.getLocalExternalIds(), 'crm_id': '42'}).

Area Methods
Setup initialize, isInitialized
Notice presentNotice, displayLayer1, displayLayer2, noticeEvents
Global consent isConsentGiven, getConsentStatus, isAllAllowed, isAllDisallowed, isConsentMixed, checkForUpdate
IAB TCF isIabPurposeAllowed, isIabVendorAllowed, isIabFeatureAllowed, isIabSpecialFeatureAllowed, isIabSpecialPurposeAllowed, isIabStacksAllowed, the matching iab...Allowed ID lists, getPurposes, getVendorsStatus...
Extra (non-IAB) getExtraPurposes, getExtraVendors, isExtraPurposeAllowed, isExtraVendorAllowed, extraPurposeIdsAllowed, extraVendorsAllowed
Filter by status getPurposesByStatus, getFeaturesByStatus, getStacksByStatus, getExtraVendorsByStatus...
Google Consent Mode getGCMState
Actions forceAcceptAll, forceDenyAll, askToClearConsent, setConsentableConsents
User and IDs getUserId, isSubjectToGDPR, isLimitedTrackingEnabled, getLocalExternalIds, setLocalExternalIds, askToGetExternalIds, askToSetExternalIds, saveExternalIds
Advanced saveFloatingPurpose, isFloatingNeedUpdate

Migrating from appconsent_clear #

  1. Replace the dependency: remove appconsent_clear and add unified_sdk.
  2. Raise the iOS deployment target to 15.0 (see Installation).
  3. Update the calls:
appconsent_clear unified_sdk
AppconsentClear.setup(appKey, forceApplyGDPR, forceATT, ...) UnifiedSdk().initialize(appKey)
AppconsentClear.presentNotice(false) presentNotice()
AppconsentClear.presentNotice(true) displayLayer1()
AppconsentClear.clearConsent() askToClearConsent()
AppconsentClear.consentGiven isConsentGiven()
AppconsentClear.checkForUpdate checkForUpdate()
AppconsentClear.isSubjectToGDPR isSubjectToGDPR()
AppconsentClear.consentableAllowed(id, ConsentableType.purpose) isIabPurposeAllowed(id)
AppconsentClear.consentableAllowed(id, ConsentableType.feature) isIabFeatureAllowed(id)
AppconsentClear.consentableAllowed(id, ConsentableType.specialFeature) isIabSpecialFeatureAllowed(id)
AppconsentClear.consentableAllowed(id, ConsentableType.specialPurpose) isIabSpecialPurposeAllowed(id)
AppconsentClear.extraConsentableAllowed(id) isExtraPurposeAllowed(id)
AppconsentClear.extraVendorAllowed(id) isExtraVendorAllowed(id)
AppconsentClear.appTracking... (iOS) no equivalent: the App Tracking Transparency prompt is part of the notice flow when your notice is configured for it

Users keep their consent: on the first launch after the update, the native SDKs migrate the identity and consent stored by the legacy SDK, once. Calls made right after initialize() already see the migrated consent: on Android initialize() completes once the migration is done, and on iOS presentNotice() and checkForUpdate() wait for it. A user who already answered is not asked again.

Platform differences #

One Dart API, but a few behaviors come from the native SDKs:

API Android iOS
isLimitedTrackingEnabled supported throws NOT_SUPPORTED_ON_IOS (use App Tracking Transparency)
isInitialized the SDK finished its setup initialize() succeeded on this engine
askToGetExternalIds the IDs known to the consent engine the locally stored IDs, like getLocalExternalIds
checkForUpdate failures throw CHECK_UPDATE_ERROR false also covers a failed call
isFloatingNeedUpdate failures throw FLOATING_ERROR false also covers a failed call

The consent data itself is identical: the integration tests run the same assertions on both platforms against the same notice.

Troubleshooting #

unifiedsdk:x.y.z FAILED in a Gradle build. Your app declares its repositories in settings.gradle with RepositoriesMode.FAIL_ON_PROJECT_REPOS or PREFER_SETTINGS, which ignores the repository the plugin adds. Declare it there:

dependencyResolutionManagement {
    repositories {
        google()
        mavenCentral()
        maven { url = uri("https://artifactory.datalf.chat/artifactory/appconsent") }
    }
}

IPHONEOS_DEPLOYMENT_TARGET ... is set to 12.0 (or 13.0) with Xcode 27. Xcode 27 refuses deployment targets below iOS 15.0, including those of other pods. Add this to the post_install block of your ios/Podfile:

post_install do |installer|
  installer.pods_project.targets.each do |target|
    flutter_additional_ios_build_settings(target)
    target.build_configurations.each do |config|
      config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '15.0'
    end
  end
end

Xcode version. The bundled iOS framework is compiled with Xcode 27 (Swift 6.4), and the plugin is built and tested with Xcode 27. Older Xcode versions may fail to import the AppConsentUnified module.

The app is terminated when the notice is shown on iOS. Add NSUserTrackingUsageDescription to Info.plist (see Installation).

The notice never shows. presentNotice() only shows it when a consent is required: listen to noticeEvents, a notDisplayed event tells you it was not needed, or why it failed. Use displayLayer1() to force it. The notice also needs network access to the AppConsent backend.

Mac Catalyst. Not supported: this plugin targets Android and iOS (iPhone and iPad) only.

The plugin's source code is licensed under the MIT License, see LICENSE. The AppConsent Unified SDKs it embeds or downloads are the property of SFBX and are not covered by it: see ios/Frameworks/LICENSE.

4
likes
150
points
211
downloads
screenshot

Documentation

Documentation
API reference

Publisher

verified publishersfbx.io

Weekly Downloads

GDPR consent management platform (CMP) by SFBX AppConsent: show the consent notice and read IAB TCF v2 and Google Consent Mode v2 consent on Android and iOS.

Homepage

Topics

#consent #gdpr #cmp #tcf #privacy

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on unified_sdk

Packages that implement unified_sdk