Mobile SDKs
Flutter SDK (shield_consent)
Official Flutter package for DPDPA 2023 compliant consent collection, ShieldGate purpose gating, guardian-OTP parental consent, and local-first offline queue.
flutter pub add shield_consent
View shield_consent on Pub.devPackage Architecture & Capabilities
DPDPA 2023 Compliant Consent Collection & Notice Fetching
ShieldGate Fail-Closed Purpose Gating Engine
Section 9 Guardian-OTP Parental Consent for Minors
Offline-First Local Queue with Auto-Sync (flushQueue)
Pure Dart Localization with 22 Official Indian Languages & English Fallback
On-Device User Identifier Hashing prior to Transmission
Initialize SDK & Setup App Entry
dart// pubspec.yaml
// dependencies:
// shield_consent: ^1.0.0-beta.3
import 'package:flutter/material.dart';
import 'package:shield_consent/shield_consent.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
// Initialize SDK with your DPDPA Shield API key
await ShieldConsent.init(
apiKey: 'dpdpa_live_sec_mumbai_...',
// cmpId: 'cmp_default', // optional CMP identifier
);
runApp(const MyApp());
}Load Notice, Localize (22 Languages) & Record Choices
dartimport 'package:shield_consent/shield_consent.dart';
Future<void> checkAndCollectConsent() async {
// 1. Check if the user has already provided preferences
final existing = await ShieldConsent.restoredDecision();
if (existing != null) return;
// 2. Fetch the published consent notice configuration
final notice = await ShieldConsent.loadNotice();
// 3. Localize for device language (Hindi with English per-field fallback)
final localized = ShieldConsent.localize(notice, languageCode: 'HI');
// 4. Record affirmative choices (identifiers hashed on-device)
await ShieldConsent.recordDecision(
ConsentDecision(
noticeId: notice.id,
given: {
'analytics-purpose-id': true,
'marketing-purpose-id': false,
'kyc-verification-id': true,
},
),
);
}ShieldGate Purpose Gating (Fail-Closed Architecture)
dartimport 'package:flutter/material.dart';
import 'package:shield_consent/shield_consent.dart';
class AnalyticsSection extends StatelessWidget {
const AnalyticsSection({super.key});
@override
Widget build(BuildContext context) {
// ShieldGate automatically enforces fail-closed privacy
// If consent is absent or denied, the fallback is safely rendered
return ShieldGate(
purposeId: 'analytics-purpose-id',
consentedChild: const LiveTelemetryWidget(),
fallback: const Center(
child: Text('Analytics telemetry paused per DPDPA preferences'),
),
);
}
}Offline-First Queue & Network Reconnect
dartimport 'package:shield_consent/shield_consent.dart';
// Consent decisions are written locally first for instant app speed.
// Any unsynced choices queued offline auto-flush upon reconnect:
void onConnectivityRestored() {
ShieldConsent.flushQueue();
}Configuration Parameters
| Parameter | Type | Description |
|---|---|---|
| apiKey | string (Required) | Your secret production API key from the DPDPA Shield Dashboard. |
| cmpId | string (Optional) | Consent Management Platform tenant or workspace identifier. |
| languageCode | string | ISO 639-1 code ('HI', 'TA', 'TE', 'MR', 'EN') with automatic fallback. |
| ShieldGate | Widget Component | Purpose-gating wrapper that evaluates consent before executing child widgets. |
Need sandbox API keys for testing?
Create a free developer assessment account in under 60 seconds.