appconsent_classic 2.0.0 copy "appconsent_classic: ^2.0.0" to clipboard
appconsent_classic: ^2.0.0 copied to clipboard

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

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:appconsent_classic/appconsent_classic.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 AppconsentClassic.setup(
        "4e9a99ed-1261-4241-8213-4f6e31d361c2", false, true);
    showCMPIfNeeded();
  }

  Future<void> showCMPIfNeeded() async {
    await AppconsentClassic.presentNotice(false);
  }

  Future<void> showSettings() async {
    await AppconsentClassic.presentNotice(true);
  }

  Future<void> resetConsent() async {
    await AppconsentClassic.clearConsent();
  }

  Future<void> checkConsent() async {
    bool consentGiven;

    try {
      consentGiven = await AppconsentClassic.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'),
            ])),
      ),
    );
  }
}
4
likes
160
points
33
downloads

Publisher

verified publishersfbx.io

Weekly Downloads

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

Homepage

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on appconsent_classic