I'm trying to create a custom logEvent to monitor the changes in my JSON model using the Firebase dashboard. The following class is an example of my object with a method to create a JSON map:
class AddressInfo {
String address;
String city;
List<String> phoneNumbers = <String>[];
AddressInfo({
this.address,
this.city,
this.phoneNumbers,
});
Map<String, dynamic> toJson() => {
'address': address,
'city': city,
'phoneNumbers': phoneNumbers,
};
}
I called the function logEvent of FirebaseAnalytics, and passed the JSON object in parameters like this:
_sendAnalyticsEvent(String eventName, AddressInfo addressInfo) async {
FirebaseAnalytics analytics = FirebaseAnalytics();
await analytics.logEvent(
name: eventName,
parameters: addressInfo.toJson(),
);
}
And, I get the below exception in the Flutter console:
E/MethodChannel#plugins.flutter.io/firebase_analytics(19272): Failed to handle method call
E/MethodChannel#plugins.flutter.io/firebase_analytics(19272): java.lang.IllegalArgumentException: Unsupported value type: java.util.ArrayList
E/MethodChannel#plugins.flutter.io/firebase_analytics(19272): at io.flutter.plugins.firebaseanalytics.FirebaseAnalyticsPlugin.createBundleFromMap(FirebaseAnalyticsPlugin.java:188)
E/MethodChannel#plugins.flutter.io/firebase_analytics(19272): at io.flutter.plugins.firebaseanalytics.FirebaseAnalyticsPlugin.handleLogEvent(FirebaseAnalyticsPlugin.java:118)
E/MethodChannel#plugins.flutter.io/firebase_analytics(19272): at io.flutter.plugins.firebaseanalytics.FirebaseAnalyticsPlugin.onMethodCall(FirebaseAnalyticsPlugin.java:84)
E/MethodChannel#plugins.flutter.io/firebase_analytics(19272): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:233)
E/MethodChannel#plugins.flutter.io/firebase_analytics(19272): at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
E/MethodChannel#plugins.flutter.io/firebase_analytics(19272): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:818)
E/MethodChannel#plugins.flutter.io/firebase_analytics(19272): at android.os.MessageQueue.nativePollOnce(Native Method)
E/MethodChannel#plugins.flutter.io/firebase_analytics(19272): at android.os.MessageQueue.next(MessageQueue.java:326)
E/MethodChannel#plugins.flutter.io/firebase_analytics(19272): at android.os.Looper.loop(Looper.java:181)
E/MethodChannel#plugins.flutter.io/firebase_analytics(19272): at android.app.ActivityThread.main(ActivityThread.java:7073)
E/MethodChannel#plugins.flutter.io/firebase_analytics(19272): at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#plugins.flutter.io/firebase_analytics(19272): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
E/MethodChannel#plugins.flutter.io/firebase_analytics(19272): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)
E/flutter (19272): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: PlatformException(error, Unsupported value type: java.util.ArrayList, null, java.lang.IllegalArgumentException: Unsupported value type: java.util.ArrayList
E/flutter (19272): at io.flutter.plugins.firebaseanalytics.FirebaseAnalyticsPlugin.createBundleFromMap(FirebaseAnalyticsPlugin.java:188)
E/flutter (19272): at io.flutter.plugins.firebaseanalytics.FirebaseAnalyticsPlugin.handleLogEvent(FirebaseAnalyticsPlugin.java:118)
E/flutter (19272): at io.flutter.plugins.firebaseanalytics.FirebaseAnalyticsPlugin.onMethodCall(FirebaseAnalyticsPlugin.java:84)
E/flutter (19272): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:233)
E/flutter (19272): at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
E/flutter (19272): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:818)
E/flutter (19272): at android.os.MessageQueue.nativePollOnce(Native Method)
E/flutter (19272): at android.os.MessageQueue.next(MessageQueue.java:326)
E/flutter (19272): at android.os.Looper.loop(Looper.java:181)
E/flutter (19272): at android.app.ActivityThread.main(ActivityThread.java:7073)
E/flutter (19272): at java.lang.reflect.Method.invoke(Native Method)
E/flutter (19272): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
E/flutter (19272): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)
E/flutter (19272): )
E/flutter (19272): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:581:7)
E/flutter (19272): #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:158:18)
E/flutter (19272): <asynchronous suspension>
E/flutter (19272): #2 FirebaseAnalytics.logEvent (package:firebase_analytics/firebase_analytics.dart:43:5)
E/flutter (19272): <asynchronous suspension>
I faced a Java error because I'm using an Android device for development. Also, the exception reveals an issue with converting ArrayList when passing an object of dart type List to the logEvent method like the phoneNumbers in the AddressInfo. The expectation is we should be able to log a list because sometimes our list is growable, and its length is unexpected. So, separating parameters is the last choice and not recommended.
I'm using Flutter Channel stable, 2.0.2, and I will also test on an iOS device to see if the problem is specific to Android.
Update
It seems there is an open GitHub issue related to this problem here: https://github.com/FirebaseExtended/flutterfire/issues/2835
Question
Should I fix this issue by developing a native implementation for each platform? Or am I missing something here with doing custom events?