Closed kaboc closed 3 years ago
Hi @kaboc, thanks for reporting this issue.
Seams like the library is not properly forwarding exceptions to currentConsentInfo
, which causes an Unhandled Exception
, instead of throwing.
The other issue is that cmpSdkVersion
is null
even though cmpSdkID
is not.
@blaugold Is there any workaround I can do on my side before the package is improved?
Not really, but I'll publish a fix today.
Fixed by 5cfacff78d01347182f53ffc698b41564aa9af1a.
iabtcf_consent_info: ^1.3.3
has been published with the fix.
@blaugold
Thanks for the amazingly quick fix, but the unhandled exception still occurs on the same line. flutter clean
didn't change the result.
Here's a reproducible code. I confirmed the issue on Android 5.1.1 and 10.
import 'package:flutter/material.dart';
import 'package:iabtcf_consent_info/iabtcf_consent_info.dart';
import 'package:user_messaging_platform/user_messaging_platform.dart';
void main() {
runApp(const App());
}
class App extends StatefulWidget {
const App();
@override
_AppState createState() => _AppState();
}
class _AppState extends State<App> {
@override
void initState() {
super.initState();
_showConsentDialog();
}
Future<void> _showConsentDialog() async {
// Simulates that you're not in EEA fordebugging
final settings = ConsentDebugSettings(
geography: DebugGeography.notEEA,
testDeviceIds: ['YOUR_TEST_DEVICE_ID'],
);
final info = await UserMessagingPlatform.instance.requestConsentInfoUpdate(
ConsentRequestParameters(debugSettings: settings),
);
print(info); // ConsentInformation(consentStatus: ConsentStatus.notRequired, formStatus: FormStatus.unavailable)
if (info.consentStatus == ConsentStatus.required) {
// The consent dialog is not shown because you're outside of EEA
await UserMessagingPlatform.instance.showConsentForm();
}
final newInfo = await IabtcfConsentInfo.instance.currentConsentInfo();
print(newInfo);
}
@override
Widget build(BuildContext context) {
return const SizedBox.shrink();
}
}
It doesn't occur if _showConsentDialog()
is as simple as below.
Future<void> _showConsentDialog() async {
final newInfo = await IabtcfConsentInfo.instance.currentConsentInfo();
print(newInfo); // null
}
Thanks for the example. I should have read the TCF spec more closely. When GDPR does not apply, the CMP only sets a few fields. I think an expected behavior would be to return null
from currentConsentInfo
when GDPR does not apply.
iabtcf_consent_info: ^2.0.0
is the latest release, which contains a breaking change to properly represent the situation where the GDPR does not apply. When no CMP SDK is active, currentConsentInfo
returns null
. If GDPR does not apply, or it has not been determined yet whether it does, BasicConsentInfo
is returned. When full consent info is available, ConsentInfo
is returned.
A wrong type cast from
Null
toint
causes an exception in theConsentInfo.parseRawInfo
factory.It looks like it is thrown in this line.
Try-catch like below can't catch it and the app stops there, which is critical...
I'm not 100% sure in what condition it occurs, but as far as I can see, there's no problem if a GDPR dialog is shown outside EEA using your "user_messaging_platform" plugin with the debug options (
geography: DebugGeography.EEA, testDeviceIds: xxxxx
) set, and the exception occurs whencurrentConsentInfo()
is executed after the dialog is skipped without the debug options.