Skip to content
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

feat: expose more properties in Controls #4105

Merged
merged 31 commits into from
Oct 29, 2024
Merged

feat: expose more properties in Controls #4105

merged 31 commits into from
Oct 29, 2024

Conversation

ndonkoHenri
Copy link
Contributor

@ndonkoHenri ndonkoHenri commented Oct 5, 2024

Summary by Sourcery

Enhance the Flet core library by introducing new properties across multiple controls, including TextField, Text, Icon, PopupMenuButton, GestureDetector, Draggable, and NavigationBarDestination, to provide more customization and interaction options. Refactor existing functions and controls to improve flexibility, error handling, and support for adaptive design.

New Features:

  • Introduce new properties to the TextField control, including cursor_error_color, obscuring_character, enable_interactive_selection, and more, enhancing customization options.
  • Add new properties to the Text control, such as show_selection_cursor, enable_interactive_selection, and on_selection_change, to improve text interaction capabilities.
  • Implement new properties for the Icon control, including shadows, fill, apply_text_scaling, grade, weight, and optical_size, allowing for more detailed icon customization.
  • Introduce new properties to the PopupMenuButton control, such as menu_padding, style, popup_animation_style, and size_constraints, for enhanced menu customization.
  • Add new properties to the GestureDetector control, including exclude_from_semantics, trackpad_scroll_causes_scale, and allowed_devices, to refine gesture handling.
  • Introduce new properties to the Draggable control, such as axis, affinity, and max_simultaneous_drags, to enhance drag-and-drop functionality.
  • Add new properties to the NavigationBarDestination control, including adaptive, to support adaptive design.
  • Introduce new properties to the IconButton control, such as size_constraints, for better layout control.

Enhancements:

  • Refactor the buildInputDecoration function to support additional parameters like prefixIcon and suffixIcon, improving input decoration flexibility.
  • Enhance the parse functions for various controls to support default values and improve error handling.
  • Refactor the MenuBar control to streamline the creation of child controls and improve code readability.
  • Improve the handling of adaptive properties across various controls to better support platform-specific adaptations.

Copy link
Contributor

sourcery-ai bot commented Oct 5, 2024

Reviewer's Guide by Sourcery

This pull request exposes more properties in various controls, enhancing their customization capabilities. It also includes some refactoring and code improvements across multiple files.

Class diagram for updated TextField class

classDiagram
    class TextField {
        +Optional[bool] enable_interactive_selection
        +Optional[bool] enable_ime_personalized_learning
        +Optional[bool] can_request_focus
        +Optional[bool] ignore_pointers
        +Optional[bool] enable_scribble
        +Optional[bool] animate_cursor_opacity
        +Optional[bool] always_call_on_tap
        +PaddingValue scroll_padding
        +Optional[ClipBehavior] clip_behavior
        +Optional[Brightness] keyboard_brightness
        +Optional[MouseCursor] mouse_cursor
        +Optional[StrutStyle] strut_style
        +OptionalControlEventCallable on_click
        +Optional[Control] helper
        +Optional[Control] error
        +Union[None, str, Control] prefix_icon
        +Union[None, str, Control] suffix_icon
        +Optional[str] focus_color
        +Optional[bool] align_label_with_hint
        +DurationValue hint_fade_duration
        +Optional[int] hint_max_lines
        +Optional[int] helper_max_lines
        +Optional[int] error_max_lines
        +Optional[str] prefix_icon_color
        +Optional[BoxConstraints] prefix_icon_size_constraints
        +Optional[str] suffix_icon_color
        +Optional[BoxConstraints] suffix_icon_size_constraints
    }
Loading

Class diagram for updated Text class

classDiagram
    class Text {
        +Optional[bool] show_selection_cursor
        +Optional[bool] enable_interactive_selection
        +OptionalNumber selection_cursor_width
        +OptionalNumber selection_cursor_height
        +Optional[str] selection_cursor_color
        +OptionalControlEventCallable on_tap
        +OptionalEventCallable[TextSelectionChangeEvent] on_selection_change
    }
Loading

Class diagram for updated Icon class

classDiagram
    class Icon {
        +Union[BoxShadow, List[BoxShadow], None] shadows
        +OptionalNumber fill
        +Optional[bool] apply_text_scaling
        +OptionalNumber grade
        +OptionalNumber weight
        +OptionalNumber optical_size
    }
Loading

Class diagram for updated PopupMenuButton class

classDiagram
    class PopupMenuButton {
        +PaddingValue menu_padding
        +Optional[ButtonStyle] style
        +Optional[AnimationStyle] popup_animation_style
        +Optional[BoxConstraints] size_constraints
        +OptionalControlEventCallable on_select
    }
Loading

Class diagram for updated GestureDetector class

classDiagram
    class GestureDetector {
        +Optional[bool] exclude_from_semantics
        +Optional[bool] trackpad_scroll_causes_scale
        +Optional[Set[PointerDeviceType]] allowed_devices
    }
Loading

File-Level Changes

Change Details Files
Enhanced TextField control with additional properties and functionality
  • Added new properties such as cursor_error_color, obscuring_character, enable_interactive_selection, and more
  • Implemented new methods for the added properties
  • Updated the build method to include the new properties
