requestConsentForm static method

Future<GdprResult> requestConsentForm({
  1. GdprDebugGeography debugGeography = GdprDebugGeography.disabled,
  2. List<String>? testIdentifiers,
})

Shows or shows not a consent form. Returns FormError of consent could not get loaded via the internet or was not given by user.

Implementation

static Future<GdprResult> requestConsentForm(
    {GdprDebugGeography debugGeography = GdprDebugGeography.disabled,
    List<String>? testIdentifiers}) async {
  final completer = Completer<GdprResult>();

  DebugGeography debugArea = DebugGeography.debugGeographyDisabled;

  if (debugGeography != GdprDebugGeography.disabled) {
    debugArea = debugGeography == GdprDebugGeography.insideEea
        ? DebugGeography.debugGeographyEea
        : DebugGeography.debugGeographyNotEea;
  }

  final params = ConsentRequestParameters(
      consentDebugSettings: ConsentDebugSettings(
          debugGeography: debugArea, testIdentifiers: testIdentifiers));

  ConsentInformation.instance.requestConsentInfoUpdate(params, () async {
    if (await ConsentInformation.instance.isConsentFormAvailable()) {
      final GdprResult result = await _loadConsentForm();
      completer.complete(result);
    } else {
      final formError = FormError(
          errorCode: 0,
          message: 'Consent Form is not available at the moment');
      completer.complete(GdprResult.error(formError));
    }
  }, (FormError formError) {
    _logFormError(formError);
    completer.complete(GdprResult.error(formError));
  });

  return completer.future;
}