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: disabling filled buttons is not visually respected #4090

Merged
merged 8 commits into from
Oct 17, 2024

Conversation

InesaFitsner
Copy link
Contributor

@InesaFitsner InesaFitsner commented Oct 3, 2024

Description

Background color and color for FilledTonalButton and FilledButton. Instead of hardcoding colors now different flutter buttons will be created.

Fixes #3941

Test Code

import flet as ft


def main(page: ft.Page):

    page.add(
        ft.FilledTonalButton(
            text="Disabled FilledTonalButton",
            on_click=lambda e: print("Disabled FilledTonalButton clicked!"),
            icon=ft.icons.SEARCH,
            disabled=True,
        ),
        ft.FilledTonalButton(
            text="FilledTonalButton",
            on_click=lambda e: print("FilledTonalButton clicked!"),
            icon=ft.icons.SEARCH,
            # disabled=True,
        ),
        ft.FilledTonalButton(
            text="Disabled FilledTonalButton no icon",
            on_click=lambda e: print("Disabled FilledTonalButton clicked!"),
            # icon=ft.icons.SEARCH,
            disabled=True,
        ),
        ft.FilledTonalButton(
            text="FilledTonalButton no icon",
            on_click=lambda e: print("FilledTonalButton clicked!"),
            # icon=ft.icons.SEARCH,
            # disabled=True,
        ),
        ft.FilledTonalButton(
            text="Disabled FilledTonalButton no icon + content",
            on_click=lambda e: print("Disabled FilledTonalButton clicked!"),
            content=ft.Checkbox(),
            # icon=ft.icons.SEARCH,
            disabled=True,
        ),
        ft.FilledTonalButton(
            text="FilledTonalButton no icon + content",
            on_click=lambda e: print("FilledTonalButton clicked!"),
            content=ft.Checkbox(),
            # icon=ft.icons.SEARCH,
            # disabled=True,
        ),
        ft.FilledButton(
            text="Disabled FilledButton",
            on_click=lambda e: print("Disabled ElevatedButton clicked!"),
            icon=ft.icons.SEARCH,
            disabled=True,
        ),
        ft.FilledButton(
            text="FilledButton",
            on_click=lambda e: print("FilledButton clicked!"),
            icon=ft.icons.SEARCH,
            # disabled=True,
        ),
        ft.FilledButton(
            text="Disabled FilledButton no icon",
            on_click=lambda e: print("Disabled ElevatedButton clicked!"),
            # icon=ft.icons.SEARCH,
            disabled=True,
        ),
        ft.FilledButton(
            text="FilledButton no icon",
            on_click=lambda e: print("FilledButton clicked!"),
            # icon=ft.icons.SEARCH,
            # disabled=True,
        ),
        ft.ElevatedButton(
            text="Disabled ElevatedButton",
            on_click=lambda e: print("Disabled ElevatedButton clicked!"),
            icon=ft.icons.SEARCH,
            disabled=True,
        ),
        ft.ElevatedButton(
            text="ElevatedButton",
            on_click=lambda e: print("ElevatedButton clicked!"),
            icon=ft.icons.SEARCH,
            # disabled=True,
        ),
        ft.ElevatedButton(
            text="Disabled RED ElevatedButton",
            on_click=lambda e: print("Disabled ElevatedButton clicked!"),
            bgcolor=ft.colors.RED,
            icon=ft.icons.SEARCH,
            disabled=True,
        ),
        ft.ElevatedButton(
            text="RED ElevatedButton",
            on_click=lambda e: print("ElevatedButton clicked!"),
            bgcolor=ft.colors.RED,
            icon=ft.icons.SEARCH,
            # disabled=True,
        ),
        ft.OutlinedButton(
            text="Disabled OutlinedButton",
            on_click=lambda e: print("Disabled OutlinedButton clicked!"),
            icon=ft.icons.SEARCH,
            disabled=True,
        ),
        ft.OutlinedButton(
            text="OutlinedButton",
            on_click=lambda e: print("OutlinedButton clicked!"),
            icon=ft.icons.SEARCH,
            # disabled=True,
        ),
    )


ft.app(target=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

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):

Screenshot 2024-10-03 at 10 37 59 AM

Additional details

Summary by Sourcery

Refactor button components to support dynamic color attributes, fixing hardcoded color issues and enhancing customization options for FilledTonalButton and FilledButton.

Bug Fixes:

  • Fix the issue with hardcoded colors in FilledTonalButton and FilledButton by allowing dynamic color attributes.

Enhancements:

  • Introduce attributes for color, background color, and elevation in FilledButton and FilledTonalButton to enhance customization.

Copy link
Contributor

sourcery-ai bot commented Oct 3, 2024

Reviewer's Guide by Sourcery

This pull request implements changes to the FilledTonalButton and FilledButton components in the Flet framework. It modifies the button creation logic to support different types of buttons (Elevated, Filled, and FilledTonal) based on new attributes. The changes also include updates to the Python SDK to reflect these new button types and their properties.

No diagrams generated as the changes look simple and do not need a visual representation.

File-Level Changes

Change Details Files
Refactored button creation logic in ElevatedButtonControl
  • Added new boolean attributes 'filled' and 'filledtonal' to determine button type
  • Created separate variables for ElevatedButton, FilledButton, and FilledTonalButton
  • Updated button creation logic to handle icon and non-icon versions of each button type
  • Modified the return statement to use the appropriate button type based on attributes
packages/flet/lib/src/controls/elevated_button.dart
Updated FilledButton class in Python SDK
  • Added new optional parameters for color, bgcolor, and elevation
  • Removed hardcoded values for color, bgcolor, and elevation
  • Added a new attribute 'filled' to distinguish FilledButton
sdk/python/packages/flet-core/src/flet_core/filled_button.py
Updated FilledTonalButton class in Python SDK
  • Added new optional parameters for color, bgcolor, and elevation
  • Removed hardcoded values for color, bgcolor, and elevation
  • Added a new attribute 'filledtonal' to distinguish FilledTonalButton
sdk/python/packages/flet-core/src/flet_core/filled_tonal_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.

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:

  • Consider refactoring the _ElevatedButtonControlState class to improve readability and maintainability. The class is becoming quite large and complex with the addition of new button types.
  • Explore using a design pattern (e.g., factory or strategy) for handling different button types. This could make it easier to add new button types in the future without modifying existing code.
  • While the manual testing is thorough, consider adding automated unit tests to ensure consistent verification of the new functionality.
Here's what I looked at during the review
  • 🟡 General issues: 2 issues 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 8, 2024 that may be closed by this pull request
@ndonkoHenri
Copy link
Contributor

Just from pushing a commit with the addition of _get_control_name in both filled buttons, for a better distinction.

@ndonkoHenri ndonkoHenri changed the title Disabled filledtonalbutton fix: disabling filled buttons is not visually respected Oct 8, 2024
@ndonkoHenri
Copy link
Contributor

@sourcery-ai review

Copy link
Contributor

sourcery-ai bot commented Oct 8, 2024

Hi @ndonkoHenri! 👋

Only authors and team members can run @sourcery-ai commands on public repos.

…simplify style initialization and assignment"

This reverts commit b9a7351.
@FeodorFitsner FeodorFitsner merged commit 9b55019 into main Oct 17, 2024
1 check passed
@FeodorFitsner FeodorFitsner deleted the disabled-filledtonalbutton branch October 17, 2024 18:25
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
3 participants