Skip to content

fix: added snackbar and small ui changes in lux meter. #2747

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

Open
wants to merge 4 commits into
base: flutter
Choose a base branch
from

Conversation

Yugesh-Kumar-S
Copy link
Collaborator

@Yugesh-Kumar-S Yugesh-Kumar-S commented Jun 18, 2025

Fixes #2746

Changes

  • Added a snackbar to notify light sensor errors like "not available" , "cannot access sensor".
  • Changed curved edges of chart
  • Added padding to the right side of chart.

Screenshots / Recordings

image

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 snackbar notifications for light sensor errors, refactor sensor initialization and disposal, and adjust the lux meter chart’s UI styling and layout.

New Features:

  • Display a floating SnackBar for light sensor errors such as unavailable sensor or access denial
  • Implement platform-specific error callbacks for unsupported platforms and sensor failures

Enhancements:

  • Refactor LuxMeterStateProvider lifecycle to initialize sensors in initState and dispose resources properly
  • Update chart styling: remove container border radius, add dynamic padding and right-side inset, and adjust axis reserved sizes

@Yugesh-Kumar-S Yugesh-Kumar-S added Status: Review Required Requested reviews from peers and maintainers Fix Solution to an existing issue in app flutter labels Jun 18, 2025
Copy link

sourcery-ai bot commented Jun 18, 2025

Reviewer's Guide

Introduces user feedback for light sensor errors via Snackbar, enhances sensor lifecycle and platform-specific error handling, and refines the lux meter chart’s UI styling and responsiveness.

Sequence diagram for light sensor error handling and Snackbar feedback

sequenceDiagram
    actor User
    participant LuxMeterScreen
    participant LuxMeterStateProvider
    participant Snackbar
    User->>LuxMeterScreen: Open screen
    LuxMeterScreen->>LuxMeterStateProvider: initializeSensors(onError)
    alt Platform not supported or sensor error
        LuxMeterStateProvider-->>LuxMeterScreen: onError callback with error message
        LuxMeterScreen->>Snackbar: Show error message
    else Sensor available
        LuxMeterStateProvider-->>LuxMeterScreen: Sensor data updates
        LuxMeterScreen->>User: Display chart
    end
Loading

File-Level Changes

Change Details Files
Add Snackbar-based user feedback and explicit sensor lifecycle management in LuxMeterScreen
  • Move sensor initialization to initState with onError callback
  • Implement dispose to cancel timers and subscriptions
  • Invoke ScaffoldMessenger to display error messages in _showSensorErrorSnackbar
  • Switch to ChangeNotifierProvider.value with the pre-initialized provider
lib/view/luxmeter_screen.dart
Enhance LuxMeterStateProvider with platform checks and detailed error handling
  • Introduce onSensorError callback and _sensorAvailable flag
  • Add _isPlatformSupported, _handleUnsupportedPlatform, and _handleSensorError flows
  • Separate error scenarios for iOS, desktop, web, and missing sensor
  • Log errors and prevent data updates when sensor is unavailable
  • Add new error message constants
lib/providers/luxmeter_state_provider.dart
lib/constants.dart
Refine chart UI styling and layout for responsiveness
  • Remove container corner radius and adjust padding based on screen width
  • Wrap LineChart in Padding for right-side spacing
  • Update reserved sizes for left, right, and bottom titles
  • Consolidate axis styling and font sizes for consistency
  • Add gridData and adjust chart bounds for dynamic scaling
lib/view/luxmeter_screen.dart

Assessment against linked issues

Issue Objective Addressed Explanation
#2746 Integrate snackbar notifications to inform users when the device lacks a light sensor or when the app lacks permission to access it.
#2746 Modify the UI to have straight edges on the chart.
#2746 Add padding to the right of the chart to center 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

@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 @Yugesh-Kumar-S - I've reviewed your changes - here's some feedback:

  • The direct import of dart:io in luxmeter_state_provider.dart will break web builds—use conditional imports or platform-agnostic abstractions to avoid build errors on non-native targets.
  • There’s a lot of duplicated logic across _handleUnsupportedPlatform, _handleSensorError, and _handleSensorNotAvailable—consider unifying these into a single streamlined error‐handling flow to reduce repetition.
  • The chart layout code repeats padding and reserved size calculations for different breakpoints—extract those values into helper constants or methods to improve readability and maintainability.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The direct import of `dart:io` in `luxmeter_state_provider.dart` will break web builds—use conditional imports or platform-agnostic abstractions to avoid build errors on non-native targets.
- There’s a lot of duplicated logic across `_handleUnsupportedPlatform`, `_handleSensorError`, and `_handleSensorNotAvailable`—consider unifying these into a single streamlined error‐handling flow to reduce repetition.
- The chart layout code repeats padding and reserved size calculations for different breakpoints—extract those values into helper constants or methods to improve readability and maintainability.

## Individual Comments

### Comment 1
<location> `lib/view/luxmeter_screen.dart:146` </location>
<code_context>
-                timeAxisLabel,
+    final reservedSizeLeft = screenWidth < 400 ? 27.0 : 30.0;
+    final reservedSizeRight = screenWidth < 400 ? 27.0 : 30.0;
+    return Padding(
+      padding: const EdgeInsets.only(right: 20.0),
+      child: LineChart(
+        LineChartData(
+          backgroundColor: Colors.black,
</code_context>

<issue_to_address>
Adding right padding to the chart may cause misalignment with other UI elements.

Consider using a responsive value or matching the card's padding to ensure consistent alignment across different screen sizes.

Suggested implementation:

```
    // Define a responsive horizontal padding, or use the card's padding value if available
    final horizontalPadding = screenWidth < 400 ? 12.0 : 20.0;

    return Padding(
      padding: EdgeInsets.only(right: horizontalPadding),

```

If the card's padding is defined elsewhere (e.g., as a constant or theme value), you should reference that value instead of defining `horizontalPadding` here. Also, consider applying the same `horizontalPadding` to the left side if you want symmetrical padding for better alignment.
</issue_to_address>

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.

Comment on lines +146 to +148
return Padding(
padding: const EdgeInsets.only(right: 20.0),
child: LineChart(
Copy link

Choose a reason for hiding this comment

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

suggestion: Adding right padding to the chart may cause misalignment with other UI elements.

Consider using a responsive value or matching the card's padding to ensure consistent alignment across different screen sizes.

Suggested implementation:

    // Define a responsive horizontal padding, or use the card's padding value if available
    final horizontalPadding = screenWidth < 400 ? 12.0 : 20.0;

    return Padding(
      padding: EdgeInsets.only(right: horizontalPadding),

If the card's padding is defined elsewhere (e.g., as a constant or theme value), you should reference that value instead of defining horizontalPadding here. Also, consider applying the same horizontalPadding to the left side if you want symmetrical padding for better alignment.

Copy link

github-actions bot commented Jun 18, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fix Solution to an existing issue in app flutter Status: Review Required Requested reviews from peers and maintainers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Lux meter improvement
2 participants