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.64k stars 3.96k forks source link

🐛 [cloud_functions]: HttpsCallableResult nested object returned as InternalLinkedHashmap of objects? #6546

Closed radvansky-tomas closed 1 year ago

radvansky-tomas commented 3 years ago

Consider having simple https function, but instead of having primitive array of string (like is in example), you've added object inside for example

{
 "nested": {
     "field":123
   }
}

In this scenario HttpsCallableResult correctly returns data of Map<String, dynamic>, however if you access field "nested" its not of the same type Map<String, dynamic> but _InternalLinkedHashmap<Object?, Object?> which THROWS cast errors on initiating Maps from it (for example by using JSON serializer)

markusaksli-nc commented 3 years ago

Hi @radvansky-tomas Could you please provide your flutter doctor -v and flutter pub deps -- --style=compact? Thank you

radvansky-tomas commented 3 years ago
[✓] Flutter (Channel beta, 2.3.0-24.1.pre, on macOS 11.3.1 20E241 darwin-arm, locale en-NZ)
    • Flutter version 2.3.0-24.1.pre at /Users/tomasradvansky/fvm/versions/beta
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 615957513e (11 days ago), 2021-06-25 09:24:44 -0700
    • Engine revision 9d517f475b
    • Dart version 2.14.0 (build 2.14.0-188.5.beta)

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at /Users/tomasradvansky/Library/Android/sdk
    • Platform android-30, build-tools 30.0.3
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.5, Build version 12E262
    • CocoaPods version 1.10.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 4.2)
    • 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.8+10-b944.6916264)

