fix: add snackbar for empty logged data#3162
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAdds an early-return guard in _deleteAllFiles to show a localized snackbar when there are no logged files instead of opening the delete confirmation dialog. Sequence diagram for _deleteAllFiles snackbar behaviorsequenceDiagram
actor User
participant LoggedDataScreenState
participant ScaffoldMessenger
participant Dialog
User->>LoggedDataScreenState: tapDeleteAllFiles()
LoggedDataScreenState->>LoggedDataScreenState: _deleteAllFiles()
alt files list is empty
LoggedDataScreenState->>ScaffoldMessenger: showSnackBar(noLoggedData)
ScaffoldMessenger-->>User: displaySnackbar(noLoggedData)
else files list is not empty
LoggedDataScreenState->>Dialog: showDialog(confirmDeleteAll)
Dialog-->>User: displayConfirmation()
User-->>Dialog: confirm()
Dialog-->>LoggedDataScreenState: confirmed true
LoggedDataScreenState->>LoggedDataScreenState: proceedWithDeletion()
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- Consider disabling or hiding the "Delete All Files" action when
_files.isEmptyinstead of showing a Snackbar, so users get immediate visual feedback that there is nothing to delete before tapping. - If this snackbar pattern (colors, style, localization) is or will be used elsewhere, consider extracting a small helper method or widget for showing app-standard snackbars to keep styling and behavior consistent.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider disabling or hiding the "Delete All Files" action when `_files.isEmpty` instead of showing a Snackbar, so users get immediate visual feedback that there is nothing to delete before tapping.
- If this snackbar pattern (colors, style, localization) is or will be used elsewhere, consider extracting a small helper method or widget for showing app-standard snackbars to keep styling and behavior consistent.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
rahul31124
left a comment
There was a problem hiding this comment.
Nice addition! This will improve the user experience
There was a problem hiding this comment.
Pull request overview
This PR improves the Logged Data UI flow by providing immediate user feedback when “Delete All Data” is invoked with an empty logged-data list, avoiding an unnecessary confirmation dialog.
Changes:
- Add an early return in
_deleteAllFiles()when_filesis empty. - Show a localized
SnackBar(“noLoggedData”) instead of opening the delete-all confirmation dialog in the empty state.
| if (_files.isEmpty) { | ||
| ScaffoldMessenger.of(context).showSnackBar( | ||
| SnackBar( | ||
| content: Text( | ||
| appLocalizations.noLoggedData, | ||
| style: TextStyle(color: snackBarContentColor), | ||
| ), | ||
| backgroundColor: snackBarBackgroundColor, | ||
| ), | ||
| ); | ||
| return; | ||
| } |
There was a problem hiding this comment.
The _files.isEmpty early-return can be triggered while _loadFiles() is still in progress because _loadFiles() clears _files and sets _isLoading = true. Since the options menu is still available during loading, tapping “Delete All Data” immediately after opening the screen will incorrectly show the “No logged data” snackbar even if files exist.
Consider also guarding on _isLoading (e.g., return early or disable the menu action while loading) so the snackbar only appears when the empty state is final, not transient during refresh/loading.
There was a problem hiding this comment.
@Diksha-MukherjeeAgarwal, could you please have a look at the Copilot comment and apply the changes if you think they make sense?
Build StatusBuild successful. APKs to test: https://github.com/fossasia/pslab-app/actions/runs/24309661880/artifacts/6393541941. Screenshots |
• To prevent showing snackbar if a user accidentally taps 'Delete all data' while loading.







-1_instruments_screen.png?raw=true)
-2_nav_drawer.png?raw=true)
-3_accelerometer.png?raw=true)
-4_power_source.png?raw=true)
-5_multimeter.png?raw=true)
-6_wave_generator.png?raw=true)
-7_oscilloscope.png?raw=true)
What does this PR do?
This PR updates the _deleteAllFiles() function in logged_data_screen.dart.
Why is this change needed?
Previously, if the user clicked "Delete All Files" when the list was empty, it would still show the delete confirmation dialog.
This update adds a check so that if _files.isEmpty is true, it shows a Snackbar.
Summary by Sourcery
Handle attempts to delete logged data when no files are present by providing user feedback instead of showing a confirmation dialog.
Bug Fixes:
Enhancements: