Skip to content

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.

Add the SDK to pubspec.yaml:

dependencies:
truconsent_consent_notice_flutter: ^1.0.0
Terminal window
flutter pub get

Create a config class to hold your SDK values in one place:

lib/config/truconsent_config.dart
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';
}

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 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,
),
],
),
);
}
}
* Required
PropTypeDescription
apiKey *StringAPI key from the platform dashboard.
organizationId *StringYour org ID — sent on every request.
bannerId *StringCollection point display_id from the platform (e.g. CP003).
assetId *StringAsset UUID from the platform.
apiUrl *StringSDK base URL: https://trukit-dev.truconsent.io
userIdStringAuthenticated user ID or guest UUID. Used to look up prior consent records.
logoUrlStringLogo URL shown in the banner header.
companyNameStringCompany name shown in the banner.
onCloseFunction(String)Called on close with one of the consent action types below.
ValueMeaning
approvedUser consented to all purposes
declinedUser declined all purposes
partial_consentUser consented to some purposes
revokedUser withdrew a previously granted consent
no_actionBanner auto-dismissed (user already consented)

Banner does not appear

  • Verify bannerId, assetId, and organizationId are correct.
  • If the user has already consented to all purposes, the widget auto-hides and onClose fires with no_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.xml has <uses-permission android:name="android.permission.INTERNET" />. Most Flutter projects include this by default.