appconsent_tv 2.3.2 copy "appconsent_tv: ^2.3.2" to clipboard
appconsent_tv: ^2.3.2 copied to clipboard

PlatformAndroid

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

example/lib/main.dart

import 'dart:async';
import 'dart:developer';

import 'package:appconsent_tv/appconsent_tv.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await initializeController();
  runApp(const MyApp());
}

Future<void> initializeController() async {
  try {
    // First method to show the CMP when you need it - Be sure to AWAIT setup
    await AppconsentTv.setup(
        'APP_KEY', true, true);
  } catch (error, stacktrace) {
    log(error.toString());
    debugPrintStack(stackTrace: stacktrace);
  }
}

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 {
    // Second method to show the CMP when it has finished initializing
    // AppconsentTv.setup("4e9a99ed-1261-4241-8213-4f6e31d361c2", true, true).then((value) => {
    //  showCMPIfNeeded()
    // });

    showCMPIfNeeded();
  }

  Future<void> showCMPIfNeeded() async {
    bool isUpdateNeeded = await AppconsentTv.checkForUpdate;
    if (isUpdateNeeded) {
      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
160
pub points
32%
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_tv