firebase / flutterfire

🔥 A collection of Firebase plugins for Flutter apps.
https://firebase.google.com/docs/flutter/setup
BSD 3-Clause "New" or "Revised" License
8.68k stars 3.97k forks source link

🐛 [firebase_analytics] Error when trying to send a list when logging event #8861

Closed victor-tinoco closed 1 year ago

victor-tinoco commented 2 years ago

Bug report

Describe the bug A PlatformException is thrown when trying to call logEvent passing a List on parameter.

This problem seems to be related to #4353 and #2835 (which was already addressed), so I can't understand why it's reproducing on the latest version. I'm using Android platform for this scenario.

Steps to reproduce

For example, when logging event:

FirebaseAnalytics.instance.logEvent(
  name: 'my_event_name',
  parameters: {
    'items': ['1', '2'],
  },
);

Logs the following on console:

image

Expected behavior

It should accept lists.


Flutter doctor

Run flutter doctor and paste the output below:

Click To Expand ``` Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel unknown, 3.0.1, on macOS 12.1 21C52 darwin-x64, locale en-BR) [✓] Android toolchain - develop for Android devices (Android SDK version 32.0.0) [✓] Xcode - develop for iOS and macOS (Xcode 13.4) [✓] Chrome - develop for the web [✓] Android Studio (version 2020.3) [✓] VS Code (version 1.67.2) [✓] Connected device (3 available) [✓] HTTP Host Availability • No issues found! ```

Flutter dependencies

Run flutter pub deps -- --style=compact and paste the output below:

