flet-dev / flet

Flet enables developers to easily build realtime web, mobile and desktop apps in Python. No frontend experience required.
https://flet.dev
Apache License 2.0
11.59k stars 454 forks source link

fix: `NavigationBarDestination.disabled` has no visual effect #4073

Closed ndonkoHenri closed 1 month ago

ndonkoHenri commented 2 months ago

Description

Fixes #4029

Test Code

import flet as ft

def main(page: ft.Page):

    page.title = "NavigationBar Example"

    def handle_disable_change(e):
        page.navigation_bar.disabled = e.control.value
        page.update()

    def handle_adaptive_change(e):
        page.navigation_bar.adaptive = e.control.value
        page.update()

    page.navigation_bar = ft.NavigationBar(
        destinations=[
            ft.NavigationBarDestination(icon=ft.icons.EXPLORE, label="Explore"),
            ft.NavigationBarDestination(icon=ft.icons.COMMUTE, label="Commute"),
            ft.NavigationBarDestination(
                icon=ft.icons.BOOKMARK_BORDER,
                selected_icon=ft.icons.BOOKMARK,
                label="Explore",
            ),
        ],
    )
    page.add(
        ft.Switch("Disable", value=False, on_change=handle_disable_change),
        ft.Switch("Adaptive", value=False, on_change=handle_adaptive_change),
    )

ft.app(main)

Summary by Sourcery

Fix the visual effect of the disabled state in NavigationBarDestination and refactor the handling of adaptive and disabled states in navigation bar controls.

Bug Fixes:

Enhancements:

sourcery-ai[bot] commented 2 months ago

Reviewer's Guide by Sourcery

This pull request addresses an issue where the NavigationBarDestination.disabled property had no visual effect. The changes implement proper handling of disabled states for both NavigationBar and CupertinoNavigationBar, improve code organization, and enhance the overall functionality of navigation components.

Sequence Diagram

sequenceDiagram
    participant User
    participant NavigationBar
    participant Destination
    User->>NavigationBar: Tap destination
    NavigationBar->>NavigationBar: Check disabled state
    alt NavigationBar is not disabled
        NavigationBar->>Destination: Check destination disabled state
        alt Destination is not disabled
            Destination->>NavigationBar: Allow selection
            NavigationBar->>User: Update selected index
        else Destination is disabled
            Destination->>NavigationBar: Prevent selection
        end
    else NavigationBar is disabled
        NavigationBar->>User: No action
    end

File-Level Changes

Change Details Files
Implement proper handling of disabled state for NavigationBar and CupertinoNavigationBar
  • Add disabled check to onDestinationSelected callback
  • Implement destinationDisabled flag for individual destinations
  • Update enabled property of NavigationDestination based on destinationDisabled
  • Modify onTap callback for CupertinoTabBar to respect disabled state
packages/flet/lib/src/controls/navigation_bar.dart
packages/flet/lib/src/controls/cupertino_navigation_bar.dart
Refactor and improve code organization
  • Add isAdaptive getter to Control class
  • Use parseDuration function for animationDuration
  • Simplify labelBehavior assignment
  • Remove redundant variable declarations
packages/flet/lib/src/controls/navigation_bar.dart
packages/flet/lib/src/models/control.dart
Enhance flexibility and consistency of navigation components
  • Add support for indicatorColor as a fallback for activeColor in CupertinoTabBar
  • Improve handling of adaptive property for individual destinations
  • Update tooltip handling to allow null values
packages/flet/lib/src/controls/navigation_bar.dart
packages/flet/lib/src/controls/cupertino_navigation_bar.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. #### Customizing Your Experience Access your [dashboard](https://app.sourcery.ai) 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 - [Contact our support team](mailto:support@sourcery.ai) for questions or feedback. - Visit our [documentation](https://docs.sourcery.ai) for detailed guides and information. - Keep in touch with the Sourcery team by following us on [X/Twitter](https://x.com/SourceryAI), [LinkedIn](https://www.linkedin.com/company/sourcery-ai/) or [GitHub](https://github.com/sourcery-ai).