Integrate consent banner
With your assetId and bannerId ready, add TruConsentModal to your Flutter app. The widget fetches its configuration on mount and auto-hides if the user has already consented to all purposes.
Install the package
Section titled “Install the package”Add the SDK to pubspec.yaml:
dependencies: truconsent_consent_notice_flutter: ^1.0.0flutter pub getStore your credentials
Section titled “Store your credentials”Create a config class to hold your SDK values in one place:
class TruConsentConfig { static const String apiKey = 'your-api-key'; static const String organizationId = 'your-organization-id'; static const String assetId = 'your-asset-id'; static const String apiBaseUrl = 'https://trukit-dev.truconsent.io';}Mount the widget
Section titled “Mount the widget”Import and add TruConsentModal to your widget tree. Place it in a Stack so it overlays your main content:
import 'package:flutter/material.dart';import 'package:truconsent_consent_notice_flutter/truconsent_consent_banner_flutter.dart';import 'config/truconsent_config.dart';
class MyApp extends StatelessWidget { const MyApp({super.key});
@override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( body: Stack( children: [ const MainContent(), TruConsentModal( apiKey: TruConsentConfig.apiKey, organizationId: TruConsentConfig.organizationId, bannerId: 'CP003', userId: 'user-uuid-or-session-id', assetId: TruConsentConfig.assetId, apiUrl: TruConsentConfig.apiBaseUrl, companyName: 'Your Company', onClose: (String type) { debugPrint('Consent banner closed: $type'); }, ), ], ), ), ); }}Show the banner conditionally
Section titled “Show the banner conditionally”Show the banner only when needed — for example, before a form submission:
import 'package:flutter/material.dart';import 'package:truconsent_consent_notice_flutter/truconsent_consent_banner_flutter.dart';import 'config/truconsent_config.dart';
class SignupScreen extends StatefulWidget { const SignupScreen({super.key});
@override State<SignupScreen> createState() => _SignupScreenState();}
class _SignupScreenState extends State<SignupScreen> { bool _showConsent = false;
void _handleConsentClose(String type) { setState(() => _showConsent = false); if (type == 'approved' || type == 'partial_consent') { _proceedWithSignup(); } else { ScaffoldMessenger.of(context).showSnackBar( const SnackBar(content: Text('Consent is required to continue.')), ); } }
void _proceedWithSignup() { // proceed with form submission }
@override Widget build(BuildContext context) { return Scaffold( body: Stack( children: [ Center( child: ElevatedButton( onPressed: () => setState(() => _showConsent = true), child: const Text('Sign Up'), ), ), if (_showConsent) TruConsentModal( apiKey: TruConsentConfig.apiKey, organizationId: TruConsentConfig.organizationId, bannerId: 'CP003', userId: 'user-uuid', assetId: TruConsentConfig.assetId, apiUrl: TruConsentConfig.apiBaseUrl, onClose: _handleConsentClose, ), ], ), ); }}Widget props
Section titled “Widget props”| Prop | Type | Description |
|---|---|---|
apiKey * | String | API key from the platform dashboard. |
organizationId * | String | Your org ID — sent on every request. |
bannerId * | String | Collection point display_id from the platform (e.g. CP003). |
assetId * | String | Asset UUID from the platform. |
apiUrl * | String | SDK base URL: https://trukit-dev.truconsent.io |
userId | String | Authenticated user ID or guest UUID. Used to look up prior consent records. |
logoUrl | String | Logo URL shown in the banner header. |
companyName | String | Company name shown in the banner. |
onClose | Function(String) | Called on close with one of the consent action types below. |
onClose callback values
Section titled “onClose callback values”| Value | Meaning |
|---|---|
approved | User consented to all purposes |
declined | User declined all purposes |
partial_consent | User consented to some purposes |
revoked | User withdrew a previously granted consent |
no_action | Banner auto-dismissed (user already consented) |
Troubleshooting
Section titled “Troubleshooting”Banner does not appear
- Verify
bannerId,assetId, andorganizationIdare correct. - If the user has already consented to all purposes, the widget auto-hides and
onClosefires withno_action.
401 Unauthorized
- Check your API key is correct and matches your organization.
403 Forbidden
- Your app’s bundle ID or domain is not allowlisted. Go to Settings → API Settings → Allowed Domains in the platform dashboard and add it.
Network error on Android
- Ensure
android/app/src/main/AndroidManifest.xmlhas<uses-permission android:name="android.permission.INTERNET" />. Most Flutter projects include this by default.