admob_consent 1.0.0+1

  • Readme
  • Changelog
  • Example
  • Installing
  • 79

Admob Consent Plugin #

Pub Version

An extended wrapper for Google's Mobile Ads Consent SDK, i.e. used as GDPR dialog on Android and iOS. The Android version has been modified to include localized consent forms. Customizable to include own Publisher ID and privacy policy URL.

Usage #

To use this plugin, add admob_consent as a dependency in your pubspec.yaml file.

Example #

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

final AdmobConsent _admobConsent = AdmobConsent();

_admobConsent.show(publisherId: "REPLACE_WITH_YOUR_PUBLISHER_ID", privacyURL: "URL_TO_YOUR_PRIVACY_POLICY");

Publisher ID #

Your publisher ID is the unique identifier for your AdMob account. Find your publisher ID. It should look like this pub-XXXXXXXXXXXXXXXX.

Listener #

You can listen to the onConsentFormLoaded, onConsentFormOpened, onConsentFormClosed and onConsentFormError streams.

_admobConsent.onConsentFormClosed.listen((bool status) {
    // Status true if personalized
    // Handle it, ie. set targetingInfo
});

Enjoy it? #

Buy Me A Coffee

Troubleshooting #

You most likely have to fiddle with proguards to keep some classes from being obfuscated or disable minifyEnabled.

# Keep classes of this plugin
-keep class com.anteger.** { *; }

# Gson uses generic type information stored in a class file when working with fields. Proguard
# removes such information by default, so configure it to keep all of it.
-keepattributes Signature

# For using GSON @Expose annotation
-keepattributes *Annotation*

# Gson specific classes
-dontwarn sun.misc.**
#-keep class com.google.gson.stream.** { *; }

# Application classes that will be serialized/deserialized over Gson
-keep class com.google.gson.examples.android.model.** { <fields>; }

# Prevent proguard from stripping interface information from TypeAdapter, TypeAdapterFactory,
# JsonSerializer, JsonDeserializer instances (so they can be used in @JsonAdapter)
-keep class * implements com.google.gson.TypeAdapter
-keep class * implements com.google.gson.TypeAdapterFactory
-keep class * implements com.google.gson.JsonSerializer
-keep class * implements com.google.gson.JsonDeserializer

# Prevent R8 from leaving Data object members always null
-keepclassmembers,allowobfuscation class * {
  @com.google.gson.annotations.SerializedName <fields>;
}

Screenshot #

Example Screenshot

1.0.0+1 #

  • Add repository and issue tracker to pubspec.yaml

1.0.0 #

  • Public release

0.0.1 #

  • Initial release

example/lib/main.dart

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

import 'package:flutter/services.dart';
import 'package:admob_consent/admob_consent.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {

  AdmobConsent _admobConsent = AdmobConsent();
  StreamSubscription<bool> _subscription;

  @override
  void initState() {
    super.initState();
    _subscription = _admobConsent.onConsentFormClosed.listen((bool status) {
      // Status true if personalized
      // Handle it, ie. set targetingInfo
    });
    initPlatformState();
  }

  Future<void> initPlatformState() async {
    _admobConsent.show(publisherId: "REPLACE_WITH_YOUR_PUBLISHER_ID", privacyURL: "REPLACE_WITH_YOUR_PRIVACY_URL");
  }

  @override
  void dispose() {
    _subscription.cancel();
    _admobConsent.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Text('An example app'),
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  admob_consent: ^1.0.0+1

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:admob_consent/admob_consent.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
59
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
79
Learn more about scoring.

We analyzed this package on Jul 2, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.13
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform linux

Because of import path [package:admob_consent/admob_consent.dart] that declares support for platforms: android, ios

Package does not support Flutter platform macos

Because of import path [package:admob_consent/admob_consent.dart] that declares support for platforms: android, ios

Package does not support Flutter platform web

Because of import path [package:admob_consent/admob_consent.dart] that declares support for platforms: android, ios

Package does not support Flutter platform windows

Because of import path [package:admob_consent/admob_consent.dart] that declares support for platforms: android, ios

Package not compatible with SDK dart

because of import path [admob_consent] that is in a package requiring null.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8
Dev dependencies
flutter_test