appconsent_clear 2.1.7 copy "appconsent_clear: ^2.1.7" to clipboard
appconsent_clear: ^2.1.7 copied to clipboard

AppConsent® cmp, the transparency-based consent management platform.

example/lib/main.dart

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;

  @override
  void initState() {
    super.initState();
    initCMP();
  }

  Future<void> initCMP() async {
    await AppconsentClear.setup(
        "4e9a99ed-1261-4241-8213-4f6e31d361c2", true, 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;
    });
  }

  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'),
              ),
              Text('Consent given? $_consentGiven\n'),
            ])),
      ),
    );
  }
}
5
likes
140
pub points
68%
popularity

Publisher

verified publishersfbx.io

AppConsent® cmp, the transparency-based consent management platform.

Homepage

Documentation

API reference

License

MIT (LICENSE)

Dependencies

flutter

More

Packages that depend on appconsent_clear