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

fix/feat: make SearchBar's view height adjustable; add new properties #4039

Merged
merged 4 commits into from
Oct 18, 2024

Conversation

ndonkoHenri
Copy link
Contributor

@ndonkoHenri ndonkoHenri commented Sep 23, 2024

Description

Fixes #3985 #4081

Test Code

import flet as ft


def main(page: ft.Page):
    page.window.always_on_top = True
    page.theme_mode = ft.ThemeMode.LIGHT
    page.add(
        ft.SearchBar(
            controls=[ft.ListTile(title=ft.Text("Hello"))],
            view_header_height=30,
            on_tap=lambda e: e.control.open_view(),
            width=350,
            view_size_constraints=ft.BoxConstraints(max_height=170, max_width=350),
            bar_hint_text="Search",
            bar_hint_text_style={
                ft.ControlState.HOVERED: ft.TextStyle(color=ft.colors.YELLOW, size=20)
            },
            bar_padding=ft.padding.symmetric(10, 10),
            bar_text_style=ft.TextStyle(color=ft.colors.RED, size=20),
            bar_border_side=ft.BorderSide(color=ft.colors.BLUE, width=2),
            bar_shape=ft.RoundedRectangleBorder(radius=0),
            bar_elevation=00.0,
            view_elevation=5.0,
            bar_shadow_color=ft.colors.BLUE,
        )
    )


ft.app(target=main, view=ft.AppView.WEB_BROWSER)

Summary by Sourcery

Fix the SearchBar component to make its view height adjustable and enhance it by adding properties for view size constraints and header height, allowing for more flexible layout configurations.

Bug Fixes:

  • Fix the issue with the SearchBar component by making its view height adjustable.

Enhancements:

  • Add support for view_size_constraints and view_header_height properties in the SearchBar component to allow more flexible layout configurations.

Summary by Sourcery

Make the SearchBar component's view height adjustable and enhance its flexibility by adding new properties for layout and style customization. Introduce utility functions for parsing widget state properties to support dynamic configurations.

Bug Fixes:

  • Fix the issue with the SearchBar component by making its view height adjustable.

Enhancements:

  • Add support for view_size_constraints and view_header_height properties in the SearchBar component to allow more flexible layout configurations.
  • Introduce new properties for SearchBar such as bar_shadow_color, bar_surface_tint_color, bar_elevation, bar_border_side, bar_shape, bar_text_style, bar_hint_text_style, and bar_padding to enhance customization options.
  • Implement new utility functions for parsing widget state properties, including parseWidgetStateDouble, parseWidgetStateInt, parseWidgetStateBool, parseWidgetStateEdgeInsets, parseWidgetStateOutlinedBorder, and parseWidgetStateTextStyle to support dynamic property handling.

Copy link
Contributor

sourcery-ai bot commented Sep 23, 2024

Reviewer's Guide by Sourcery

This pull request enhances the SearchBar component in the Flet framework by making its view height adjustable and adding new properties for more flexible layout configurations. The changes primarily affect the SearchBar class in Python and its corresponding implementation in Dart.

Updated class diagram for the SearchBar component

classDiagram
    class SearchBar {
        +OptionalNumber view_header_height
        +Optional[BoxConstraints] view_size_constraints
        +Union[None, str, Dict[ControlState, str]] bar_shadow_color
        +Union[None, str, Dict[ControlState, str]] bar_surface_tint_color
        +Union[OptionalNumber, Dict[ControlState, Number]] bar_elevation
        +Union[None, BorderSide, Dict[ControlState, BorderSide]] bar_border_side
        +Union[None, OutlinedBorder, Dict[ControlState, OutlinedBorder]] bar_shape
        +Union[None, TextStyle, Dict[ControlState, TextStyle]] bar_text_style
        +Union[None, TextStyle, Dict[ControlState, TextStyle]] bar_hint_text_style
        +Union[PaddingValue, Dict[ControlState, PaddingValue]] bar_padding
        +OptionalControlEventCallable on_tap_outside_bar
    }
    class BoxConstraints {
        +OptionalNumber min_width
        +OptionalNumber min_height
        +OptionalNumber max_width
        +OptionalNumber max_height
    }