Click To Expand ``` Dart SDK 2.17.1 Flutter SDK 3.0.1 trader 2.31.02+1000090 dependencies: - async 2.8.2 [collection meta] - cached_network_image 3.2.0 [flutter flutter_cache_manager octo_image cached_network_image_platform_interface cached_network_image_web] - clock 1.1.0 - cloud_firestore 3.1.11 [cloud_firestore_platform_interface cloud_firestore_web collection firebase_core firebase_core_platform_interface flutter meta] - collection 1.16.0 - copy_with_extension 4.0.0 - cpfcnpj 2.0.0 - datadog_flutter 2.0.0 [meta logging http flutter flutter_web_plugins js] - decimal 2.1.0 [rational] - device_info_plus 3.2.2 [flutter device_info_plus_platform_interface device_info_plus_macos device_info_plus_linux device_info_plus_web device_info_plus_windows] - dio 4.0.6 [http_parser path] - dotted_border 2.0.0+2 [flutter path_drawing] - facetec_flutter 1.1.1 [flutter freezed_annotation permission_handler] - file 6.1.2 [meta path] - firebase_analytics 9.1.9 [firebase_analytics_platform_interface firebase_analytics_web firebase_core firebase_core_platform_interface flutter] - firebase_core 1.14.0 [firebase_core_platform_interface firebase_core_web flutter meta] - firebase_crashlytics 2.6.0 [firebase_core firebase_core_platform_interface firebase_crashlytics_platform_interface flutter stack_trace] - firebase_performance 0.8.0+8 [firebase_core firebase_core_platform_interface firebase_performance_platform_interface firebase_performance_web flutter] - firebase_remote_config 2.0.3 [firebase_core firebase_core_platform_interface firebase_remote_config_platform_interface firebase_remote_config_web flutter] - flutter 0.0.0 [characters collection material_color_utilities meta vector_math sky_engine] - flutter_cache_manager 3.3.0 [clock collection file flutter http path path_provider pedantic rxdart sqflite uuid] - flutter_heartbeat 1.0.0 [flutter] - flutter_jailbreak_detection 1.8.0 [flutter] - flutter_localizations 0.0.0 [flutter intl characters clock collection material_color_utilities meta path vector_math] - flutter_mobx 2.0.4 [flutter mobx] - flutter_svg 1.0.3 [flutter meta path_drawing vector_math xml] - flutter_widget_from_html_core 0.8.5+1 [csslib flutter fwfh_text_style html] - freezed_annotation 1.1.0 [collection json_annotation meta] - html 0.15.0 [csslib source_span] - http_certificate_pinning 2.0.4 [dio flutter http] - intersperse 2.0.0 - intl 0.17.0 [clock path] - jaguar_jwt 3.0.0 [auth_header crypto] - local_auth 1.1.11 [flutter flutter_plugin_android_lifecycle intl platform] - logging 1.0.2 - lottie 1.2.2 [archive flutter path vector_math] - mask_text_input_formatter 2.3.0 [flutter] - mobx 2.0.6+1 [meta] - network_status_broadcaster 1.1.1 [logging rxdart] - open_file 3.2.1 [flutter ffi] - open_store 0.2.4 [flutter url_launcher] - orquestra 2.1.0 [flutter flutter_svg lottie modal_bottom_sheet shimmer] - otp 3.0.2 [base32 crypto logging] - package_info_plus 1.4.0 [flutter package_info_plus_platform_interface package_info_plus_linux package_info_plus_macos package_info_plus_windows package_info_plus_web] - path_drawing 1.0.0 [vector_math meta path_parsing flutter] - path_provider 2.0.10 [flutter path_provider_android path_provider_ios path_provider_linux path_provider_macos path_provider_platform_interface path_provider_windows] - permission_handler 9.2.0 [flutter meta permission_handler_android permission_handler_apple permission_handler_windows permission_handler_platform_interface] - pointycastle 3.5.2 [collection convert js] - provider 6.0.2 [collection flutter nested] - quiver 3.0.1+1 [matcher] - retrofit 3.0.1+1 [dio meta] - retry 3.1.0 - rxdart 0.27.3 - share_plus 4.0.3 [meta mime flutter share_plus_platform_interface share_plus_linux share_plus_macos share_plus_windows share_plus_web] - smooth_page_indicator 1.0.0+2 [flutter] - timeago 3.2.2 - url_launcher 6.0.20 [flutter url_launcher_android url_launcher_ios url_launcher_linux url_launcher_macos url_launcher_platform_interface url_launcher_web url_launcher_windows] - uuid 3.0.6 [crypto] - wakelock 0.6.1+2 [flutter meta wakelock_macos wakelock_platform_interface wakelock_web wakelock_windows] - webview_flutter 3.0.1 [flutter webview_flutter_android webview_flutter_platform_interface webview_flutter_wkwebview] dev dependencies: - build_runner 2.1.8 [args async analyzer build build_config build_daemon build_resolvers build_runner_core code_builder collection crypto dart_style frontend_server_client glob graphs http_multi_server io js logging meta mime package_config path pool pub_semver pubspec_parse shelf shelf_web_socket stack_trace stream_transform timing watcher web_socket_channel yaml] - copy_with_extension_gen 4.0.1 [analyzer build source_gen copy_with_extension] - fake_async 1.3.0 [clock collection] - flutter_test 0.0.0 [flutter test_api path fake_async clock stack_trace vector_math async boolean_selector characters charcode collection matcher material_color_utilities meta source_span stream_channel string_scanner term_glyph] - freezed 1.1.1 [analyzer build build_config collection meta source_gen freezed_annotation] - integration_test 0.0.0 [flutter flutter_driver flutter_test path vm_service archive async boolean_selector characters charcode clock collection crypto fake_async file matcher material_color_utilities meta source_span stack_trace stream_channel string_scanner sync_http term_glyph test_api typed_data vector_math webdriver] - json_serializable 6.1.5 [analyzer async build build_config collection json_annotation meta path pub_semver pubspec_parse source_gen source_helper] - mobx_codegen 2.0.5+2 [analyzer build build_resolvers meta mobx path source_gen] - mockito 5.1.0 [analyzer build code_builder collection dart_style matcher meta path source_gen test_api] - path_provider_platform_interface 2.0.3 [flutter platform plugin_platform_interface] - plugin_platform_interface 2.1.2 [meta] - retrofit_generator 4.0.1 [dio source_gen built_collection code_builder tuple retrofit analyzer dart_style build] transitive dependencies: - _fe_analyzer_shared 38.0.0 [meta] - analyzer 3.4.1 [_fe_analyzer_shared collection convert crypto glob meta package_config path pub_semver source_span watcher yaml] - archive 3.1.11 [crypto path] - args 2.3.0 - auth_header 3.0.1 - base32 2.1.1 - boolean_selector 2.1.0 [source_span string_scanner] - build 2.2.1 [analyzer async convert crypto glob logging meta path] - build_config 1.0.0 [checked_yaml json_annotation path pubspec_parse yaml] - build_daemon 3.0.1 [built_collection built_value http_multi_server logging path pool shelf shelf_web_socket stream_transform watcher web_socket_channel] - build_resolvers 2.0.6 [analyzer async build crypto graphs logging path package_config pool pub_semver stream_transform yaml] - build_runner_core 7.2.3 [async build build_config build_resolvers collection convert crypto glob graphs json_annotation logging meta path package_config pool timing watcher yaml] - built_collection 5.1.1 - built_value 8.1.4 [built_collection collection fixnum meta] - cached_network_image_platform_interface 1.0.0 [flutter flutter_cache_manager] - cached_network_image_web 1.0.1 [flutter flutter_cache_manager cached_network_image_platform_interface] - characters 1.2.0 - charcode 1.3.1 - checked_yaml 2.0.1 [json_annotation source_span yaml] - cloud_firestore_platform_interface 5.5.2 [collection firebase_core flutter meta plugin_platform_interface] - cloud_firestore_web 2.6.11 [cloud_firestore_platform_interface collection firebase_core firebase_core_web flutter flutter_web_plugins js] - code_builder 4.1.0 [built_collection built_value collection matcher meta] - convert 3.0.1 [typed_data] - crypto 3.0.1 [collection typed_data] - csslib 0.17.1 [source_span] - dart_style 2.2.2 [analyzer args path pub_semver source_span] - device_info_plus_linux 2.1.1 [device_info_plus_platform_interface file flutter meta] - device_info_plus_macos 2.2.2 [device_info_plus_platform_interface flutter] - device_info_plus_platform_interface 2.3.0+1 [flutter meta plugin_platform_interface] - device_info_plus_web 2.1.0 [device_info_plus_platform_interface flutter_web_plugins flutter] - device_info_plus_windows 2.1.1 [device_info_plus_platform_interface ffi flutter win32] - execution_queue 1.2.0 - ffi 1.1.2 - firebase 9.0.2 [http http_parser js] - firebase_analytics_platform_interface 3.1.7 [firebase_core flutter meta plugin_platform_interface] - firebase_analytics_web 0.4.0+14 [firebase_analytics_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins js] - firebase_core_platform_interface 4.4.0 [collection flutter meta plugin_platform_interface] - firebase_core_web 1.6.4 [firebase_core_platform_interface flutter flutter_web_plugins js meta] - firebase_crashlytics_platform_interface 3.2.2 [collection firebase_core flutter meta plugin_platform_interface] - firebase_performance_platform_interface 0.1.1+2 [firebase_core flutter plugin_platform_interface] - firebase_performance_web 0.1.0+8 [firebase firebase_core firebase_core_web firebase_performance_platform_interface flutter flutter_web_plugins js] - firebase_remote_config_platform_interface 1.1.2 [firebase_core flutter meta plugin_platform_interface] - firebase_remote_config_web 1.0.8 [firebase_core firebase_core_web firebase_remote_config_platform_interface flutter flutter_web_plugins js] - fixnum 1.0.0 - flutter_blurhash 0.6.4 [flutter] - flutter_driver 0.0.0 [file flutter flutter_test fuchsia_remote_debug_protocol path meta vm_service webdriver archive async boolean_selector characters charcode clock collection crypto matcher material_color_utilities platform process source_span stack_trace stream_channel string_scanner sync_http term_glyph test_api typed_data vector_math] - flutter_plugin_android_lifecycle 2.0.5 [flutter] - flutter_web_plugins 0.0.0 [flutter js characters collection material_color_utilities meta vector_math] - frontend_server_client 2.1.2 [async path] - fuchsia_remote_debug_protocol 0.0.0 [process vm_service file meta path platform] - fwfh_text_style 2.7.3+1 [flutter] - glob 2.0.2 [async collection file path string_scanner] - graphs 2.1.0 [collection] - http 0.13.4 [async http_parser meta path] - http_multi_server 3.2.0 [async] - http_parser 4.0.0 [charcode collection source_span string_scanner typed_data] - io 1.0.3 [meta path string_scanner] - js 0.6.4 - json_annotation 4.4.0 [meta] - matcher 0.12.11 [stack_trace] - material_color_utilities 0.1.4 - meta 1.7.0 - mime 1.0.1 - modal_bottom_sheet 2.0.1 [flutter] - nested 1.0.0 [flutter] - octo_image 1.0.1 [flutter flutter_blurhash] - package_config 2.0.2 [path] - package_info_plus_linux 1.0.3 [package_info_plus_platform_interface flutter path] - package_info_plus_macos 1.3.0 [flutter] - package_info_plus_platform_interface 1.0.2 [flutter meta plugin_platform_interface] - package_info_plus_web 1.0.4 [flutter flutter_web_plugins http meta package_info_plus_platform_interface] - package_info_plus_windows 1.0.4 [package_info_plus_platform_interface ffi flutter win32] - path 1.8.1 - path_parsing 1.0.0 [vector_math meta] - path_provider_android 2.0.12 [flutter path_provider_platform_interface] - path_provider_ios 2.0.8 [flutter path_provider_platform_interface] - path_provider_linux 2.1.5 [ffi flutter path path_provider_platform_interface xdg_directories] - path_provider_macos 2.0.5 [flutter path_provider_platform_interface] - path_provider_windows 2.0.5 [ffi flutter path path_provider_platform_interface win32] - pedantic 1.11.1 - permission_handler_android 9.0.2+1 [flutter permission_handler_platform_interface] - permission_handler_apple 9.0.4 [flutter permission_handler_platform_interface] - permission_handler_platform_interface 3.7.0 [flutter meta plugin_platform_interface] - permission_handler_windows 0.1.0 [flutter permission_handler_platform_interface] - petitparser 4.4.0 [meta] - platform 3.1.0 - pool 1.5.0 [async stack_trace] - process 4.2.4 [file path platform] - pub_semver 2.1.1 [collection meta] - pubspec_parse 1.2.0 [checked_yaml collection json_annotation pub_semver yaml] - rational 2.2.0 - share_plus_linux 3.0.0 [share_plus_platform_interface file flutter meta url_launcher] - share_plus_macos 3.0.0 [share_plus_platform_interface flutter] - share_plus_platform_interface 3.0.2 [flutter meta mime plugin_platform_interface] - share_plus_web 3.0.0 [share_plus_platform_interface url_launcher flutter flutter_web_plugins meta] - share_plus_windows 3.0.0 [share_plus_platform_interface flutter meta url_launcher] - shelf 1.3.0 [async collection http_parser path stack_trace stream_channel] - shelf_web_socket 1.0.1 [shelf stream_channel web_socket_channel] - shimmer 2.0.0 [flutter] - sky_engine 0.0.99 - source_gen 1.2.1 [analyzer async build dart_style glob meta path source_span yaml] - source_helper 1.3.1 [analyzer collection source_gen] - source_span 1.8.2 [collection path term_glyph] - sqflite 2.0.2 [flutter sqflite_common path] - sqflite_common 2.2.1 [synchronized path meta] - stack_trace 1.10.0 [path] - stream_channel 2.1.0 [async] - stream_transform 2.0.0 - string_scanner 1.1.0 [charcode source_span] - sync_http 0.3.0 - synchronized 3.0.0+2 - term_glyph 1.2.0 - test_api 0.4.9 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph matcher] - timing 1.0.0 [json_annotation] - tuple 2.0.0 [quiver] - typed_data 1.3.0 [collection] - url_launcher_android 6.0.15 [flutter url_launcher_platform_interface] - url_launcher_ios 6.0.15 [flutter url_launcher_platform_interface] - url_launcher_linux 3.0.0 [flutter url_launcher_platform_interface] - url_launcher_macos 3.0.0 [flutter url_launcher_platform_interface] - url_launcher_platform_interface 2.0.5 [flutter plugin_platform_interface] - url_launcher_web 2.0.9 [flutter flutter_web_plugins url_launcher_platform_interface] - url_launcher_windows 3.0.0 [flutter url_launcher_platform_interface] - vector_math 2.1.2 - vm_service 8.2.2 - wakelock_macos 0.4.0 [flutter flutter_web_plugins wakelock_platform_interface] - wakelock_platform_interface 0.3.0 [flutter meta] - wakelock_web 0.4.0 [flutter flutter_web_plugins js wakelock_platform_interface] - wakelock_windows 0.2.0 [flutter wakelock_platform_interface win32] - watcher 1.0.1 [async path] - web_socket_channel 2.1.0 [async crypto stream_channel] - webdriver 3.0.0 [archive matcher path stack_trace sync_http] - webview_flutter_android 2.8.3 [flutter webview_flutter_platform_interface] - webview_flutter_platform_interface 1.8.1 [flutter plugin_platform_interface] - webview_flutter_wkwebview 2.7.1 [flutter webview_flutter_platform_interface] - win32 2.5.1 [ffi] - xdg_directories 0.2.0+1 [meta path process] - xml 5.3.1 [collection meta petitparser] - yaml 3.1.0 [collection source_span string_scanner] ```

