gdpr_admob 1.0.2 copy "gdpr_admob: ^1.0.2" to clipboard
gdpr_admob: ^1.0.2 copied to clipboard

A Flutter package to manage GDPR consent for AdMob.

Flutter GDPR Admob Package #

This guide provides a basic understanding of how to use the gdpr_admob package in a Flutter application.

Introduction #

The gdpr_admob package helps you display a GDPR consent form to users within the European Economic Area (EEA) and initialize Google Mobile Ads based on user consent. This guide explains how to set it up in your Flutter app.

First release of gdpr_admob package

Step-by-Step Guide #

1. Add Dependencies #

Add the following dependencies to your pubspec.yaml file:

dependencies:
  flutter:
    sdk: flutter
  google_mobile_ads: ^5.1.0
  gdpr_admob: ^1.0.1

2. Import Packages #

Import the required packages in your Dart file:

import 'package:flutter/material.dart';
import 'package:gdpr_admob/gdpr_admob.dart';
import 'package:google_mobile_ads/google_mobile_ads.dart';

3. Initializing GDPR #

In your Stateful widget, create an instance of GdprAdmob and define a method to initialize it. This method will set the GDPR consent status for the user.

final GdprAdmob gdprAdmob = GdprAdmob();
bool _isLoading = false;
String? _errorMessage;
String? _consentStatus;

Future<void> _initializeGdpr() async {
  setState(() {
    _isLoading = true;
  });

  final error = await gdprAdmob.initialize(
    mode: DebugGeography.debugGeographyEea,
    testIdentifiers: ["WRITE_YOUR_TEST_DEVICE_IDENTIFIERS"],
  );

  if (error != null) {
    setState(() {
      _errorMessage = error.message;
    });
  }

  setState(() {
    getStatus();
    _isLoading = false;
  });
}

Define another method to get the current consent status of the user.

getStatus() async {
  final status = await gdprAdmob.getConsentStatus();
  setState(() {
    _consentStatus = status;
  });
}

5. Displaying GDPR Dialog #

You can now use these methods in your widget tree to display the GDPR dialog and get the consent status. You can also reset the consent status using the resetConsentStatus method.

ElevatedButton(
  onPressed: _initializeGdpr,
  child: const Text("Show GDPR dialog"),
),
ElevatedButton(
  onPressed: () async {
    await gdprAdmob.resetConsentStatus();
    getStatus();
  },
  child: const Text("Reset the consent state"),
),
if (_consentStatus != null)
  Text('Consent Status: $_consentStatus'),
if (_errorMessage != null) Text('Error: $_errorMessage'),

That's it! You have now integrated the gdpr_admob package into your Flutter application.

1
likes
150
pub points
61%
popularity

Publisher

verified publisherarabflutter.com

A Flutter package to manage GDPR consent for AdMob.

Repository (GitHub)
View/report issues

Documentation

API reference

License

GPL-3.0 (license)

Dependencies

flutter, google_mobile_ads

More

Packages that depend on gdpr_admob