appconsent_clear 2.4.2 appconsent_clear: ^2.4.2 copied to clipboard
AppConsent® cmp, the transparency-based consent management platform.
import 'dart:async';
import 'package:appconsent_clear/appconsent_clear.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
bool _consentGiven = false;
bool _checkForUpdate = false;
@override
void initState() {
super.initState();
initCMP();
}
Future<void> initCMP() async {
await AppconsentClear.setup(
"c2285ad1-4e50-4b63-8689-b2ecb3b020f4", true, true, fullscreen: true);
showCMPIfNeeded();
}
Future<void> showCMPIfNeeded() async {
bool isUpdateNeeded = await AppconsentClear.checkForUpdate;
if (isUpdateNeeded) {
AppconsentClear.presentNotice(false);
}
}
Future<void> showSettings() async {
await AppconsentClear.presentNotice(true);
}
Future<void> resetConsent() async {
await AppconsentClear.clearConsent();
}
Future<void> checkConsent() async {
bool consentGiven;
try {
consentGiven = await AppconsentClear.consentGiven;
} on PlatformException {
consentGiven = false;
}
if (!mounted) return;
setState(() {
_consentGiven = consentGiven;
});
}
Future<void> checkForUpdate() async {
bool checkForUpdate;
try {
checkForUpdate = await AppconsentClear.checkForUpdate;
} on PlatformException {
checkForUpdate = false;
}
if (!mounted) return;
setState(() {
_checkForUpdate = checkForUpdate;
});
}
void updateConsentStatus() {}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('SFBX AppConsent Flutter'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
ElevatedButton(
onPressed: showCMPIfNeeded,
child: const Text('Show CMP if needed'),
),
ElevatedButton(
onPressed: showSettings,
child: const Text('Display Settings'),
),
ElevatedButton(
onPressed: resetConsent,
child: const Text('Reset Consent'),
),
ElevatedButton(
onPressed: checkConsent,
child: const Text('Check Consent'),
),
ElevatedButton(
onPressed: checkForUpdate,
child: const Text('Check For Update'),
),
Text('Consent given? $_consentGiven\n'),
Text('Check For Update? $_checkForUpdate\n'),
])),
),
);
}
}