consent_sdk 1.0.0
consent_sdk: ^1.0.0 copied to clipboard
Flutter plugin for the Privasapien Consent SDK. Delegates all consent UI to native Android and iOS SDKs, enabling GDPR-compliant user consent flows.
consent_sdk
Flutter plugin for the Privasapien Consent SDK — GDPR-compliant, backend-driven consent UI for Android and iOS.
A thin Flutter wrapper over the native Privasapien Consent SDKs for Android (Kotlin + Jetpack Compose) and iOS (Swift + SwiftUI). All consent UI is rendered entirely in native code — nothing is rebuilt in Flutter/Dart.
Features #
- Backend-driven consent UI — text, purposes, layout, and colors configured from your Privasapien dashboard; no app updates needed when regulations change
- Bottom sheet & full-screen modes — adapts to your UX requirements
- Multi-language support — users can switch language directly from the consent UI
- Real-time events —
onConsentSubmitted,onConsentClosed,onConsentError,onLanguageChanged,onPurposeToggled - Parental consent flow — automatic handling for users under 18
- Zero Flutter UI — delegates entirely to the platform SDKs; native performance and fidelity
Platform Support #
| Platform | Minimum version |
|---|---|
| Android | API 24 (Android 7.0) |
| iOS | 17.0 |
Installation #
Add consent_sdk to your pubspec.yaml:
dependencies:
consent_sdk: ^1.0.0
Then run:
flutter pub get
Usage #
1. Initialize #
Call initialize once before showing any consent UI — typically in main() after WidgetsFlutterBinding.ensureInitialized().
import 'package:consent_sdk/consent_sdk.dart';
await ConsentSDK.initialize(
const ConsentInitConfig(
apiUrl: 'https://api.your-domain.com/api/v1',
applicationId: 'your-app-id',
tenantId: 'your-tenant-id',
userIdentifier: 'user@example.com',
modeOfCommunication: 'email',
language: 'english', // optional, defaults to 'english'
),
);
2. Show the consent UI #
// As a bottom sheet (recommended for most use cases)
await ConsentSDK.showBottomSheet();
// Or full screen (ideal for first-time onboarding)
await ConsentSDK.showFullScreen();
3. Listen to events #
Register a ConsentListener before showing the UI to receive lifecycle callbacks.
ConsentSDK.setListener(
ConsentListener(
onConsentSubmitted: (List<String> acceptedPurposeIds) {
// User submitted consent — store the accepted purpose IDs in your backend
},
onConsentClosed: () {
// User dismissed the consent UI without submitting
},
onConsentError: (String error) {
// An error occurred in the native SDK (network, API, etc.)
},
onLanguageChanged: (String languageCode) {
// User switched the consent UI language
},
onPurposeToggled: (String purposeId, bool isSelected) {
// A purpose toggle changed before submission
},
),
);
// Remove the listener when it is no longer needed
ConsentSDK.removeListener();
Full example #
import 'package:flutter/material.dart';
import 'package:consent_sdk/consent_sdk.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await ConsentSDK.initialize(
const ConsentInitConfig(
apiUrl: 'https://api.your-domain.com/api/v1',
applicationId: 'your-app-id',
tenantId: 'your-tenant-id',
userIdentifier: 'user@example.com',
modeOfCommunication: 'email',
),
);
ConsentSDK.setListener(
ConsentListener(
onConsentSubmitted: (ids) => debugPrint('Accepted: $ids'),
onConsentError: (e) => debugPrint('Error: $e'),
),
);
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Center(
child: ElevatedButton(
onPressed: () => ConsentSDK.showBottomSheet(),
child: const Text('Manage Privacy'),
),
),
),
);
}
}
API Reference #
ConsentSDK #
| Method | Description |
|---|---|
initialize(ConsentInitConfig) |
Initialise the native SDK. Must be called before showing UI. |
showBottomSheet() |
Present the consent UI as a bottom sheet. |
showFullScreen() |
Present the consent UI full screen. |
setListener(ConsentListener) |
Register a listener for SDK events. Replaces any previous listener. |
removeListener() |
Unregister the listener and cancel the event stream. |
ConsentInitConfig #
| Field | Type | Required | Description |
|---|---|---|---|
apiUrl |
String |
✓ | Base URL of the Privasapien consent API |
applicationId |
String |
✓ | Your application identifier |
tenantId |
String |
✓ | Your tenant identifier |
userIdentifier |
String |
✓ | Unique user identifier (e.g. email address) |
modeOfCommunication |
String |
✓ | Communication channel — "email" or "sms" |
introductionMessage |
String? |
Optional intro text displayed above consent purposes | |
age |
int? |
User age. If under 18, parentEmail is required |
|
parentEmail |
String? |
Parent/guardian email for minors | |
language |
String |
Consent UI language (default: "english") |
ConsentListener #
| Callback | Signature | Description |
|---|---|---|
onConsentSubmitted |
(List<String> acceptedPurposeIds) |
User submitted consent |
onConsentClosed |
() |
Consent UI was dismissed without submitting |
onConsentError |
(String error) |
A native SDK error occurred |
onLanguageChanged |
(String languageCode) |
User changed the consent UI language |
onPurposeToggled |
(String purposeId, bool isSelected) |
A purpose toggle was changed |
All callbacks are optional — pass only the ones you need.
How it works #
The Flutter plugin bridges to the native SDKs via Flutter platform channels:
Flutter (Dart)
│ MethodChannel: com.privasapien/consent_sdk
│ EventChannel: com.privasapien/consent_sdk/events
▼
Android (Kotlin) iOS (Swift)
ConsentManagerSDK ConsentManager.shared
Jetpack Compose UI SwiftUI
The native SDKs own the full consent lifecycle: fetching configuration from the API, rendering the UI, persisting consent state, and emitting events back to Flutter.
License #
Copyright © 2024 Privasapien. All rights reserved. See LICENSE for details.