flutterfire
flutterfire copied to clipboard
_assertParameterTypesAreCorrect throws null check error
Bug report
Describe the bug Firebase analytics logEvent allows paramters to be Map<String, Object?>?, but if object is null it throws the following error:
Fatal Exception: io.flutter.plugins.firebase.crashlytics.FlutterError: 'package:firebase_analytics/src/firebase_analytics.dart': Failed assertion: line 1468 pos 9: 'value is String || value is num': 'string' OR 'number' must be set as the value of the parameter: user_id. null found instead
Steps to reproduce
Steps to reproduce the behavior:
- Add a logEvent with name and parameters
- In parameters add a map of key and value as null
Expected behavior
If you are checking whether the value is string or num, then it shouldn't allow the object to be null right? Paramters accept Map<String, Object>? rather than Map<String, Object?>?.
Sample project
FirebaseAnalytics.instance.logEvent(name: "logout", parameters: {
"user_id": user?.id,
"user_role": user?.designation.name,
"company_id": user?.company.id,
});
Here there's no syntax error but breaks the flow of the app during execution
Additional context
Add any other context about the problem here.
Flutter doctor
Run flutter doctor and paste the output below:
Click To Expand
[✓] Flutter (Channel stable, 3.16.9, on Ubuntu 22.04.3 LTS 6.5.0-15-generic, locale en_IN)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
[✓] Chrome - develop for the web
[✓] Linux toolchain - develop for Linux desktop
[✓] Android Studio (version 2023.1)
[✓] Android Studio (version 2021.2)
[✓] IntelliJ IDEA Community Edition (version 2023.1)
[✓] VS Code (version unknown)
✗ Unable to determine VS Code version.
[✓] Connected device (3 available)
[✓] Network resources
• No issues found!
Flutter dependencies
Run flutter pub deps -- --style=compact and paste the output below:
Click To Expand
- firebase_analytics 10.8.3 [firebase_analytics_platform_interface firebase_analytics_web firebase_core firebase_core_platform_interface flutter]
- firebase_core 2.25.2 [firebase_core_platform_interface firebase_core_web flutter meta]
Reproducible using the plugin example app.
To reproduce, modify any of the parameters for logEvent to null and call the method. It will throw an assertion error.
This is an assert in the plugin so it cuts across all the platforms. It might be better to change the type of the parameters object as pointed out above so that users of the plugin know that they can't set null values.
cc @russellwheatley