Is there an existing issue for this?
Which plugins are affected?
Cloud Functions
Which platforms are affected?
Android, iOS
Description
When fetching data from cloud function using httpsCallable.call on android or ios, the returned data is List, the response from the cloud function is array of json objects.
The current implementation of MethodChannelHttpsCallable does not correctly handle the types returned by cloud functions when the result is multiple objects (List). it handle only the map object so if List will not be handled and will be returned as List and in dart this map should has the same datatype so if my fromJson method accepts Map<String,dynamic> this will throw exception because Map is not subtype of type Map<String,dynamic>
Steps to Reproduce
Call a cloud function that is supposed to return a List<Map<String, dynamic>>.
Observe that the returned type is List, causing type mismatches when trying to parse or use the data as List<Map<String, dynamic>>.
Expected Behavior
The expected behavior is that the returned result from the cloud function should be correctly typed as List<Map<String, dynamic>> when the data structure from the cloud function is structured as such.
Actual Behavior
The result returned from the cloud function is treated as List, and further operations expecting List<Map<String, dynamic>> fail due to type mismatches.
Proposed Solution
To address this issue, implement a nested conversion method similar to the _convertNested method found in packages/cloud_functions/cloud_functions_web/lib/interop/functions.dart. This method would ensure proper type handling by recursively converting nested Maps and Lists to their respective Dart representations.
Proposed Code Change
// Method to handle nested conversions
dynamic _convertNested(dynamic object) {
if (object is List) {
return object.map(_convertNested).toList();
} else if (object is Map) {
var map = <String, dynamic>{};
object.forEach((key, value) {
map[key] = _convertNested(value);
});
return map;
} else {
return object;
}
}
// Usage of _convertNested in the call method
@Override
Future<dynamic> call([Object? parameters]) async {
try {
Object? result = await MethodChannelFirebaseFunctions.channel
.invokeMethod('FirebaseFunctions#call', <String, dynamic>{
'appName': functions.app!.name,
'functionName': name,
'functionUri': uri?.toString(),
'origin': origin,
'region': functions.region,
'timeout': options.timeout.inMilliseconds,
'parameters': parameters,
'limitedUseAppCheckToken': options.limitedUseAppCheckToken,
});
return _convertNested(result);
} catch (e, s) {
convertPlatformException(e, s);
}
}
Reproducing the issue
-
make a cloud function that returns List result
-
make the parse method that takes list and parse them to a datatype for example
static NearbyPlacesStruct fromMap(Map<String, dynamic> data) =>
-
call this method the error will be thrown
Unhandled Exception: type '_Map<Object?, Object?>' is not a subtype of type 'Map<String, dynamic>'
Firebase Core version
2.31.0
Flutter Version
3.22.2
Relevant Log Output
Unhandled Exception: type '_Map<Object?, Object?>' is not a subtype of type 'Map<String, dynamic>'
Flutter dependencies
Expand Flutter dependencies snippet
╔════════════════════════════════════════════════════════════════════════════╗
║ Welcome to Flutter! - https://flutter.dev ║
║ ║
║ The Flutter tool uses Google Analytics to anonymously report feature usage ║
║ statistics and basic crash reports. This data is used to help improve ║
║ Flutter tools over time. ║
║ ║
║ Flutter tool analytics are not sent on the very first run. To disable ║
║ reporting, type 'flutter config --no-analytics'. To display the current ║
║ setting, type 'flutter config'. If you opt out of analytics, an opt-out ║
║ event will be sent, and then no further information will be sent by the ║
║ Flutter tool. ║
║ ║
║ By downloading the Flutter SDK, you agree to the Google Terms of Service. ║
║ The Google Privacy Policy describes how data is handled in this service. ║
║ ║
║ Moreover, Flutter includes the Dart SDK, which may send usage metrics and ║
║ crash reports to Google. ║
║ ║
║ Read about data we send with crash reports: ║
║ https://flutter.dev/docs/reference/crash-reporting ║
║ ║
║ See Google's privacy policy: ║
║ https://policies.google.com/privacy ║
║ ║
║ To disable animations in this tool, use ║
║ 'flutter config --no-cli-animations'. ║
╚════════════════════════════════════════════════════════════════════════════╝
Dart SDK 3.4.3
Flutter SDK 3.22.2
talabat_tinder 1.0.0+1
dependencies:
- auto_size_text 3.0.0 [flutter]
- barcode_widget 2.0.3 [barcode flutter]
- bonsoir 5.1.9 [flutter bonsoir_platform_interface bonsoir_android bonsoir_darwin bonsoir_windows bonsoir_linux]
- cached_network_image 3.3.1 [cached_network_image_platform_interface cached_network_image_web flutter flutter_cache_manager octo_image]
- cloud_firestore 4.17.3 [cloud_firestore_platform_interface cloud_firestore_web collection firebase_core firebase_core_platform_interface flutter meta]
- cloud_firestore_platform_interface 6.2.3 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface]
- cloud_firestore_web 3.12.3 [_flutterfire_internals cloud_firestore_platform_interface collection firebase_core firebase_core_web flutter flutter_web_plugins]
- cloud_functions 4.7.4 [cloud_functions_platform_interface cloud_functions_web firebase_core firebase_core_platform_interface flutter]
- cloud_functions_platform_interface 5.5.26 [firebase_core flutter meta plugin_platform_interface]
- cloud_functions_web 4.9.4 [cloud_functions_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins]
- collection 1.18.0
- cupertino_icons 1.0.8
- data_table_2 2.5.10 [flutter async]
- easy_debounce 2.0.1 [flutter]
- firebase_auth 4.19.5 [firebase_auth_platform_interface firebase_auth_web firebase_core firebase_core_platform_interface flutter meta]
- firebase_auth_platform_interface 7.2.6 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface]
- firebase_auth_web 5.11.5 [firebase_auth_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins http_parser meta web]
- firebase_core 2.31.0 [firebase_core_platform_interface firebase_core_web flutter meta]
- firebase_core_platform_interface 5.0.0 [collection flutter flutter_test meta plugin_platform_interface]
- firebase_core_web 2.17.0 [firebase_core_platform_interface flutter flutter_web_plugins meta web]
- firebase_performance 0.9.4+5 [firebase_core firebase_core_platform_interface firebase_performance_platform_interface firebase_performance_web flutter]
- firebase_performance_platform_interface 0.1.4+33 [_flutterfire_internals firebase_core flutter plugin_platform_interface]
- firebase_performance_web 0.1.6+5 [_flutterfire_internals firebase_core firebase_core_web firebase_performance_platform_interface flutter flutter_web_plugins]
- flutter 0.0.0 [characters collection material_color_utilities meta vector_math sky_engine]
- flutter_animate 4.5.0 [flutter flutter_shaders]
- flutter_barcode_scanner 2.0.0 [flutter flutter_plugin_android_lifecycle]
- flutter_cache_manager 3.3.1 [clock collection file flutter http path path_provider rxdart sqflite uuid]
- flutter_card_swiper 6.0.0 [flutter]
- flutter_localizations 0.0.0 [flutter intl characters clock collection material_color_utilities meta path vector_math]
- flutter_plugin_android_lifecycle 2.0.20 [flutter]
- flutter_rating_bar 4.0.1 [flutter]
- flutter_staggered_grid_view 0.7.0 [flutter]
- font_awesome_flutter 10.6.0 [flutter]
- from_css_color 2.0.0 [flutter]
- geolocator 12.0.0 [flutter geolocator_platform_interface geolocator_android geolocator_apple geolocator_web geolocator_windows]
- geolocator_android 4.6.0 [flutter geolocator_platform_interface meta uuid]
- geolocator_apple 2.3.7 [flutter geolocator_platform_interface]
- geolocator_platform_interface 4.2.3 [flutter plugin_platform_interface vector_math meta]
- geolocator_web 4.0.0 [flutter flutter_web_plugins geolocator_platform_interface web]
- go_router 12.1.3 [collection flutter flutter_web_plugins logging meta]
- google_fonts 6.1.0 [flutter http path_provider crypto]
- google_maps 7.1.0 [js js_wrapping meta web]
- google_maps_flutter 2.6.1 [flutter google_maps_flutter_android google_maps_flutter_ios google_maps_flutter_platform_interface google_maps_flutter_web]
- google_maps_flutter_android 2.8.1 [flutter flutter_plugin_android_lifecycle google_maps_flutter_platform_interface stream_transform]
- google_maps_flutter_ios 2.6.1 [flutter google_maps_flutter_platform_interface stream_transform]
- google_maps_flutter_platform_interface 2.7.1 [collection flutter plugin_platform_interface stream_transform]
- google_maps_flutter_web 0.5.7 [collection flutter flutter_web_plugins google_maps google_maps_flutter_platform_interface sanitize_html stream_transform web]
- google_sign_in 6.1.5 [flutter google_sign_in_android google_sign_in_ios google_sign_in_platform_interface google_sign_in_web]
- google_sign_in_android 6.1.20 [flutter google_sign_in_platform_interface]
- google_sign_in_ios 5.6.4 [flutter google_sign_in_platform_interface pigeon]
- google_sign_in_platform_interface 2.4.2 [flutter plugin_platform_interface quiver]
- google_sign_in_web 0.12.1 [flutter flutter_web_plugins google_identity_services_web google_sign_in_platform_interface http js]
- intl 0.19.0 [clock meta path]
- json_path 0.7.2 [iregexp maybe_just_nothing petitparser rfc_6901]
- location 6.0.2 [flutter location_platform_interface location_web]
- page_transition 2.1.0 [flutter]
- path_provider 2.1.3 [flutter path_provider_android path_provider_foundation path_provider_linux path_provider_platform_interface path_provider_windows]
- path_provider_android 2.2.5 [flutter path_provider_platform_interface]
- path_provider_foundation 2.4.0 [flutter path_provider_platform_interface]
- path_provider_platform_interface 2.1.2 [flutter platform plugin_platform_interface]
- permission_handler 11.3.0 [flutter meta permission_handler_android permission_handler_apple permission_handler_html permission_handler_windows permission_handler_platform_interface]
- plugin_platform_interface 2.1.8 [meta]
- pointer_interceptor 0.10.1+1 [flutter flutter_web_plugins pointer_interceptor_ios pointer_interceptor_platform_interface pointer_interceptor_web]
- provider 6.1.2 [collection flutter nested]
- rxdart 0.27.7
- share_plus 9.0.0 [cross_file meta mime flutter flutter_web_plugins share_plus_platform_interface file url_launcher_web url_launcher_windows url_launcher_linux url_launcher_platform_interface ffi web win32]
- shared_preferences 2.2.2 [flutter shared_preferences_android shared_preferences_foundation shared_preferences_linux shared_preferences_platform_interface shared_preferences_web shared_preferences_windows]
- shared_preferences_android 2.2.1 [flutter shared_preferences_platform_interface]
- shared_preferences_foundation 2.3.4 [flutter shared_preferences_platform_interface]
- shared_preferences_platform_interface 2.3.1 [flutter plugin_platform_interface]
- shared_preferences_web 2.2.1 [flutter flutter_web_plugins shared_preferences_platform_interface]
- sign_in_with_apple 4.3.0 [flutter meta sign_in_with_apple_platform_interface sign_in_with_apple_web]
- sign_in_with_apple_platform_interface 1.0.0 [flutter plugin_platform_interface meta]
- sign_in_with_apple_web 1.0.1 [flutter flutter_web_plugins sign_in_with_apple_platform_interface js]
- sqflite 2.2.6 [flutter sqflite_common path]
- stream_transform 2.1.0
- substring_highlight 1.0.33 [flutter]
- timeago 3.6.1 [intl]
- url_launcher 6.2.5 [flutter url_launcher_android url_launcher_ios url_launcher_linux url_launcher_macos url_launcher_platform_interface url_launcher_web url_launcher_windows]
- url_launcher_android 6.3.0 [flutter url_launcher_platform_interface]
- url_launcher_ios 6.2.5 [flutter url_launcher_platform_interface]
- url_launcher_platform_interface 2.3.2 [flutter plugin_platform_interface]
dev dependencies:
- flutter_launcher_icons 0.13.1 [args checked_yaml cli_util image json_annotation path yaml]
- flutter_lints 4.0.0 [lints]
- flutter_test 0.0.0 [flutter test_api matcher path fake_async clock stack_trace vector_math leak_tracker_flutter_testing async boolean_selector characters collection leak_tracker leak_tracker_testing material_color_utilities meta source_span stream_channel string_scanner term_glyph vm_service]
- image 4.0.17 [archive meta xml]
- lints 4.0.0
dependency overrides:
- http 1.2.1 [async http_parser meta web]
- uuid 4.4.0 [crypto sprintf meta fixnum]
transitive dependencies:
- _fe_analyzer_shared 61.0.0 [meta]
- _flutterfire_internals 1.3.33 [collection firebase_core firebase_core_platform_interface flutter meta]
- analyzer 5.13.0 [_fe_analyzer_shared collection convert crypto glob meta package_config path pub_semver source_span watcher yaml]
- archive 3.6.1 [crypto path]
- args 2.5.0
- async 2.11.0 [collection meta]
- barcode 2.2.8 [meta qr]
- bonsoir_android 5.1.4 [flutter bonsoir_platform_interface]
- bonsoir_darwin 5.1.2 [flutter bonsoir_platform_interface]
- bonsoir_linux 5.1.2 [flutter bonsoir_platform_interface dbus meta]
- bonsoir_platform_interface 5.1.2 [flutter meta plugin_platform_interface]
- bonsoir_windows 5.1.4 [flutter bonsoir_platform_interface]
- boolean_selector 2.1.1 [source_span string_scanner]
- cached_network_image_platform_interface 4.0.0 [flutter flutter_cache_manager]
- cached_network_image_web 1.2.0 [cached_network_image_platform_interface flutter flutter_cache_manager]
- characters 1.3.0
- checked_yaml 2.0.3 [json_annotation source_span yaml]
- cli_util 0.4.1 [meta path]
- clock 1.1.1
- convert 3.1.1 [typed_data]
- cross_file 0.3.4+1 [meta web]
- crypto 3.0.3 [typed_data]
- csslib 1.0.0 [source_span]
- dbus 0.7.10 [args ffi meta xml]
- fake_async 1.3.1 [clock collection]
- ffi 2.1.2
- file 7.0.0 [meta path]
- fixnum 1.1.0
- flutter_shaders 0.1.2 [flutter vector_math]
- flutter_web_plugins 0.0.0 [flutter characters collection material_color_utilities meta vector_math]
- geolocator_windows 0.2.3 [flutter geolocator_platform_interface]
- glob 2.1.2 [async collection file path string_scanner]
- google_identity_services_web 0.2.2 [js meta]
- html 0.15.4 [csslib source_span]
- http_parser 4.0.2 [collection source_span string_scanner typed_data]
- iregexp 0.1.2 [petitparser]
- js 0.6.7 [meta]
- js_wrapping 0.7.4 [js]
- json_annotation 4.9.0 [meta]
- leak_tracker 10.0.4 [clock collection meta path vm_service]
- leak_tracker_flutter_testing 3.0.3 [flutter leak_tracker leak_tracker_testing matcher meta]
- leak_tracker_testing 3.0.1 [leak_tracker matcher meta]
- location_platform_interface 4.0.0 [flutter plugin_platform_interface]
- location_web 5.0.1 [flutter flutter_web_plugins http_parser js location_platform_interface]
- logging 1.2.0
- matcher 0.12.16+1 [async meta stack_trace term_glyph test_api]
- material_color_utilities 0.8.0 [collection]
- maybe_just_nothing 0.5.3
- meta 1.12.0
- mime 1.0.5
- nested 1.0.0 [flutter]
- octo_image 2.0.0 [flutter]
- package_config 2.1.0 [path]
- path 1.9.0
- path_provider_linux 2.2.1 [ffi flutter path path_provider_platform_interface xdg_directories]
- path_provider_windows 2.2.1 [ffi flutter path path_provider_platform_interface win32]
- permission_handler_android 12.0.7 [flutter permission_handler_platform_interface]
- permission_handler_apple 9.4.5 [flutter permission_handler_platform_interface]
- permission_handler_html 0.1.1 [flutter flutter_web_plugins permission_handler_platform_interface]
- permission_handler_platform_interface 4.2.1 [flutter meta plugin_platform_interface]
- permission_handler_windows 0.2.1 [flutter permission_handler_platform_interface]
- petitparser 6.0.2 [meta]
- pigeon 11.0.1 [analyzer args collection meta path yaml]
- platform 3.1.4
- pointer_interceptor_ios 0.10.1 [flutter plugin_platform_interface pointer_interceptor_platform_interface]
- pointer_interceptor_platform_interface 0.10.0+1 [flutter plugin_platform_interface]
- pointer_interceptor_web 0.10.2 [flutter flutter_web_plugins plugin_platform_interface pointer_interceptor_platform_interface web]
- pub_semver 2.1.4 [collection meta]
- qr 3.0.1 [meta]
- quiver 3.2.1 [matcher]
- rfc_6901 0.2.0
- sanitize_html 2.1.0 [html meta]
- share_plus_platform_interface 4.0.0 [cross_file flutter meta mime plugin_platform_interface path_provider uuid]
- shared_preferences_linux 2.3.2 [file flutter path path_provider_linux path_provider_platform_interface shared_preferences_platform_interface]
- shared_preferences_windows 2.3.2 [file flutter path path_provider_platform_interface path_provider_windows shared_preferences_platform_interface]
- sky_engine 0.0.99
- source_span 1.10.0 [collection path term_glyph]
- sprintf 7.0.0
- sqflite_common 2.5.4 [synchronized path meta]
- stack_trace 1.11.1 [path]
- stream_channel 2.1.2 [async]
- string_scanner 1.2.0 [source_span]
- synchronized 3.1.0+1
- term_glyph 1.2.1
- test_api 0.7.0 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph]
- typed_data 1.3.2 [collection]
- url_launcher_linux 3.1.1 [flutter url_launcher_platform_interface]
- url_launcher_macos 3.2.0 [flutter url_launcher_platform_interface]
- url_launcher_web 2.3.1 [flutter flutter_web_plugins url_launcher_platform_interface web]
- url_launcher_windows 3.1.1 [flutter url_launcher_platform_interface]
- vector_math 2.1.4
- vm_service 14.2.1
- watcher 1.1.0 [async path]
- web 0.5.1
- win32 5.5.0 [ffi]
- xdg_directories 1.0.4 [meta path]
- xml 6.5.0 [collection meta petitparser]
- yaml 3.1.2 [collection source_span string_scanner]
Additional context and comments
This issue is crucial for ensuring that developers can handle complex data types returned from Firebase Cloud Functions correctly without resorting to manual type checks and conversions, which can lead to error-prone code and reduce productivity.
Is there an existing issue for this?
Which plugins are affected?
Cloud Functions
Which platforms are affected?
Android, iOS
Description
When fetching data from cloud function using
httpsCallable.callon android or ios, the returned data is List, the response from the cloud function is array of json objects.The current implementation of
MethodChannelHttpsCallabledoes not correctly handle the types returned by cloud functions when the result is multiple objects (List). it handle only the map object so if List will not be handled and will be returned as List and in dart this map should has the same datatype so if my fromJson method accepts Map<String,dynamic> this will throw exception because Map is not subtype of type Map<String,dynamic>Steps to Reproduce
Call a cloud function that is supposed to return a List<Map<String, dynamic>>.
Observe that the returned type is List, causing type mismatches when trying to parse or use the data as List<Map<String, dynamic>>.
Expected Behavior
The expected behavior is that the returned result from the cloud function should be correctly typed as List<Map<String, dynamic>> when the data structure from the cloud function is structured as such.
Actual Behavior
The result returned from the cloud function is treated as List, and further operations expecting List<Map<String, dynamic>> fail due to type mismatches.
Proposed Solution
To address this issue, implement a nested conversion method similar to the _convertNested method found in packages/cloud_functions/cloud_functions_web/lib/interop/functions.dart. This method would ensure proper type handling by recursively converting nested Maps and Lists to their respective Dart representations.
Proposed Code Change
Reproducing the issue
make a cloud function that returns List result
make the parse method that takes list and parse them to a datatype for example
static NearbyPlacesStruct fromMap(Map<String, dynamic> data) =>call this method the error will be thrown
Firebase Core version
2.31.0
Flutter Version
3.22.2
Relevant Log Output
Flutter dependencies
Expand
Flutter dependenciessnippetAdditional context and comments
This issue is crucial for ensuring that developers can handle complex data types returned from Firebase Cloud Functions correctly without resorting to manual type checks and conversions, which can lead to error-prone code and reduce productivity.