Skip to content

fix: ensure ElevatedButton Properties (bgcolor, color, elevation) are correctly updated #4126

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

Merged
merged 1 commit into from
Oct 17, 2024

Conversation

InesaFitsner
Copy link
Contributor

@InesaFitsner InesaFitsner commented Oct 9, 2024

Description

The issue was that bgcolor, color and elevation were were not updated (only updated for the first time).

Fixes #4119

Test Code

import flet as ft


def main(page: ft.Page):

    test_button = ft.ElevatedButton(
        "Click to change color",
        icon="park_rounded",
        icon_color="green400",
        color=ft.colors.WHITE,
        bgcolor=ft.colors.RED,
        style=ft.ButtonStyle(text_style=ft.TextStyle(italic=True)),
    )

    def on_click(e):
        if test_button.text == "red":
            test_button.text = "blue"
            test_button.bgcolor = ft.colors.BLUE_800
            test_button.color = ft.colors.BLACK
            test_button.elevation = 10
        else:
            test_button.text = "red"
            test_button.bgcolor = ft.colors.RED_800
            test_button.color = ft.colors.WHITE
            test_button.elevation = 20
        page.update()

    def change_color(e):
        e.control.style = ft.ButtonStyle(
            bgcolor=ft.colors.YELLOW, color=ft.colors.BLACK, elevation=20
        )
        page.update()

    test_button.on_click = on_click

    style_button = ft.ElevatedButton(
        "Click to change style",
        icon="park_rounded",
        icon_color="green400",
        # bgcolor=ft.colors.RED,
        style=ft.ButtonStyle(
            bgcolor=ft.colors.GREEN, color=ft.colors.RED, elevation=10
        ),
        on_click=change_color,
    )

    page.add(test_button, style_button)


ft.app(main)

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update. Need to add that bgcolor, color and elevation properties override bgcolor, color and elevation in button.style

Checklist:

  • I signed the CLA.
  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • New and existing tests pass locally with my changes
  • I have made corresponding changes to the documentation (if applicable)

Screenshots (if applicable):

Additional details

Summary by Sourcery

Fix the update mechanism for bgcolor, color, and elevation properties in the ElevatedButton component to ensure they are correctly applied after the initial setting. Update documentation to reflect the behavior of these properties.

Bug Fixes:

  • Fix the issue where bgcolor, color, and elevation properties were not updated after the initial setting in the ElevatedButton component.

Documentation:

  • Update documentation to clarify that bgcolor, color, and elevation properties override the corresponding properties in button.style.

@InesaFitsner InesaFitsner self-assigned this Oct 9, 2024
Copy link
Contributor

sourcery-ai bot commented Oct 9, 2024

Reviewer's Guide by Sourcery

This pull request fixes a bug in the ElevatedButton class where the bgcolor, color, and elevation properties were not being properly updated after the initial setting. The changes ensure that these properties override the corresponding values in the button's style when explicitly set.

Updated class diagram for ElevatedButton

classDiagram
    class ElevatedButton {
        - __color
        - __bgcolor
        - __elevation
        - __style
        + before_update()
    }
    class ButtonStyle {
        + color
        + bgcolor
        + elevation
        + side
        + shape
        + padding
    }
    ElevatedButton --> ButtonStyle
    ElevatedButton : +before_update()
Loading

File-Level Changes

Change Details Files
Refactored the before_update method in the ElevatedButton class to properly handle color, bgcolor, and elevation updates
  • Removed conditional assignments that were preventing updates to color, bgcolor, and elevation
  • Added explicit checks for non-None values of color, bgcolor, and elevation
  • Directly assigned the new values to the style properties when they are set
sdk/python/packages/flet-core/src/flet_core/elevated_button.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.
  • 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 @InesaFitsner - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Thank you for this fix. Please remember to update the documentation as mentioned in your checklist to reflect that bgcolor, color, and elevation properties override the corresponding properties in button.style.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 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.

if self.__style.elevation is not None
else self.elevation
)
if self.__color is not None:
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (code-quality): Extract code out into method (extract-method)

@ndonkoHenri

This comment was marked as resolved.

@ndonkoHenri ndonkoHenri changed the title fixed bgcolor, color and elevation fix: ensure ElevatedButton Properties (bgcolor, color, elevation) are correctly updated Oct 10, 2024
Copy link
Contributor

@ndonkoHenri ndonkoHenri left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@FeodorFitsner FeodorFitsner merged commit e175c7f into main Oct 17, 2024
3 checks passed
@FeodorFitsner FeodorFitsner deleted the elevated-button-bgcolor branch October 17, 2024 17:43
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.

ElevatedButton unable to update bgcolor property after upgrade to version >=0.24
3 participants