Skip to content

feat: added Settings screen #2696

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 3 commits into from
May 19, 2025
Merged

Conversation

Vidhijain20
Copy link

@Vidhijain20 Vidhijain20 commented May 19, 2025

Adds the Settings screen.

Screenshots / Recordings

setting_screen1
settings_screen2

Checklist:

  • No hard coding: I have used resources from strings.xml, dimens.xml and colors.xml without hard coding any value.
  • No end of file edits: No modifications done at end of resource files strings.xml, dimens.xml or colors.xml.
  • Code reformatting: I have reformatted code and fixed indentation in every file included in this pull request.
  • No extra space: My code does not contain any extra lines or extra spaces than the ones that are necessary.

Summary by Sourcery

Add a new Settings screen to allow users to toggle auto-start behavior and choose export data format, integrate it into the app’s navigation and provider logic.

New Features:

  • Introduce SettingsScreen UI with a checkbox for auto-start and a list tile that opens a dialog to select TXT or CSV export format
  • Register '/settings' route in main.dart and add a Settings entry in the navigation drawer

Enhancements:

  • Extend BoardStateProvider with exportFormat and autoStart properties and conditionally subscribe to USB events based on autoStart
  • Define new constants for settings labels and export formats in constants.dart
  • Improve navigation drawer logic to correctly navigate to or reuse the Settings screen

Copy link

sourcery-ai bot commented May 19, 2025

Reviewer's Guide

This PR introduces a new Settings screen for configuring auto-start and export format options, integrates it into the app navigation, and extends the BoardStateProvider to persist these settings and conditionally manage USB auto-connect behavior.

Sequence Diagram for Conditional USB Auto-Connection

sequenceDiagram
    participant BSP as BoardStateProvider
    participant US as UsbSerial
    participant SCL as ScienceLabCommon

    BSP->>BSP: initialize()
    alt autoStart is true
        BSP->>US: usbEventStream.listen(...)
        US-->>BSP: UsbEvent.ACTION_USB_ATTACHED
        BSP->>BSP: attemptToConnectPSLab()
        BSP->>SCL: openDevice()
        SCL-->>BSP: pslabIsConnected = true
        BSP->>BSP: setPSLabVersionIDs()
    else autoStart is false
        BSP->>BSP: Skip UsbSerial event listening
    end
Loading

Sequence Diagram for Updating Settings

sequenceDiagram
    actor User
    participant SS as SettingsScreen
    participant BSP as BoardStateProvider

    User->>SS: Toggles "Auto Start" checkbox
    SS->>BSP: autoStart = (new value)
    BSP-->>SS: Notifies listeners (UI updates)

    User->>SS: Taps "Export Data Format" list tile
    SS->>SS: _showExportFormatDialog()
    Note right of SS: Dialog with TXT/CSV options appears
    User->>SS: Selects export format (e.g., CSV) in Dialog
    SS->>BSP: exportFormat = (selected format)
    BSP-->>SS: Notifies listeners (UI updates)
    SS->>User: Dialog closes, selection applied
Loading

File-Level Changes

Change Details Files
Implemented Settings screen UI and interaction logic
  • Created SettingsScreen StatefulWidget with main scaffold
  • Added CheckboxListTile for auto-start toggle
  • Added ListTile to display and change export format via SimpleDialog
  • Managed radio selections and updated provider values via GetIt
lib/view/settings_screen.dart
Extended BoardStateProvider to store settings and gate USB listener
  • Imported constants and added exportFormat and autoStart fields
  • Wrapped USB event stream subscription in autoStart check
  • Retained existing detach logic and notifyListeners on disconnect
lib/providers/board_state_provider.dart
Added new string constants for Settings screen
  • Defined labels for Settings, Auto Start, export options, and cancel button
lib/constants.dart
Integrated Settings route into main navigation
  • Imported SettingsScreen in main.dart
  • Registered '/settings' in the routes map
lib/main.dart
Updated navigation drawer to handle Settings navigation
  • Added logic to push or pop until '/settings' on drawer tap
lib/view/widgets/navigation_drawer.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. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the 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 exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

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

@Vidhijain20
Copy link
Author

@CloudyPadmal @AsCress Could you please review this as well ?

Copy link

github-actions bot commented May 19, 2025

ListTile(
title: Text(export),
subtitle: Text(
'Current format is ${GetIt.instance.get<BoardStateProvider>().exportFormat}'),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Fetch the text from the constant file

Copy link
Author

Choose a reason for hiding this comment

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

title: Text(txtFormat),
value: true,
groupValue: isTxtFormatSelected,
activeColor: const Color(0xFFD32F2F),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Create a colors.dart file in the same directory as the constants.dart and move all the hard-coded colors to colors.dart.

Then use those here and rest of this file.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for your suggestions ! I've implemented this.

@Vidhijain20 Vidhijain20 requested a review from CloudyPadmal May 19, 2025 14:22
Copy link
Collaborator

@AsCress AsCress left a comment

Choose a reason for hiding this comment

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

LGTM @Vidhijain20 !

@AsCress AsCress enabled auto-merge (squash) May 19, 2025 15:33
@AsCress AsCress merged commit de3c52b into fossasia:flutter May 19, 2025
4 of 5 checks passed
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.

3 participants