fossasia / badgemagic-android

Badge Magic with LEDs - Android App https://play.google.com/apps/testing/org.fossasia.badgemagic
Apache License 2.0
1.85k stars 206 forks source link

fix: Updated the Navigation drawer to have a single instance of each class #1083

Closed Jhalakupadhyay closed 3 weeks ago

Jhalakupadhyay commented 3 weeks ago

1082

Summary by Sourcery

Refactor the navigation drawer to maintain a single instance of each class, improving state management and reducing redundancy in navigation logic.

Bug Fixes:

Enhancements:

sourcery-ai[bot] commented 3 weeks ago

Reviewer's Guide by Sourcery

This PR refactors the navigation system by introducing a MainScreen widget that manages a single instance of each screen through an IndexedStack, replacing the previous navigation-based approach. The changes improve the app's architecture by centralizing navigation control and screen management.

Sequence diagram for navigation using MainScreen

sequenceDiagram
    actor User
    participant MainScreen
    participant CommonDrawer
    participant Navigator
    User ->> CommonDrawer: Tap on drawer item
    CommonDrawer ->> MainScreen: onTap(index)
    MainScreen ->> MainScreen: setState()
    MainScreen ->> MainScreen: updateOrientation()
    MainScreen ->> Navigator: pop()
    Navigator -->> User: Update UI based on currentIndex

Class diagram for MainScreen and CommonDrawer

classDiagram
    class MainScreen {
        +int currentIndex
        +List<String> appBarTitles
        +void initState()
        +void onDrawerItemTapped(int index)
        +void updateOrientation()
        +void dispose()
        +Widget build(BuildContext context)
    }
    class CommonDrawer {
        +Function(int) onTap
        +int selectedIndex
        +Widget build(BuildContext context)
    }
    MainScreen --> CommonDrawer : uses

File-Level Changes

Change Details Files
Introduced a new MainScreen widget to manage screen navigation and state
  • Created a StatefulWidget that maintains the current screen index
  • Implemented screen switching using IndexedStack instead of navigation
  • Added orientation management based on selected screen
  • Centralized app bar management with dynamic titles
lib/view/main_screen.dart
lib/main.dart
Refactored the navigation drawer implementation
  • Renamed BMDrawer to CommonDrawer
  • Simplified drawer item tap handling with a callback function
  • Added visual feedback for selected items with proper styling
  • Removed direct navigation calls in favor of index-based switching
lib/view/widgets/navigation_drawer.dart
Simplified CommonScaffold widget and screen implementations
  • Removed navigation drawer and app bar from CommonScaffold
  • Removed index parameter from all screen widgets
  • Updated screen widgets to use simplified CommonScaffold
lib/view/widgets/common_scaffold_widget.dart
lib/view/about_us_screen.dart
lib/view/draw_badge_screen.dart
lib/view/homescreen.dart
lib/view/save_badge_screen.dart
lib/view/saved_clipart.dart
lib/view/settings_screen.dart

Possibly linked issues


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](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).