Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: The getter 'publisherConsents' isn't defined for the class 'BasicConsentInfo' #10

Open
chrissy-dev opened this issue Mar 20, 2023 · 1 comment

Comments

@chrissy-dev
Copy link

chrissy-dev commented Mar 20, 2023

I can't seem to access publisherConsents in the return. I can print it but I can't access it? Any ideas? I'm using the demo code.

I'd like to create a wrapper that takes a widget, checks for consent and decides whether the it can load.

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

class ConsentGate extends StatefulWidget {
  const ConsentGate({Key? key, required this.child}) : super(key: key);

  final Widget child;

  @override
  State<ConsentGate> createState() => _ConsentGateState();
}

class _ConsentGateState extends State<ConsentGate> {
  BasicConsentInfo? consentInfo;

  @override
  void initState() {
    WidgetsBinding.instance.addPostFrameCallback((_) async {
      consentInfo = await _getConsentInfo();
    });
    super.initState();
  }

  Future<BasicConsentInfo?> _getConsentInfo() async {
    BasicConsentInfo? consent =
        await IabtcfConsentInfo.instance.currentConsentInfo();

    setState(() {
      consentInfo = consent;
    });

    return consent;
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Text(consentInfo.toString());
  }
}

I'd like to have a conditional check in the build but I can't access the data. I can see the data being printed but I'm unsure how to access it.

Screenshot 2023-03-20 at 13 27 17

@jice-lavocat
Copy link

jice-lavocat commented Jun 17, 2023

Try to set the type as ConsentInfo instead of BasicConsentInfo to get access to the relevant variables.

Example:

final info = await IabtcfConsentInfo.instance.currentConsentInfo() as ConsentInfo;
bool hasAdsGranted = info.purposeConsents.contains(DataUsagePurpose.selectBasicAds) ?? false;
print(hasAdsGranted); // should display true or false

It got me some time to figure out, so I posted it for other people who might land here too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants