getConsentStatus method

Future<ConsentStatus> getConsentStatus()

Possible returned values:

OBTAINED status means, that user already chose one of the variants ('Consent' or 'Do not consent');

REQUIRED status means, that form should be shown by user, because his location is at EEA or UK;

NOT_REQUIRED status means, that form would not be shown by user, because his location is not at EEA or UK;

UNKNOWN status means, that there is no information about user location.

Implementation

Future<ConsentStatus> getConsentStatus() async {
  try {
    final String result = await _channel.invokeMethod('gdpr.getConsentStatus', []) ?? '';
    debugPrint('Got a GDPR status: $result');

    switch (result) {
      case 'REQUIRED':
        return ConsentStatus.required;
      case 'NOT_REQUIRED':
        return ConsentStatus.notRequired;
      case 'OBTAINED':
        return ConsentStatus.obtained;
      case 'UNKNOWN':
      default:
        return ConsentStatus.unknown;
    }
  } on Exception catch (e) {
    debugPrint('$e');
    return ConsentStatus.unknown;
  }
}