firestoreodm-flutter
firestoreodm-flutter copied to clipboard
[ODM] Cannot search on Enums (Code Generator does not produce where for type enum)
Moved from: https://github.com/firebase/flutterfire/issues/8338
Bug report
When having a field with a type enum, the ODM generator automagically produces code to store or retrieve the values (technically as a String), however it does not create the .whereEnumField and .orderEnumField code. It is my assumption this is supposed to work because it will store/retrieve the enums.
Steps to reproduce
Steps to reproduce the behavior:
- Create a Model with an (userRef) enum
- Create a document using the model to store the enum (usersRef.add(myEnum: testEnum.red))
- Attempt to search the model with usersRef.whereMyEnum(isEqualTo: testEnum.red)
Expected behavior
A method .whereMyEnum should be created for each enum field.
Sample project
enum ContentType {
text,
image,
video,
audio,
}
@JsonSerializable()
class TestUser {
TestUser({
required this.name,
required this.age,
required this.email,
this.timestamp = 0,
this.contentType = ContentType.text,
}) {
this.timestamp = Timestamp.now().microsecondsSinceEpoch; //Timestamp.now() nanoseconds.toString();
}
String name;
final String email;
int timestamp;
final contentType;
@Min(0)
final int age;
}
@Collection<TestUser>('test_users')
final testUsersRef = TestUserCollectionReference();
[...] testUsersRef.whereContentType(isEqualTo: ContentType.text); // Doesn't work
Additional context
As a quick effort, I attempted to add f.isEnumConstant to collection_generator.dart just to see if it would attempt to produce some code, but didn't:
queryableFields: collectionTargetElement.fields
.where((f) => f.isPublic)
.where(
(f) =>
f.type.isDartCoreString ||
f.type.isDartCoreNum ||
f.type.isDartCoreInt ||
f.type.isDartCoreDouble ||
f.type.isDartCoreBool ||
f.type.isDartCoreList ||
f.isEnumConstant, // ADDED to Test Enums
// TODO filter list other than LIst<string|bool|num>
)
.toList(),
Flutter doctor
Run flutter doctor
and paste the output below:
Click To Expand
flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 2.10.3, on Microsoft Windows [Version 10.0.19044.1586], locale en-US)
[√] Android toolchain - develop for Android devices (Android SDK version 32.0.0-rc1)
[√] Chrome - develop for the web
[√] Visual Studio - develop for Windows (Visual Studio Community 2022 17.1.1)
[√] Android Studio (version 2021.1)
[!] Android Studio
X android-studio-dir = C:\Users\mark\AppData\Local\JetBrains\Toolbox\apps\AndroidStudio
X Unable to find bundled Java version.
[√] IntelliJ IDEA Ultimate Edition (version 2021.3)
[√] Connected device (4 available)
[√] HTTP Host Availability
Flutter dependencies
Run flutter pub deps -- --style=compact
and paste the output below:
Click To Expand
flutter pub deps -- --style=compact
Dart SDK 2.16.1
Flutter SDK 2.10.3
peache_flutter_video 1.0.2+3
dependencies:
- align_positioned 3.0.0 [matrix4_transform flutter]
- animated_text_kit 4.2.1 [flutter characters]
- cached_network_image 3.2.0 [flutter flutter_cache_manager octo_image cached_network_image_platform_interface cached_network_image_web]
- camera 0.9.4+16 [camera_platform_interface camera_web flutter flutter_plugin_android_lifecycle quiver]
- cloud_firestore 3.1.10 [cloud_firestore_platform_interface cloud_firestore_web collection firebase_core firebase_core_platform_interface flutter meta]
- cloud_firestore_odm 1.0.0-dev.10 [cloud_firestore flutter meta]
- confetti 0.6.0 [flutter vector_math]
- cupertino_icons 1.0.4
- 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]
- device_preview 0.7.4 [flutter flutter_localizations provider path_provider device_frame font_awesome_flutter http freezed_annotation json_annotation shared_preferences pedantic path]
- exif 3.1.1 [args collection convert json_annotation sprintf]
- firebase_analytics 8.3.4 [firebase_analytics_platform_interface firebase_analytics_web firebase_core flutter meta]
- firebase_auth 3.3.11 [firebase_auth_platform_interface firebase_auth_web firebase_core firebase_core_platform_interface flutter meta]
- firebase_core 1.13.1 [firebase_core_platform_interface firebase_core_web flutter meta]
- firebase_crashlytics 2.5.3 [firebase_core firebase_core_platform_interface firebase_crashlytics_platform_interface flutter stack_trace]
- firebase_messaging 11.2.11 [firebase_core firebase_core_platform_interface firebase_messaging_platform_interface firebase_messaging_web flutter meta]
- firebase_storage 10.2.9 [firebase_core firebase_core_platform_interface firebase_storage_platform_interface firebase_storage_web flutter]
- flare_flutter 3.0.2 [collection flutter meta]
- flutter 0.0.0 [characters collection material_color_utilities meta typed_data vector_math sky_engine]
- flutter_local_notifications 9.4.0 [clock flutter flutter_local_notifications_linux flutter_local_notifications_platform_interface timezone]
- flutter_riverpod 2.0.0-dev.4 [collection flutter meta riverpod state_notifier]
- flutter_secure_storage 5.0.2 [meta flutter flutter_secure_storage_linux flutter_secure_storage_macos flutter_secure_storage_platform_interface flutter_secure_storage_web flutter_secure_storage_windows]
- flutter_sms 2.3.2 [flutter flutter_web_plugins plugin_platform_interface url_launcher]
- flutter_svg 0.22.0 [flutter meta path_drawing vector_math xml]
- flutter_tags_x 1.0.0 [flutter]
- flutter_typeahead 3.2.4 [flutter flutter_keyboard_visibility]
- flutter_webrtc 0.7.1 [flutter path_provider]
- fluttermoji 0.2.2 [flutter flutter_svg get shared_preferences]
- fluttertoast 8.0.9 [flutter flutter_web_plugins]
- font_awesome_flutter 10.0.0-beta [flutter lite_graphql]
- get_it 7.2.0 [async collection]
- google_sign_in 5.2.4 [flutter google_sign_in_platform_interface google_sign_in_web]
- http 0.13.4 [async http_parser meta path]
- image_picker 0.8.4+11 [flutter flutter_plugin_android_lifecycle image_picker_for_web image_picker_platform_interface]
- intl 0.17.0 [clock path]
- json_annotation 4.4.0 [meta]
- oauth2 2.0.0 [collection crypto http http_parser]
- 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_provider 2.0.9 [flutter path_provider_android path_provider_ios path_provider_linux path_provider_macos path_provider_platform_interface path_provider_windows]
- permission_handler 8.3.0 [flutter meta permission_handler_platform_interface]
- photo_view 0.13.0 [flutter]
- provider 5.0.0 [collection flutter nested]
- qr_flutter 4.0.0 [flutter qr]
- responsive_builder 0.4.2 [flutter]
- share 2.0.4 [meta mime flutter]
- shared_preferences 2.0.13 [flutter shared_preferences_android shared_preferences_ios shared_preferences_linux shared_preferences_macos shared_preferences_platform_interface shared_preferences_web shared_preferences_wind
ows]
- sms_autofill 2.2.0 [pin_input_text_field flutter]
- spincircle_bottom_bar 2.0.0 [flutter]
- telephony 0.1.4 [flutter platform]
- transparent_image 2.0.0
- uni_links 0.5.1 [flutter uni_links_platform_interface uni_links_web]
- universal_platform 1.0.0+1
- video_player 2.3.0 [flutter html video_player_android video_player_avfoundation video_player_platform_interface video_player_web]
- video_thumbnail 0.4.6 [flutter]
- visibility_detector 0.2.2 [flutter]
- xml 5.3.1 [collection meta petitparser]
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]
- cloud_firestore_odm_generator 1.0.0-dev.10 [analyzer build build_config cloud_firestore_odm collection json_annotation meta recase source_gen]
- flutter_launcher_icons 0.9.2 [args image path yaml]
- 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 te
rm_glyph typed_data]
- json_serializable 6.1.5 [analyzer async build build_config collection json_annotation meta path pub_semver pubspec_parse source_gen source_helper]
dependency overrides:
- font_awesome_flutter 10.0.0-beta [flutter lite_graphql]
transitive dependencies:
- _fe_analyzer_shared 31.0.0 [meta]
- analyzer 2.8.0 [_fe_analyzer_shared cli_util collection convert crypto glob meta package_config path pub_semver source_span watcher yaml]
- archive 3.2.2 [crypto path]
- args 2.3.0
- async 2.8.2 [collection meta]
- 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]
- camera_platform_interface 2.1.5 [cross_file flutter plugin_platform_interface stream_transform]
- camera_web 0.2.1+3 [camera_platform_interface flutter flutter_web_plugins stream_transform]
- characters 1.2.0
- charcode 1.3.1
- checked_yaml 2.0.1 [json_annotation source_span yaml]
- cli_util 0.3.5 [meta path]
- clock 1.1.0
- cloud_firestore_platform_interface 5.5.1 [collection firebase_core flutter meta plugin_platform_interface]
- cloud_firestore_web 2.6.10 [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]
- collection 1.15.0
- convert 3.0.1 [typed_data]
- cross_file 0.3.2 [flutter js meta]
- crypto 3.0.1 [collection typed_data]
- csslib 0.17.1 [source_span]
- dart_style 2.2.1 [analyzer args path pub_semver source_span]
- dbus 0.7.1 [args ffi meta xml]
- device_frame 0.4.2 [flutter_svg path_drawing freezed_annotation flutter]
- 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]
- fake_async 1.2.0 [clock collection]
- ffi 1.1.2
- file 6.1.2 [meta path]
- firebase 9.0.2 [http http_parser js]
- firebase_analytics_platform_interface 2.0.1 [flutter meta]
- firebase_analytics_web 0.3.0+1 [firebase firebase_analytics_platform_interface flutter flutter_web_plugins meta]
- firebase_auth_platform_interface 6.2.1 [firebase_core flutter meta plugin_platform_interface]
- firebase_auth_web 3.3.9 [firebase_auth_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins http_parser intl js meta]
- firebase_core_platform_interface 4.2.5 [collection flutter meta plugin_platform_interface]
- firebase_core_web 1.6.1 [firebase_core_platform_interface flutter flutter_web_plugins js meta]
- firebase_crashlytics_platform_interface 3.2.1 [collection firebase_core flutter meta plugin_platform_interface]
- firebase_messaging_platform_interface 3.2.1 [firebase_core flutter meta plugin_platform_interface]
- firebase_messaging_web 2.2.9 [firebase_core firebase_core_web firebase_messaging_platform_interface flutter flutter_web_plugins js meta]
- firebase_storage_platform_interface 4.1.1 [collection firebase_core flutter meta plugin_platform_interface]
- firebase_storage_web 3.2.10 [async firebase_core firebase_core_web firebase_storage_platform_interface flutter flutter_web_plugins http js meta]
- fixnum 1.0.0
- flutter_blurhash 0.6.4 [flutter]
- flutter_cache_manager 3.3.0 [clock collection file flutter http path path_provider pedantic rxdart sqflite uuid]
- flutter_keyboard_visibility 5.2.0 [meta flutter_keyboard_visibility_platform_interface flutter_keyboard_visibility_web flutter]
- flutter_keyboard_visibility_platform_interface 2.0.0 [flutter meta plugin_platform_interface]
- flutter_keyboard_visibility_web 2.0.0 [flutter_keyboard_visibility_platform_interface flutter_web_plugins flutter]
- flutter_local_notifications_linux 0.4.2 [flutter flutter_local_notifications_platform_interface dbus path xdg_directories]
- flutter_local_notifications_platform_interface 5.0.0 [flutter plugin_platform_interface]
- flutter_localizations 0.0.0 [flutter intl characters clock collection material_color_utilities meta path typed_data vector_math]
- flutter_plugin_android_lifecycle 2.0.5 [flutter]
- flutter_secure_storage_linux 1.1.0 [flutter flutter_secure_storage_platform_interface]
- flutter_secure_storage_macos 1.1.0 [flutter flutter_secure_storage_platform_interface]
- flutter_secure_storage_platform_interface 1.0.0 [flutter plugin_platform_interface]
- flutter_secure_storage_web 1.0.2 [flutter flutter_web_plugins flutter_secure_storage_platform_interface js]
- flutter_secure_storage_windows 1.1.2 [flutter flutter_secure_storage_platform_interface]
- flutter_web_plugins 0.0.0 [flutter js characters collection material_color_utilities meta typed_data vector_math]
- freezed_annotation 0.14.3 [collection json_annotation meta]
- frontend_server_client 2.1.2 [async path]
- get 4.6.1 [flutter]
- glob 2.0.2 [async collection file path string_scanner]
- google_sign_in_platform_interface 2.1.2 [flutter quiver]
- google_sign_in_web 0.10.0+5 [flutter flutter_web_plugins google_sign_in_platform_interface js]
- graphs 2.1.0 [collection]
- html 0.15.0 [csslib source_span]
- http_multi_server 3.2.0 [async]
- http_parser 4.0.0 [charcode collection source_span string_scanner typed_data]
- image 3.1.3 [archive meta xml]
- image_picker_for_web 2.1.6 [flutter flutter_web_plugins image_picker_platform_interface]
- image_picker_platform_interface 2.4.4 [cross_file flutter http plugin_platform_interface]
- io 1.0.3 [meta path string_scanner]
- js 0.6.3
- lite_graphql 0.0.1 [http logger]
- logger 1.1.0
- logging 1.0.2
- matcher 0.12.11 [stack_trace]
- material_color_utilities 0.1.3
- matrix4_transform 2.0.1 [flutter]
- meta 1.7.0
- mime 1.0.1
- 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.0
- path_drawing 0.5.1+1 [vector_math meta path_parsing flutter]
- path_parsing 0.2.1 [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_platform_interface 2.0.3 [flutter platform plugin_platform_interface]
- path_provider_windows 2.0.5 [ffi flutter path path_provider_platform_interface win32]
- pedantic 1.11.1
- permission_handler_platform_interface 3.7.0 [flutter meta plugin_platform_interface]
- petitparser 4.4.0 [meta]
- pin_input_text_field 4.1.2 [flutter]
- platform 3.1.0
- plugin_platform_interface 2.1.2 [meta]
- 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]
- qr 2.1.0 [meta]
- quiver 3.0.1+1 [matcher]
- recase 4.0.0
- riverpod 2.0.0-dev.4 [collection meta stack_trace state_notifier]
- rxdart 0.27.3
- shared_preferences_android 2.0.11 [flutter shared_preferences_platform_interface]
- shared_preferences_ios 2.1.0 [flutter shared_preferences_platform_interface]
- shared_preferences_linux 2.1.0 [file flutter path path_provider_linux path_provider_platform_interface shared_preferences_platform_interface]
- shared_preferences_macos 2.0.3 [flutter shared_preferences_platform_interface]
- shared_preferences_platform_interface 2.0.0 [flutter]
- shared_preferences_web 2.0.3 [flutter flutter_web_plugins shared_preferences_platform_interface]
- shared_preferences_windows 2.1.0 [file flutter path path_provider_platform_interface path_provider_windows shared_preferences_platform_interface]
- shelf 1.2.0 [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.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.1 [collection path term_glyph]
- sprintf 6.0.0
- sqflite 2.0.2 [flutter sqflite_common path]
- sqflite_common 2.2.1 [synchronized path meta]
- stack_trace 1.10.0 [path]
- state_notifier 0.7.2+1 [meta]
- stream_channel 2.1.0 [async]
- stream_transform 2.0.0
- string_scanner 1.1.0 [charcode source_span]
- synchronized 3.0.0
- term_glyph 1.2.0
- test_api 0.4.8 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph matcher]
- timezone 0.8.0 [path]
- timing 1.0.0 [json_annotation]
- typed_data 1.3.0 [collection]
- uni_links_platform_interface 1.0.0 [flutter plugin_platform_interface]
- uni_links_web 0.1.0 [flutter flutter_web_plugins uni_links_platform_interface]
- 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]
- 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]
- uuid 3.0.6 [crypto]
- vector_math 2.1.1
- video_player_android 2.3.1 [flutter video_player_platform_interface]
- video_player_avfoundation 2.3.1 [flutter video_player_platform_interface]
- video_player_platform_interface 5.1.0 [flutter plugin_platform_interface]
- video_player_web 2.0.7 [flutter flutter_web_plugins video_player_platform_interface]
- watcher 1.0.1 [async path]
- web_socket_channel 2.1.0 [async crypto stream_channel]
- win32 2.4.2 [ffi]
- xdg_directories 0.2.0+1 [meta path process]
- yaml 3.1.0 [collection source_span string_scanner]