[✓] VS Code (version 1.57.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.24.0
Dart SDK 2.14.0-188.5.beta
Flutter SDK 2.3.0-24.1.pre
****cesored***_platform 4.0.0

dependencies:
- abstract_widget_view 0.0.1 [flutter]
- adaptive_breakpoints 0.0.4 [flutter]
- adaptive_navigation 0.0.3 [flutter adaptive_breakpoints]
- badges 2.0.1 [flutter]
- camera 0.8.1+3 [camera_platform_interface flutter pedantic quiver]
- cloud_firestore 2.3.0 [cloud_firestore_platform_interface cloud_firestore_web firebase_core firebase_core_platform_interface flutter meta]
- cloud_functions 2.0.0 [cloud_functions_platform_interface cloud_functions_web firebase_core firebase_core_platform_interface flutter]
- collection 1.15.0
- connectivity 3.0.6 [flutter meta connectivity_platform_interface connectivity_macos connectivity_for_web]
- crop_box 1.0.2 [flutter image_editor image_size_getter exif]
- csv 5.0.0
- cupertino_icons 1.0.3
- equatable 2.0.3 [collection meta]
- file_picker 3.0.3 [flutter flutter_web_plugins flutter_plugin_android_lifecycle plugin_platform_interface]
- firebase_auth 2.0.0 [firebase_auth_platform_interface firebase_auth_web firebase_core firebase_core_platform_interface flutter meta]
- firebase_core 1.3.0 [firebase_core_platform_interface firebase_core_web flutter meta]
- firebase_storage 9.0.0 [firebase_core firebase_core_platform_interface firebase_storage_platform_interface firebase_storage_web flutter]
- flutter 0.0.0 [characters collection meta typed_data vector_math sky_engine]
- flutter_background_geolocation 4.0.2 [flutter collection background_fetch]
- flutter_datetime_picker 1.5.1 [flutter]
- flutter_modular 3.3.0 [flutter_modular_annotations triple flutter]
- geocoding 2.0.0 [flutter geocoding_platform_interface]
- global_configuration 2.0.0-nullsafety.1 [flutter http]
- google_fonts 2.1.0 [flutter http path_provider crypto]
- google_ml_vision 0.0.4 [flutter]
- http 0.13.3 [async http_parser meta path pedantic]
- image 3.0.2 [archive meta xml]
- image_picker 0.8.1+3 [flutter flutter_plugin_android_lifecycle image_picker_for_web image_picker_platform_interface]
- intl 0.17.0 [clock path]
- line_awesome_flutter 1.1.0-nullsafety [flutter]
- logger 1.0.0
****cesored***
- overlay_support 1.2.1 [flutter async]
- package_info_plus 1.0.3 [flutter package_info_plus_platform_interface package_info_plus_linux package_info_plus_macos package_info_plus_windows package_info_plus_web]
- percent_indicator 3.3.0-nullsafety.1 [flutter]
- reactive_forms 10.4.1 [flutter intl]
- retry 3.1.0
- rxdart 0.26.0
- universal_ntp 1.0.8 [universal_io]
- universal_platform 1.0.0+1
- url_launcher 6.0.8 [flutter meta url_launcher_linux url_launcher_macos url_launcher_platform_interface url_launcher_web url_launcher_windows]
- uuid 3.0.4 [crypto]

dev dependencies:
- build_runner 2.0.5 [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 pedantic pool pub_semver pubspec_parse shelf shelf_web_socket stack_trace stream_transform timing watcher web_socket_channel yaml]
- faker 2.0.0 [crypto]
- flutter_test 0.0.0 [flutter test_api path fake_async clock stack_trace vector_math async boolean_selector characters charcode collection matcher meta source_span stream_channel string_scanner term_glyph typed_data]
- json_annotation 4.0.1
- json_serializable 4.1.3 [analyzer build build_config collection json_annotation meta path source_gen]
- mockito 5.0.10 [analyzer build code_builder collection dart_style matcher meta path source_gen test_api]
- pedantic 1.11.1

transitive dependencies:
- _fe_analyzer_shared 22.0.0 [meta]
- analyzer 1.7.0 [_fe_analyzer_shared cli_util collection convert crypto glob meta package_config path pub_semver source_span watcher yaml pedantic]
- archive 3.1.2 [crypto path]
- args 2.1.1
- async 2.7.0 [collection meta]
- background_fetch 1.0.1 [flutter]
- boolean_selector 2.1.0 [source_span string_scanner]
- build 2.0.2 [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.0 [built_collection built_value http_multi_server logging pedantic path pool shelf shelf_web_socket stream_transform watcher web_socket_channel]
- build_resolvers 2.0.3 [analyzer async build crypto graphs logging path package_config pool pub_semver stream_transform yaml]
- build_runner_core 7.0.0 [async build build_config build_resolvers collection convert crypto glob graphs json_annotation logging meta path package_config pedantic pool timing watcher yaml]
- built_collection 5.1.0
- built_value 8.1.0 [built_collection collection fixnum meta]
- camera_platform_interface 2.0.1 [flutter meta plugin_platform_interface cross_file stream_transform]
- characters 1.1.0
- charcode 1.2.0
- checked_yaml 2.0.1 [json_annotation source_span yaml]
- cli_util 0.3.1 [meta path]
- clock 1.1.0
- cloud_firestore_platform_interface 5.2.0 [collection firebase_core flutter meta plugin_platform_interface]
- cloud_firestore_web 2.2.0 [cloud_firestore_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins js]
- cloud_functions_platform_interface 5.0.7 [firebase_core flutter meta plugin_platform_interface]
- cloud_functions_web 4.0.9 [cloud_functions_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins js]
- code_builder 4.0.0 [built_collection built_value collection matcher meta]
- connectivity_for_web 0.4.0 [connectivity_platform_interface flutter_web_plugins flutter]
- connectivity_macos 0.2.0 [flutter]
- connectivity_platform_interface 2.0.1 [flutter meta plugin_platform_interface]
- convert 3.0.1 [typed_data]
- cross_file 0.3.1+1 [flutter meta]
- crypto 3.0.1 [collection typed_data]
- dart_style 2.0.1 [analyzer args path pub_semver source_span]
- dartz 0.10.0-nullsafety.2
- exif 2.2.0 [args collection convert sprintf]
- fake_async 1.2.0 [clock collection]
- ffi 1.1.2
- file 6.1.2 [meta path]
- firebase_auth_platform_interface 5.0.0 [firebase_core flutter meta plugin_platform_interface]
- firebase_auth_web 2.0.0 [firebase_auth_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins http_parser intl js meta]
- firebase_core_platform_interface 4.0.1 [collection flutter meta plugin_platform_interface]
- firebase_core_web 1.1.0 [firebase_core_platform_interface flutter flutter_web_plugins js meta]
- firebase_storage_platform_interface 3.0.0 [collection firebase_core flutter meta plugin_platform_interface]
- firebase_storage_web 2.0.0 [async firebase_core firebase_core_web firebase_storage_platform_interface flutter flutter_web_plugins http js meta]
- fixnum 1.0.0
- flutter_modular_annotations 0.0.2 [flutter]
- flutter_plugin_android_lifecycle 2.0.2 [flutter]
- flutter_web_plugins 0.0.0 [flutter js characters collection meta typed_data vector_math]
- frontend_server_client 2.1.0 [async path]
- geocoding_platform_interface 2.0.0 [flutter meta plugin_platform_interface]
- glob 2.0.1 [async collection file path pedantic string_scanner]
- graphs 2.0.0
- hashcodes 2.0.0
- http_multi_server 3.0.1 [async]
- http_parser 4.0.0 [charcode collection source_span string_scanner typed_data]
- image_editor 1.0.0 [flutter]
- image_picker_for_web 2.0.0 [image_picker_platform_interface meta flutter flutter_web_plugins]
- image_picker_platform_interface 2.1.0 [flutter meta http plugin_platform_interface]
- image_size_getter 1.0.0 [collection hashcodes]
- io 1.0.0 [meta path string_scanner]
- js 0.6.3
- logging 1.0.1
- matcher 0.12.10 [stack_trace]
- meta 1.4.0
- mime 1.0.0
- package_config 2.0.0 [path]
- package_info_plus_linux 1.0.2 [package_info_plus_platform_interface flutter path]
- package_info_plus_macos 1.1.1 [flutter]
- package_info_plus_platform_interface 1.0.1 [flutter meta plugin_platform_interface]
- package_info_plus_web 1.0.2 [http package_info_plus_platform_interface flutter flutter_web_plugins meta]
- package_info_plus_windows 1.0.2 [package_info_plus_platform_interface ffi flutter win32]
- path 1.8.0
- path_provider 2.0.2 [flutter path_provider_platform_interface path_provider_macos path_provider_linux path_provider_windows]
- path_provider_linux 2.0.0 [path xdg_directories path_provider_platform_interface flutter]
- path_provider_macos 2.0.0 [flutter]
- path_provider_platform_interface 2.0.1 [flutter meta platform plugin_platform_interface]
- path_provider_windows 2.0.1 [path_provider_platform_interface meta path flutter ffi win32]
- petitparser 4.1.0 [meta]
- platform 3.0.0
- plugin_platform_interface 2.0.0 [meta]
- pool 1.5.0 [async stack_trace]
- process 4.2.1 [file path platform]
- pub_semver 2.0.0 [collection]
- pubspec_parse 1.0.0 [checked_yaml collection json_annotation pub_semver yaml]
- quiver 3.0.1 [matcher]
- shelf 1.1.4 [async collection http_parser path stack_trace stream_channel]
- shelf_web_socket 1.0.1 [shelf stream_channel web_socket_channel]
- sky_engine 0.0.99
- source_gen 1.0.2 [analyzer async build dart_style glob meta path pedantic source_span yaml]
- source_span 1.8.1 [collection path term_glyph]
- sprintf 6.0.0
- 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]
- term_glyph 1.2.0
- test_api 0.4.0 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph matcher]
- timing 1.0.0 [json_annotation]
- triple 1.0.2 [meta async dartz]
- typed_data 1.3.0 [collection]
- universal_io 1.0.1 [meta zone_local]
- url_launcher_linux 2.0.0 [flutter]
- url_launcher_macos 2.0.0 [flutter]
- url_launcher_platform_interface 2.0.3 [flutter plugin_platform_interface]
- url_launcher_web 2.0.1 [flutter flutter_web_plugins meta url_launcher_platform_interface]
- url_launcher_windows 2.0.0 [flutter]
- vector_math 2.1.0
- watcher 1.0.0 [async path pedantic]
- web_socket_channel 2.1.0 [async crypto stream_channel]
- win32 2.2.4 [ffi]
- xdg_directories 0.2.0 [meta path process]
- xml 5.1.2 [collection meta petitparser]
- yaml 3.1.0 [collection source_span string_scanner]
- zone_local 0.1.2
radvansky-tomas commented 3 years ago

