-
Notifications
You must be signed in to change notification settings - Fork 584
feat!: make Tooltip
a dataclass which can be used in Control.tooltip
#3837
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Reviewer's Guide by SourceryThis pull request significantly refactors the File-Level Changes
Tips
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @ndonkoHenri - I've reviewed your changes and they look great!
Here's what I looked at during the review
- 🟡 General issues: 2 issues found
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟡 Complexity: 2 issues found
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.
LONG_PRESS = "long_press" | ||
|
||
|
||
@dataclass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Consider adding documentation for the new Tooltip dataclass
The change to a dataclass is good, but it would be helpful to add a class-level docstring explaining the new structure and any breaking changes from the previous implementation.
@dataclass | |
@dataclass | |
class Tooltip: | |
""" | |
Tooltips provide text labels which help explain the function of a button or other user interface action. | |
This dataclass implementation replaces the previous Tooltip class. | |
It offers a more concise and type-safe way to create and manage tooltips. | |
""" |
return tooltipFromJSON(j, widget, theme); | ||
} | ||
|
||
Tooltip? tooltipFromJSON(dynamic j, Widget widget, ThemeData theme) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Add documentation for the expected JSON structure
Please add a comment explaining the expected JSON structure for this function. This will help developers correctly format their tooltip data.
Tooltip? tooltipFromJSON(dynamic j, Widget widget, ThemeData theme) { | |
/// Converts a JSON object to a Tooltip widget. | |
/// Expected JSON structure: | |
/// { | |
/// "message": "Tooltip text", | |
/// "preferBelow": true, | |
/// "verticalOffset": 20.0 | |
/// } | |
Tooltip? tooltipFromJSON(dynamic j, Widget widget, ThemeData theme) { |
animate_offset: AnimationValue = None, | ||
on_animation_end: OptionalEventCallable = None, | ||
tooltip: Optional[str] = None, | ||
tooltip: Optional[Union[str, Tooltip]] = None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (complexity): Consider using a single type for the tooltip parameter.
The recent change to the tooltip
parameter, switching from Optional[str]
to Optional[Union[str, Tooltip]]
, introduces additional complexity. Handling multiple types increases the complexity of the code, as it requires additional logic to manage both str
and Tooltip
types. This can lead to more complex conditionals and type-checking, potentially increasing maintenance overhead. To simplify, consider using a single type for tooltip
, or if Tooltip
is necessary, ensure its usage is well-documented and justified. This will help maintain readability and ease of understanding for future developers.
AnimationValue = Optional[Union[bool, int, Animation]] | ||
|
||
|
||
@dataclass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (complexity): Consider using a single unit of time for duration values.
The introduction of the Duration
class has increased the complexity of the code. It adds a new data structure with multiple fields, which can lead to confusion and potential misuse. The redundancy with existing time representations (like using integers for milliseconds) further complicates the code. To simplify, consider using a single unit of time (e.g., milliseconds) for all duration values and avoid introducing a new class unless necessary for additional functionality. This will reduce cognitive load and make the code easier to maintain.
sdk/python/packages/flet-core/src/flet_core/animated_switcher.py
Outdated
Show resolved
Hide resolved
Oh, well, could you merge |
# Conflicts: # packages/flet/lib/src/controls/tooltip.dart # sdk/python/packages/flet-core/src/flet_core/animated_switcher.py # sdk/python/packages/flet-core/src/flet_core/card.py # sdk/python/packages/flet-core/src/flet_core/charts/bar_chart.py # sdk/python/packages/flet-core/src/flet_core/charts/line_chart.py # sdk/python/packages/flet-core/src/flet_core/charts/pie_chart.py # sdk/python/packages/flet-core/src/flet_core/checkbox.py # sdk/python/packages/flet-core/src/flet_core/chip.py # sdk/python/packages/flet-core/src/flet_core/circle_avatar.py # sdk/python/packages/flet-core/src/flet_core/cupertino_action_sheet.py # sdk/python/packages/flet-core/src/flet_core/cupertino_action_sheet_action.py # sdk/python/packages/flet-core/src/flet_core/cupertino_activity_indicator.py # sdk/python/packages/flet-core/src/flet_core/cupertino_button.py # sdk/python/packages/flet-core/src/flet_core/cupertino_checkbox.py # sdk/python/packages/flet-core/src/flet_core/cupertino_date_picker.py # sdk/python/packages/flet-core/src/flet_core/cupertino_list_tile.py # sdk/python/packages/flet-core/src/flet_core/cupertino_picker.py # sdk/python/packages/flet-core/src/flet_core/cupertino_radio.py # sdk/python/packages/flet-core/src/flet_core/cupertino_segmented_button.py # sdk/python/packages/flet-core/src/flet_core/cupertino_slider.py # sdk/python/packages/flet-core/src/flet_core/cupertino_sliding_segmented_button.py # sdk/python/packages/flet-core/src/flet_core/cupertino_switch.py # sdk/python/packages/flet-core/src/flet_core/cupertino_textfield.py # sdk/python/packages/flet-core/src/flet_core/cupertino_timer_picker.py # sdk/python/packages/flet-core/src/flet_core/datatable.py # sdk/python/packages/flet-core/src/flet_core/dismissible.py # sdk/python/packages/flet-core/src/flet_core/dropdown.py # sdk/python/packages/flet-core/src/flet_core/elevated_button.py # sdk/python/packages/flet-core/src/flet_core/expansion_tile.py # sdk/python/packages/flet-core/src/flet_core/flet_app.py # sdk/python/packages/flet-core/src/flet_core/floating_action_button.py # sdk/python/packages/flet-core/src/flet_core/form_field_control.py # sdk/python/packages/flet-core/src/flet_core/icon.py # sdk/python/packages/flet-core/src/flet_core/icon_button.py # sdk/python/packages/flet-core/src/flet_core/image.py # sdk/python/packages/flet-core/src/flet_core/interactive_viewer.py # sdk/python/packages/flet-core/src/flet_core/list_tile.py # sdk/python/packages/flet-core/src/flet_core/lottie.py # sdk/python/packages/flet-core/src/flet_core/map/map.py # sdk/python/packages/flet-core/src/flet_core/markdown.py # sdk/python/packages/flet-core/src/flet_core/matplotlib_chart.py # sdk/python/packages/flet-core/src/flet_core/menu_item_button.py # sdk/python/packages/flet-core/src/flet_core/outlined_button.py # sdk/python/packages/flet-core/src/flet_core/pagelet.py # sdk/python/packages/flet-core/src/flet_core/placeholder.py # sdk/python/packages/flet-core/src/flet_core/plotly_chart.py # sdk/python/packages/flet-core/src/flet_core/popup_menu_button.py # sdk/python/packages/flet-core/src/flet_core/progress_bar.py # sdk/python/packages/flet-core/src/flet_core/progress_ring.py # sdk/python/packages/flet-core/src/flet_core/radio.py # sdk/python/packages/flet-core/src/flet_core/range_slider.py # sdk/python/packages/flet-core/src/flet_core/rive.py # sdk/python/packages/flet-core/src/flet_core/safe_area.py # sdk/python/packages/flet-core/src/flet_core/search_bar.py # sdk/python/packages/flet-core/src/flet_core/segmented_button.py # sdk/python/packages/flet-core/src/flet_core/semantics.py # sdk/python/packages/flet-core/src/flet_core/shader_mask.py # sdk/python/packages/flet-core/src/flet_core/slider.py # sdk/python/packages/flet-core/src/flet_core/submenu_button.py # sdk/python/packages/flet-core/src/flet_core/switch.py # sdk/python/packages/flet-core/src/flet_core/text.py # sdk/python/packages/flet-core/src/flet_core/text_button.py # sdk/python/packages/flet-core/src/flet_core/textfield.py # sdk/python/packages/flet-core/src/flet_core/tooltip.py # sdk/python/packages/flet-core/src/flet_core/transparent_pointer.py # sdk/python/packages/flet-core/src/flet_core/video.py # sdk/python/packages/flet-core/src/flet_core/webview.py # sdk/python/packages/flet-core/src/flet_core/window_drag_area.py # sdk/python/packages/flet-core/tests/test_tooltip.py
Summary by Sourcery
Refactor the
Tooltip
component to be a dataclass, enhancing its flexibility and integration across various components. This change allows tooltips to be specified as either a simple string or a more complexTooltip
instance, providing more customization options for developers.New Features:
Tooltip
dataclass to provide text labels for user interface elements, allowing for more structured and flexible tooltip configurations.Enhancements:
Tooltip
implementation to use a dataclass, simplifying the code and improving maintainability.Tooltip
dataclass, allowing tooltips to be specified as either a string or aTooltip
instance.Chores:
Tooltip
class implementation and associated test files, cleaning up deprecated code.