Use DropdownMenuEntry<Object> for type safety#452
Use DropdownMenuEntry<Object> for type safety#452jogendra-flutter wants to merge 1 commit intoStacDev:devfrom
Conversation
This replaces implicit dynamic usage with DropdownMenuEntry<Object> to satisfy the analyzer and improve type safety.
📝 WalkthroughWalkthroughA type safety improvement narrowing dropdown menu entry filters from Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~5 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
packages/stac/lib/src/parsers/widgets/stac_dropdown_menu/stac_dropdown_menu_parser.dart (2)
41-42: Pre-existing resource leak:TextEditingControllerandFocusNodeare never disposed.Neither
_controllernor_focusNodeoverridesdispose(), which will leak resources when the widget is removed from the tree. This is not introduced by this PR, but the widget is touched here so it's worth addressing.♻️ Proposed fix — add a
disposeoverride+ `@override` + void dispose() { + _controller.dispose(); + _focusNode.dispose(); + super.dispose(); + } + `@override` Widget build(BuildContext context) {🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/stac/lib/src/parsers/widgets/stac_dropdown_menu/stac_dropdown_menu_parser.dart` around lines 41 - 42, The widget creates a TextEditingController (_controller) and a FocusNode (_focusNode) but never disposes them; add an override of dispose() in the widget's State class (the state that owns _controller/_focusNode in stac_dropdown_menu_parser) that calls _controller.dispose(); _focusNode.dispose(); and then super.dispose() to prevent the resource leak.
41-42: Pre-existing resource leak:TextEditingControllerandFocusNodeare never disposed.Neither
_controllernor_focusNodehas a correspondingdispose()call. This isn't introduced by this PR but is worth tracking to avoid memory/resource leaks.♻️ Proposed fix — add a `dispose` override
+ `@override` + void dispose() { + _controller.dispose(); + _focusNode.dispose(); + super.dispose(); + } + `@override` Widget build(BuildContext context) {🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/stac/lib/src/parsers/widgets/stac_dropdown_menu/stac_dropdown_menu_parser.dart` around lines 41 - 42, The TextEditingController (_controller) and FocusNode (_focusNode) are never disposed; add an override of dispose() in the State class that owns these fields (the State subclass in stac_dropdown_menu_parser.dart) and call dispose on both _controller and _focusNode before calling super.dispose(); ensure you reference TextEditingController and FocusNode and place the dispose logic in the same class where those fields are declared.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In
`@packages/stac/lib/src/parsers/widgets/stac_dropdown_menu/stac_dropdown_menu_parser.dart`:
- Around line 41-42: The widget creates a TextEditingController (_controller)
and a FocusNode (_focusNode) but never disposes them; add an override of
dispose() in the widget's State class (the state that owns
_controller/_focusNode in stac_dropdown_menu_parser) that calls
_controller.dispose(); _focusNode.dispose(); and then super.dispose() to prevent
the resource leak.
- Around line 41-42: The TextEditingController (_controller) and FocusNode
(_focusNode) are never disposed; add an override of dispose() in the State class
that owns these fields (the State subclass in stac_dropdown_menu_parser.dart)
and call dispose on both _controller and _focusNode before calling
super.dispose(); ensure you reference TextEditingController and FocusNode and
place the dispose logic in the same class where those fields are declared.
Title:
fix: use DropdownMenuEntry<Object> to fix type assignment errorThis replaces implicit dynamic usage with
DropdownMenuEntry<Object>to satisfy the analyzer and improve type safety.Description
DropdownMenu.dropdownMenuEntriesexpectsList<DropdownMenuEntry<Object>>, but the previous code producedList<DropdownMenuEntry<dynamic>>in two places:.whereType<DropdownMenuEntry>()— missing the<Object>type parameter, defaulting todynamicconst <DropdownMenuEntry<dynamic>>[]— fallback list explicitly typed asdynamicBecause Dart's generics are invariant,
List<DropdownMenuEntry<dynamic>>is not assignable toList<DropdownMenuEntry<Object>>, causing a compile-time error on newer Flutter/Dart SDK versions.Fix: Added
<Object>to both expressions so the unified type resolves toList<DropdownMenuEntry<Object>>.Related Issues
Closes #
Type of Change
Summary by CodeRabbit