Loading

File-Level Changes

Change Details Files
Added new properties to the SearchBar class for more customization options
  • Added view_size_constraints property to control the size of the search view
  • Added view_header_height property to adjust the height of the view header
  • Introduced new bar-related properties like bar_shadow_color, bar_surface_tint_color, bar_elevation, bar_border_side, bar_shape, bar_text_style, bar_hint_text_style, and bar_padding
  • Added on_tap_outside_bar event handler
sdk/python/packages/flet-core/src/flet_core/search_bar.py
Updated the Dart implementation of SearchBar to support new properties
  • Added support for parsing and applying new properties in the SearchBar widget
  • Implemented headerHeight and viewConstraints in the SearchBar constructor
  • Added support for new bar-related properties in the SearchBar's builder method
packages/flet/lib/src/controls/search_anchor.dart
Added utility functions for parsing new property types
  • Created parseBoxConstraints function to parse BoxConstraints from JSON
  • Added parseWidgetStateEdgeInsets, parseWidgetStateOutlinedBorder, and parseWidgetStateTextStyle functions
  • Implemented parseWidgetStateDouble, parseWidgetStateInt, and parseWidgetStateBool functions
packages/flet/lib/src/utils/box.dart
packages/flet/lib/src/utils/edge_insets.dart
packages/flet/lib/src/utils/borders.dart
packages/flet/lib/src/utils/text.dart
packages/flet/lib/src/utils/numbers.dart
Added BoxConstraints class to the Python SDK
  • Created BoxConstraints dataclass with min_width, min_height, max_width, and max_height properties
sdk/python/packages/flet-core/src/flet_core/box.py
Updated Control class to support control state attributes
  • Added _set_control_state_attr_json method to handle control state attributes
sdk/python/packages/flet-core/src/flet_core/control.py

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.

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 and they look great!

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 to tell me if it was helpful.

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

@sourcery-ai review

@ndonkoHenri ndonkoHenri changed the title fix: make the SearchBar's view height adjustable fix/feat: make SearchBar's view height adjustable; add new properties Oct 4, 2024
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 and they look great!

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.

@FeodorFitsner FeodorFitsner merged commit 5e87936 into main Oct 18, 2024
2 checks passed
@FeodorFitsner FeodorFitsner deleted the fix-searchview-height branch October 18, 2024 17:06
@ClearSafety
Copy link

Hi,
Thank you for that.
I've just upgrade the Flet but even so the new properties aren't available. Will they be available in a new version realise?

@ndonkoHenri
Copy link
Contributor Author

They are available in the latest prerelease: pip install flet --pre -U

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)
  ...
@ClearSafety
Copy link

@ndonkoHenri
Hi,
I'm trying to set 'bar_border_side', but it has no effect in the SearchBar.
I tried your own example, but nor border is displayed

import flet as ft

def main(page: ft.Page):
page.window.always_on_top = True
page.theme_mode = ft.ThemeMode.LIGHT
page.add(
ft.SearchBar(
controls=[ft.ListTile(title=ft.Text("Hello"))],
view_header_height=30,
on_tap=lambda e: e.control.open_view(),
width=350,
view_size_constraints=ft.BoxConstraints(max_height=170, max_width=350),
bar_hint_text="Search",
bar_hint_text_style={
ft.ControlState.HOVERED: ft.TextStyle(color=ft.colors.YELLOW, size=20)
},
bar_padding=ft.padding.symmetric(10, 10),
bar_text_style=ft.TextStyle(color=ft.colors.RED, size=20),
bar_border_side=ft.BorderSide(color=ft.colors.BLUE, width=2),
bar_shape=ft.RoundedRectangleBorder(radius=0),
bar_elevation=00.0,
view_elevation=5.0,
bar_shadow_color=ft.colors.BLUE,
)
)

ft.app(target=main, view=ft.AppView.WEB_BROWSER)****

@ndonkoHenri
Copy link
Contributor Author

@ClearSafety i opened an issue: #4767

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.

Enhance SearchBar control Make it possible to change SearchBar's view height
3 participants