Only resolution I found so far is to enable "anyMap:true" under json serializer and basically loose Map<String,dynamic> type

But if thats way to go, I dont understand why result is type of Map<String,dynamic> and not generic Map. (of dynamic)

markusaksli-nc commented 3 years ago

Was able to reproduce this with cloud_functions: ^2.0.0.

flutter doctor -v ``` [√] Flutter (Channel master, 2.4.0-1.0.pre.94, on Microsoft Windows [Version 10.0.19041.1052], locale et-EE) • Flutter version 2.4.0-1.0.pre.94 at C:\Development\flutter_master • Upstream repository https://github.com/flutter/flutter.git • Framework revision ba143ae21e (5 hours ago), 2021-07-06 22:01:02 -0700 • Engine revision 60eea42346 • Dart version 2.14.0 (build 2.14.0-284.0.dev) [√] Android toolchain - develop for Android devices (Android SDK version 30.0.2) • Android SDK at C:\Users\marku\AppData\Local\Android\sdk • Platform android-30, build-tools 30.0.2 • Java binary at: C:\Users\marku\AppData\Local\JetBrains\Toolbox\apps\AndroidStudio\ch-0\202.7486908\jre\bin\java • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6842174) • All Android licenses accepted. [√] Chrome - develop for the web • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe [√] Visual Studio - develop for Windows (Visual Studio Community 2019 16.7.7) • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community • Visual Studio Community 2019 version 16.7.30621.155 • Windows 10 SDK version 10.0.18362.0 [√] Android Studio (version 4.2.0) • Android Studio at C:\Users\marku\AppData\Local\JetBrains\Toolbox\apps\AndroidStudio\ch-0\202.7486908 • Flutter plugin version 58.0.1 • Dart plugin version 202.8531 • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6842174) [√] IntelliJ IDEA Ultimate Edition (version 2021.1) • IntelliJ at C:\Users\marku\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\211.7628.21 • 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 [√] Connected device (4 available) • SM G950F (mobile) • ce12171c51cc001c03 • android-arm64 • Android 9 (API 28) • Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.19041.1052] • Chrome (web) • chrome • web-javascript • Google Chrome 91.0.4472.124 • Edge (web) • edge • web-javascript • Microsoft Edge 91.0.864.54 • No issues found! ```
radvansky-tomas commented 3 years ago

