appconsent_tv 0.1.3 copy "appconsent_tv: ^0.1.3" to clipboard
appconsent_tv: ^0.1.3 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_tv/appconsent_tv.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 AppconsentTv.setup(
        "4e9a99ed-1261-4241-8213-4f6e31d361c2", true, true);
    showCMPIfNeeded();
  }

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

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

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

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

    try {
      consentGiven = await AppconsentTv.consentGiven;
    } on PlatformException {
      consentGiven = false;
    }

    if (!mounted) return;

    setState(() {
      _consentGiven = consentGiven;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Shortcuts(
        shortcuts: <LogicalKeySet, Intent>{
          LogicalKeySet(LogicalKeyboardKey.select): const ActivateIntent(),
        },
        child: MaterialApp(
          title: 'SFBX AppConsent Flutter TV',
          theme: ThemeData(
            primarySwatch: Colors.blue,
            visualDensity: VisualDensity.adaptivePlatformDensity,
          ),
          home: Scaffold(
            appBar: AppBar(
              title: const Text('SFBX AppConsent Flutter TV'),
            ),
            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 Preferences Saved? $_consentGiven\n'),
                ])),
          ),
        ));
  }
}
6
likes
0
pub points
50%
popularity

Publisher

verified publishersfbx.io

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

Homepage

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on appconsent_tv