Skip to content

Conversation

@marcnause
Copy link
Contributor

@marcnause marcnause commented Dec 22, 2025

Fixes #3008

Changes

  • Add call to method which toggles state of the button
  • Rename

Screenshots / Recordings

Screen_recording_20251222_223954.mp4

Checklist:

  • No hard coding: I have used values from constants.dart or localization files instead of hard-coded values.
  • No end of file edits: No modifications done at end of resource files.
  • Code reformatting: I have formatted the code using dart format or the IDE formatter.
  • Code analysis: My code passes checks run in flutter analyze and tests run in flutter test.

Summary by Sourcery

Fix the multimeter screen switch so that toggling it updates the underlying state.

Bug Fixes:

  • Wire the multimeter screen switch to update the provider state when toggled.

Enhancements:

  • Rename the provider method for updating the switch state to a clearer, more descriptive name.

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Dec 22, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Connects the multimeter UI switch to its provider state and renames the provider method for clarity.

Sequence diagram for multimeter switch toggle flow

sequenceDiagram
    actor User
    participant MultimeterScreen
    participant SwitchWidget
    participant MultimeterStateProvider

    User->>SwitchWidget: tap
    SwitchWidget->>MultimeterScreen: onChanged(value)
    MultimeterScreen->>MultimeterStateProvider: setSwitch(value)
    MultimeterStateProvider->>MultimeterStateProvider: update isSwitchChecked
    MultimeterStateProvider-->>MultimeterScreen: notifyListeners()
    MultimeterScreen->>SwitchWidget: rebuild with provider.isSwitchChecked
Loading

Updated class diagram for multimeter state and screen

classDiagram
    class MultimeterStateProvider {
      bool isSwitchChecked
      void setSwitch(bool checked)
      void notifyListeners()
    }

    class MultimeterScreen {
      +build(BuildContext context)
    }

    class SwitchWidget {
      +bool value
      +Function onChanged
    }

    MultimeterScreen --> MultimeterStateProvider : uses
    MultimeterScreen o-- SwitchWidget : contains
    SwitchWidget --> MultimeterStateProvider : calls setSwitch
Loading

File-Level Changes

Change Details Files
Wire up the multimeter screen switch to update provider state.
  • Replace empty onChanged handler of the CupertinoSwitch with a call into the provider to update switch state
  • Pass the new switch value from the UI into the provider method
lib/view/multimeter_screen.dart
Rename and simplify the provider API for updating the switch flag.
  • Rename toggleSwitch(bool value) to setSwitch(bool checked) for clearer semantics
  • Preserve behavior of updating isSwitchChecked and notifying listeners
lib/providers/multimeter_state_provider.dart

Assessment against linked issues

Issue Objective Addressed Explanation
#3008 Ensure the Hz/Count Pulse switch on the multimeter screen correctly updates and persists its checked state when the user toggles it.

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. 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

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 - I've left some high level feedback:

  • You can simplify the onChanged callback by passing the method directly (e.g., onChanged: provider.setSwitch) instead of wrapping it in a one-line closure.
  • Consider renaming setSwitch to something more explicit like setSwitchChecked to better convey that it updates a boolean checked state rather than a generic switch object.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- You can simplify the `onChanged` callback by passing the method directly (e.g., `onChanged: provider.setSwitch`) instead of wrapping it in a one-line closure.
- Consider renaming `setSwitch` to something more explicit like `setSwitchChecked` to better convey that it updates a boolean checked state rather than a generic switch object.

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.

@github-actions
Copy link
Contributor

github-actions bot commented Dec 22, 2025

Build Status

Build successful. APKs to test: https://github.com/fossasia/pslab-app/actions/runs/20694791565/artifacts/5018015443.

Screenshots

Android Screenshots
iPhone Screenshots
iPad Screenshots

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.

Multimeter: switch always returns to unchecked state

1 participant