Any update on this ?

crazyguysdev commented 2 years ago

Same problem here... As there is no solution, currently I'm parsing the response data myself and using it.


dynamic renderValue(dynamic value) {
  if (value is List) {
    return _renderList(value);
  }
  if (value is Map) {
    return _renderMap(value);
  }
  return value;
}

List _renderList(List list) {
  final result = [];
  for (int i = 0; i < list.length; i++) {
    result.add(renderValue(list[i]));
  }
  return result;
}

Map _renderMap(Map map) {
  final result = <String, dynamic>{};
  map.entries.forEach((entry) {
    result[entry.key as String] = renderValue(entry.value);
  });
  return result;
}

final response = await callable.call<Map<String, dynamic>>()
renderValue(response.data)
masterfego commented 2 years ago

I have the same issue with cloud_functions: ^3.3.1 All the nested Object has a type of _InternalLinkedHashMap<Object?, Object?>, throwing error all the time.

This is making the library useless

We do not receive from our API basics types like a list of Fruits.

Can a serious refactor be done to receive a Map<"string", dynamic> instead?

Lyokone commented 1 year ago

Hi, trying to get the data from a nested map I don't face any issues: https://github.com/firebase/flutterfire/pull/10054

I've probably misunderstood what you are trying to achieve. Do you care to explain in more detail?

masterfego commented 1 year ago

If you get the result from the library and decode it to objects, most of the libraries required a Map<String, dynamic>. But this library returns a different type that throws the exception that we are referring.

We need to manually transform the _InternalLinkedHashMap<Object?, Object?>, to a Map<String, dynamic>.

Lyokone commented 1 year ago

@masterfego If you look at the linked PR, I'm using json_serializable which is the standard library for JSON parsing without any issue. Please share your code to see if your use case is something that we want to support.

google-oss-bot commented 1 year ago

Hey @radvansky-tomas. 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!

google-oss-bot commented 1 year ago

Since there haven't been any recent updates here, I am going to close this issue.

@radvansky-tomas if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.