showConsentForm method

Future<bool> showConsentForm()

Shows the consent form if it is available.

Implementation

Future<bool> showConsentForm() async {
  if (await _isConsentFormAvailable()) {
    _logger.debug('Consent form is available, loading consent form...');
    final consentForm = await _loadConsentForm();
    final completer = Completer<bool>();

    if (consentForm != null) {
      _logger.debug('Consent form loaded, showing consent form...');

      consentForm.show((formError) async {
        _logger.debug('Consent form closed');

        if (formError != null) {
          _logger.error('Consent form error: $formError');
        }

        final status = await getConsentStatus();
        _logger.info('Consent status', status);

        await MobileAds.instance.initialize();

        completer.complete(true);
      });

      return completer.future;
    } else {
      _logger.error('Consent form is null');
    }
  } else {
    _logger.debug('Consent form is not available');
  }

  return false;
}