Add user preference in settings to hide diet plan if not used
Related Issue(s)
Fixes #865
Summary
This PR generalizes the original “hide Nutrition widget” request into a flexible system that allows users to toggle the visibility of any dashboard widget. Instead of a single boolean flag, the app now maintains a dashboardWidgetVisibility map that supports multiple configurable widgets.
Motivation
Issue #852 requested the ability to hide the Nutrition widget. During review, maintainers suggested making the feature more flexible so all dashboard widgets could be user-configurable. This PR implements that expanded functionality.
Changes
UserProvider
- Added dashboardWidgetVisibility map to store visibility states for all widgets.
- Persisted the map using SharedPreferencesAsync.
- Added helper methods: _loadDashboardWidgetVisibility(), isDashboardWidgetVisible(), setDashboardWidgetVisible()
Dashboard
- Updated DashboardScreen so routines, weight, measurements, calendar, and nutrition widgets render only if marked visible in the map.
Settings UI
- Added a new “Dashboard Widget Visibility” section in SettingsPage.
- Implemented SwitchListTile controls for each widget.
- UI updates immediately via Provider and persists across app restarts.
Testing
- Verified toggles correctly update visibility in real time.
- Restarted the app to confirm persistence.
- Confirmed behavior across multiple widgets.
- Tested on iOS simulator (iPhone 15).
- Added new test stubs to support the expanded visibility logic.
If applicable, please link to any related issues (Closes #123,
Closes wger-project/other-repo#123, See also #123, etc.)
Please check that the PR fulfills these requirements
- [ x] Tests for the changes have been added (for bug fixes / features)
- [ x] Set a 100 character limit in your editor/IDE to avoid white space diffs in the PR
(run
dart format .) - [x ] Updated/added relevant documentation (doc comments with
///). - [ x] Added relevant reviewers.
Hi and thanks for the PR!
I would say that we should be a bit more flexible and allow the users to hide / show other widgets in the home screen (they might want to hide the routines, but not the diet plan). We could save in the prefs a map with the visibility state of the different widgets?
@rolandgeider
Thanks for the suggestion! I refactored the implementation to store a dashboardWidgetVisibility map in UserProvider and added toggles in the Settings page for routines, weight, measurements, calendar, and nutrition. The dashboard now checks this map before rendering each widget, so users can individually hide or show the sections they care about.