victor-tinoco commented 2 years ago

Actually, reading the PR (#4394), which addresses these issues, it seems that only Map iterables are supported by the current implementation.

image

Why? Is this behavior clear to the one who is using logEvent and sees a Map<String, Object?>? parameters property?

darshankawar commented 2 years ago

Thanks for the report @victor-tinoco. Per the PR implementation, it support Map iterables parameters: <String, dynamic>{ as you pointed correctly and seems to support sending Lists with Map<String, dynamic>.

Is this an acceptable solution for you ?

Is this behavior clear to the one who is using logEvent and sees a Map<String, Object?>? parameters property?

this probably can be added as document. If you agree, you may close this issue and open a documentation request for same.

victor-tinoco commented 2 years ago

But I don't think that this is an expected behavior, also, it seems to be an Android-only behavior. Shouldn't it be addressed instead of documented?

maheshj01 commented 2 years ago

Hi @victor-tinoco, Thanks for filing the issue. I can reproduce the issue, I certainly think that its a bug in parsing the object, Also, this seems android only,since it works fine on IOS.

logs ``` Launching lib/main.dart on sdk gphone arm64 in debug mode... Warning: Mapping new ns http://schemas.android.com/repository/android/common/02 to old ns http://schemas.android.com/repository/android/common/01 Warning: Mapping new ns http://schemas.android.com/repository/android/generic/02 to old ns http://schemas.android.com/repository/android/generic/01 Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/02 to old ns http://schemas.android.com/sdk/android/repo/addon2/01 Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/repository2/02 to old ns http://schemas.android.com/sdk/android/repo/repository2/01 Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/02 to old ns http://schemas.android.com/sdk/android/repo/sys-img2/01 Warning: Mapping new ns http://schemas.android.com/repository/android/common/02 to old ns http://schemas.android.com/repository/android/common/01 Warning: Mapping new ns http://schemas.android.com/repository/android/generic/02 to old ns http://schemas.android.com/repository/android/generic/01 Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/02 to old ns http://schemas.android.com/sdk/android/repo/addon2/01 Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/repository2/02 to old ns http://schemas.android.com/sdk/android/repo/repository2/01 Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/02 to old ns http://schemas.android.com/sdk/android/repo/sys-img2/01 Note: /Users/mahesh/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_analytics-9.1.9/android/src/main/java/io/flutter/plugins/firebase/analytics/FlutterFirebaseAnalyticsPlugin.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details. Note: /Users/mahesh/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_analytics-9.1.9/android/src/main/java/io/flutter/plugins/firebase/analytics/FlutterFirebaseAnalyticsPlugin.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. ✓ Built build/app/outputs/flutter-apk/app-debug.apk. W/FlutterActivityAndFragmentDelegate(29258): A splash screen was provided to Flutter, but this is deprecated. See flutter.dev/go/android-splash-migration for migration steps. Connecting to VM Service at ws://127.0.0.1:57866/ttF6iTfZvt8=/ws Reloaded 1 of 597 libraries in 467ms. Reloaded 1 of 597 libraries in 316ms. Reloaded 1 of 597 libraries in 259ms. Reloaded 1 of 597 libraries in 173ms. E/flutter (29258): [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: PlatformException(firebase_analytics, Unsupported value type: java.lang.String in list at key items, null, null) E/flutter (29258): #0 StandardMethodCodec.decodeEnvelope E/flutter (29258): #1 MethodChannel._invokeMethod E/flutter (29258): E/flutter (29258): #2 FirebaseAnalytics.logEvent E/flutter (29258): E/flutter (29258): #3 _MyHomePageState._sendAnalyticsEvent E/flutter (29258): E/flutter (29258): ```
flutter doctor -v (mac) ``` [✓] Flutter (Channel stable, 3.0.1, on macOS 12.3 21E230 darwin-arm, locale en-IN) • Flutter version 3.0.1 at /Users/mahesh/Documents/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision fb57da5f94 (3 days ago), 2022-05-19 15:50:29 -0700 • Engine revision caaafc5604 • Dart version 2.17.1 • DevTools version 2.12.2 [✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0) • Android SDK at /Users/mahesh/Library/Android/sdk • Platform android-32, build-tools 31.0.0 • ANDROID_HOME = /Users/mahesh/Library/Android/sdk • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7772763) • All Android licenses accepted. [!] Xcode - develop for iOS and macOS (Xcode 13.2.1) • Xcode at /Applications/Xcode.app/Contents/Developer ! CocoaPods 1.10.2 out of date (1.11.0 is recommended). CocoaPods is used to retrieve the iOS and macOS platform side's plugin code that responds to your plugin usage on the Dart side. Without CocoaPods, plugins will not work on iOS or macOS. For more info, see https://flutter.dev/platform-plugins To upgrade see https://guides.cocoapods.org/using/getting-started.html#installation for instructions. [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 2021.1) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7772763) [✓] IntelliJ IDEA Community Edition (version 2021.2.1) • IntelliJ at /Applications/IntelliJ IDEA CE.app • Flutter plugin version 61.2.4 • Dart plugin version 212.5080.8 [✓] VS Code (version 1.66.2) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.40.0 [✓] Connected device (4 available) • Redmi K20 Pro (mobile) • 192.168.1.2:5555 • android-arm64 • Android 11 (API 30) • iPhone 12 Pro (mobile) • 19FD0231-BFF0-441D-B584-AD94C4084525 • ios • com.apple.CoreSimulator.SimRuntime.iOS-15-2 (simulator) • macOS (desktop) • macos • darwin-arm64 • macOS 12.3 21E230 darwin-arm • Chrome (web) • chrome • web-javascript • Google Chrome 101.0.4951.64 [✓] HTTP Host Availability • All required HTTP hosts are available ! Doctor found issues in 1 category. ```
code sample ```dart // ignore_for_file: require_trailing_commas // Copyright 2017 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. import 'dart:async'; import 'package:firebase_core/firebase_core.dart'; import 'package:flutter/material.dart'; import 'package:firebase_analytics/firebase_analytics.dart'; import 'package:firebase_analytics/observer.dart'; import 'tabs_page.dart'; Future main() async { WidgetsFlutterBinding.ensureInitialized(); await Firebase.initializeApp(); runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({Key? key}) : super(key: key); static FirebaseAnalytics analytics = FirebaseAnalytics.instance; static FirebaseAnalyticsObserver observer = FirebaseAnalyticsObserver(analytics: analytics); @override Widget build(BuildContext context) { return MaterialApp( title: 'Firebase Analytics Demo', theme: ThemeData( primarySwatch: Colors.blue, ), navigatorObservers: [observer], home: MyHomePage( title: 'Firebase Analytics Demo', analytics: analytics, observer: observer, ), ); } } class MyHomePage extends StatefulWidget { MyHomePage({ Key? key, required this.title, required this.analytics, required this.observer, }) : super(key: key); final String title; final FirebaseAnalytics analytics; final FirebaseAnalyticsObserver observer; @override _MyHomePageState createState() => _MyHomePageState(); } class _MyHomePageState extends State { String _message = ''; void setMessage(String message) { setState(() { _message = message; }); Future.delayed(Duration(seconds: 2), () { setMessage(''); }); } Future _sendAnalyticsEvent() async { await widget.analytics.logEvent( name: 'test_event', parameters: { 'items': ['1', '2'], }, ); setMessage('logEvent succeeded'); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text(widget.title), ), body: Column( children: [ MaterialButton( onPressed: _sendAnalyticsEvent, child: const Text('Test logEvent'), ), Text(_message, style: const TextStyle(color: Color.fromARGB(255, 0, 155, 0))), ], ), floatingActionButton: FloatingActionButton( onPressed: () { Navigator.of(context).push(MaterialPageRoute( settings: const RouteSettings(name: TabsPage.routeName), builder: (BuildContext context) { return TabsPage(widget.observer); })); }, child: const Icon(Icons.tab), ), ); } } ```
mateusfccp commented 2 years ago

This is such a basic feature that I am surprised that it has not been solved yet.

@maheshmnj Do you know if this happens in the platform (plugin) side and has to be solved there? If this is the case, is there any open issue for this problem in the Android plugin repository (I couldn't actually find the repository, is it closed source)? Also, if this is the case, can we provide a workaround on the Flutter's plugin side?

I would be glad to help fixing this, but we have to first decide where's the problem and how we should solve it.

victor-tinoco commented 2 years ago

A viable solution with a recursive method was provided on #9005. It's a simple and basic fix, and I think that should be addressed as fast as possible.

Dalakoti07 commented 2 years ago

@victor-tinoco can you please tell how recursive method was provided on #9005 .

I am getting same issue while logging list of string.

victor-tinoco commented 2 years ago

@Dalakoti07 Sorry, I got it wrong. That issue is not related to this one.

russellwheatley commented 2 years ago

Hi @victor-tinoco, I've just tested this code:

FirebaseAnalytics.instance.logEvent(
  name: 'my_event_name',
  parameters: {
    'items': ['1', '2'],
  },
);

It did not appear in the analytic's dashboard when debugging iOS app. "items" array has a pre-defined shape and cannot be a list of numbers (like your example). The only solution for me is to throw an exception in the dart layer so that users can only use AnalyticsEventItem as a value in the "items" list, and every other property has to have a primitive value.

victor-tinoco commented 2 years ago

Hey @russellwheatley,

Right, it was a misleading (and coincidence) when providing an example and trying to name, generically, the example's list. Taking a look into logEvent method's implementation it seems that the items key-word is reserved:

image

First of all, it surely should be documented and throw an exception or any else feedback of unaccepted parameter.

Anyway, the issue's main problem seems to be still pending: we have a Map<String, Object?>? parameters which does not allow to pass any primitive-value-list when running into an Android device. Also, as aforementioned, into Android Analytics' method channel's implementation it clearly throws an exception when sending an Iterable of any non-Map type. It works properly in the iOS implementation and is such a basic requirement.

russellwheatley commented 2 years ago

@victor-tinoco - yes, correct, which is why I suggested we ought to throw an exception if it doesn't follow the correct schema. I am curious if you see those primitive values appear in the Firebase Analytics dashboard if you put them in a list when using iOS? I suspect not, as far as I'm aware, Item in the Items have a schema and anything else will be ignored. But it seems like you believe you do see primitive list values appear in the dashboard. Could you share a screenshot, please?

google-oss-bot commented 2 years ago

Hey @victor-tinoco. We need more information to resolve this issue but there hasn't been an update in 7 weekdays. I'm marking the issue as stale and if there are no new updates in the next 7 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

victor-tinoco commented 2 years ago

Hello @russellwheatley,

Sorry for the delay. I didn't have an able time to continue our discussion in this issue. Actually I didn't test it on dashboard when I had this problem, I just opened the issue since when in iOS it didn't crash but when in Android it was crashing.

Anyway I'm going to test here, but I think it should be shown into dashboard since on Android it works. Also, it is a such basic data type, so I can't understand a proper reason for this behavior.

russellwheatley commented 2 years ago

@victor-tinoco yes, a basic data type that is ignored by the Firebase SDK/Firebase server which is why it doesn't show in the dashboard at least from my testing. If you can provide evidence that it appears in the Firebase console, I would happily update the android code.

I suspect it doesn't work which is why my preference is to throw an exception across all platforms to alert users to an incorrect data type.

mateusfccp commented 2 years ago

@russellwheatley If Firebase does not support lists, why do we provide a dynamic API and throw at runtime? Wouldn't it be better/safer to provide an API that doesn't allow the consumer to try to send an unsupported type?

victor-tinoco commented 2 years ago

A sumtype-like model would be nice to make it clear. When providing a dynamic API, we shouldn't have too many edge-cases, which are error-prone. However, this change would result in breaking changes.

Anyway, I tested here and it appeared on dashboard but with a firebase_error, with the code 21, as parameter:

image

Therefore, if the decision will be to throw an exception, we must do so on all available platforms.