sdk/python/packages/flet-core/src/flet_core/textfield.py
packages/flet/lib/src/controls/textfield.dart
Expanded FormFieldControl with new attributes and methods
  • Added properties like focus_color, align_label_with_hint, hint_fade_duration, and more
  • Implemented getter and setter methods for the new properties
  • Updated the buildInputDecoration method to include the new properties
sdk/python/packages/flet-core/src/flet_core/form_field_control.py
packages/flet/lib/src/utils/form_field.dart
Enhanced Icon control with additional customization options
  • Added properties like shadows, fill, apply_text_scaling, grade, weight, and optical_size
  • Implemented getter and setter methods for the new properties
  • Updated the build method to include the new properties
sdk/python/packages/flet-core/src/flet_core/icon.py
packages/flet/lib/src/controls/icon.dart
Refactored and improved various controls and utilities
  • Updated PopupMenuButton with new properties and methods
  • Refactored GestureDetector to support more customization options
  • Improved Dropdown control with additional properties
  • Enhanced NavigationBar and NavigationDrawer controls
  • Updated utility functions for parsing and handling various properties
sdk/python/packages/flet-core/src/flet_core/popup_menu_button.py
packages/flet/lib/src/controls/popup_menu_button.dart
sdk/python/packages/flet-core/src/flet_core/gesture_detector.py
packages/flet/lib/src/controls/gesture_detector.dart
sdk/python/packages/flet-core/src/flet_core/dropdown.py
packages/flet/lib/src/controls/dropdown.dart
sdk/python/packages/flet-core/src/flet_core/navigation_bar.py
packages/flet/lib/src/controls/navigation_bar.dart
sdk/python/packages/flet-core/src/flet_core/navigation_drawer.py
packages/flet/lib/src/controls/navigation_drawer.dart
packages/flet/lib/src/utils/transforms.dart
packages/flet/lib/src/utils/box.dart
packages/flet/lib/src/utils/others.dart

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a 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 - here's some feedback:

Overall Comments:

  • This is a substantial update that greatly expands the capabilities of many controls. While this flexibility is welcome, we should be cautious about the increased API surface area and ensure that documentation is updated to reflect all these new options.
  • The deprecation of MapPointerDeviceType in favor of PointerDeviceType is a good move for consistency. Consider adding migration guides or warnings to help users transition to the new enum.
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@ndonkoHenri ndonkoHenri linked an issue Oct 6, 2024 that may be closed by this pull request
1 task
@ndonkoHenri ndonkoHenri linked an issue Oct 11, 2024 that may be closed by this pull request
1 task
@FeodorFitsner
Copy link
Contributor

Please resolve conflicts.

# Conflicts:
#	packages/flet/lib/src/controls/cupertino_textfield.dart
#	packages/flet/lib/src/controls/navigation_bar.dart
#	sdk/python/packages/flet-core/src/flet_core/buttons.py
#	sdk/python/packages/flet-core/src/flet_core/elevated_button.py
@FeodorFitsner
Copy link
Contributor

Could you look at the conflict please?

@@ -205,7 +205,7 @@ def before_update(self):
self._set_attr_json("labelStyle", self.__label_style)
self._set_attr_json("padding", self.__padding)
self._set_attr_json("shape", self.__shape)
self._set_attr_json("color", self.__color)
self._set_attr_json("color", self.__color, wrap_attr_dict=True)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see it's been changed in multiple controls. Do you have any examples/tests to see if anything is broken by that?

@FeodorFitsner FeodorFitsner merged commit 7810f71 into main Oct 29, 2024
2 checks passed
@FeodorFitsner FeodorFitsner deleted the new-props branch October 29, 2024 19:49
pengwon added a commit to pengwon/flet that referenced this pull request Oct 30, 2024
* main: (31 commits)
  Migrate `colors` and `icons` variables to Enums (flet-dev#4180)
  feat: expose more properties in Controls (flet-dev#4105)
  feat!: Refactor `Badge` Control to a Dataclass; create new `Control.badge` property (flet-dev#4077)
  fix: clicking on `CupertinoContextMenuAction` doesn't close context menu (flet-dev#3948)
  fix dropdown `max_menu_height` (flet-dev#3974)
  Fix undefined name "Future" --> asyncio.Future (flet-dev#4230)
  wrap ListTile in material widget (flet-dev#4206)
  Update CONTRIBUTING.md (flet-dev#4208)
  TextField: suffix_icon, prefix_icon and icon can be Control or str (flet-dev#4173)
  feat!: enhance `Map` control (flet-dev#3994)
  skip running flutter doctor on windows if no_rich_output is True (flet-dev#4108)
  add --pyinstaller-build-args to pack cli command (flet-dev#4187)
  fix/feat: make `SearchBar`'s view height adjustable; add new properties (flet-dev#4039)
  fix: prevent button `style` from being modified in `before_update()` (flet-dev#4181)
  fix: disabling filled buttons is not visually respected (flet-dev#4090)
  when `label` is set, use `MainAxisSize.min` for the `Row` (flet-dev#3998)
  fix: `NavigationBarDestination.disabled` has no visual effect (flet-dev#4073)
  fix autofill in CupertinoTextField (flet-dev#4103)
  Linechart: jsonDecode tooltip before displaying (flet-dev#4069)
  fixed bgcolor, color and elevation (flet-dev#4126)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Setting ButtonStyle.text_style displays grey screen TextField. Property height doesn't work properly
2 participants