Move dashboard visibility settings to own screen

This seems cleaner and can be opened from other places
This commit is contained in:
Roland Geider
2026-01-17 12:50:07 +01:00
parent 3664da4f78
commit 5574f74a2f
14 changed files with 375 additions and 153 deletions

View File

@@ -1,13 +1,13 @@
/*
* This file is part of wger Workout Manager <https://github.com/wger-project>.
* Copyright (C) 2020, 2021 wger Team
* Copyright (c) 2026 wger Team
*
* wger Workout Manager is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* wger Workout Manager is distributed in the hope that it will be useful,
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
@@ -49,13 +49,9 @@ void main() {
setUp(() {
when(mockUserProvider.themeMode).thenReturn(ThemeMode.system);
when(mockUserProvider.isDashboardWidgetVisible(any)).thenReturn(true);
when(mockExerciseProvider.exercises).thenReturn(getTestExercises());
when(mockNutritionProvider.ingredients).thenReturn([ingredient1, ingredient2]);
when(mockUserProvider.isDashboardWidgetVisible('routines')).thenReturn(true);
when(mockUserProvider.isDashboardWidgetVisible('weight')).thenReturn(true);
when(mockUserProvider.isDashboardWidgetVisible('measurements')).thenReturn(true);
when(mockUserProvider.isDashboardWidgetVisible('calendar')).thenReturn(true);
when(mockUserProvider.isDashboardWidgetVisible('nutrition')).thenReturn(true);
});
Widget createSettingsScreen({locale = 'en'}) {
@@ -105,24 +101,27 @@ void main() {
group('Theme settings', () {
test('Default theme is system', () async {
when(mockSharedPreferences.getBool(PREFS_USER_DARK_THEME)).thenAnswer((_) async => null);
when(mockSharedPreferences.getString('dashboardWidgetVisibility'))
.thenAnswer((_) async => null);
when(
mockSharedPreferences.getString('dashboardWidgetVisibility'),
).thenAnswer((_) async => null);
final userProvider = await UserProvider(MockWgerBaseProvider(), prefs: mockSharedPreferences);
expect(userProvider.themeMode, ThemeMode.system);
});
test('Loads light theme', () async {
when(mockSharedPreferences.getBool(PREFS_USER_DARK_THEME)).thenAnswer((_) async => false);
when(mockSharedPreferences.getString('dashboardWidgetVisibility'))
.thenAnswer((_) async => null);
when(
mockSharedPreferences.getString('dashboardWidgetVisibility'),
).thenAnswer((_) async => null);
final userProvider = await UserProvider(MockWgerBaseProvider(), prefs: mockSharedPreferences);
expect(userProvider.themeMode, ThemeMode.light);
});
test('Saves theme to prefs', () {
when(mockSharedPreferences.getBool(any)).thenAnswer((_) async => null);
when(mockSharedPreferences.getString('dashboardWidgetVisibility'))
.thenAnswer((_) async => null);
when(
mockSharedPreferences.getString('dashboardWidgetVisibility'),
).thenAnswer((_) async => null);
final userProvider = UserProvider(MockWgerBaseProvider(), prefs: mockSharedPreferences);
userProvider.setThemeMode(ThemeMode.dark);
verify(mockSharedPreferences.setBool(PREFS_USER_DARK_THEME, true)).called(1);

View File

@@ -943,6 +943,14 @@ class MockUserProvider extends _i1.Mock implements _i21.UserProvider {
)
as _i14.SharedPreferencesAsync);
@override
Map<_i21.DashboardWidget, bool> get dashboardWidgetVisibility =>
(super.noSuchMethod(
Invocation.getter(#dashboardWidgetVisibility),
returnValue: <_i21.DashboardWidget, bool>{},
)
as Map<_i21.DashboardWidget, bool>);
@override
set themeMode(_i22.ThemeMode? value) => super.noSuchMethod(
Invocation.setter(#themeMode, value),
@@ -955,6 +963,12 @@ class MockUserProvider extends _i1.Mock implements _i21.UserProvider {
returnValueForMissingStub: null,
);
@override
set dashboardWidgetVisibility(Map<_i21.DashboardWidget, bool>? value) => super.noSuchMethod(
Invocation.setter(#dashboardWidgetVisibility, value),
returnValueForMissingStub: null,
);
@override
set profile(_i23.Profile? value) => super.noSuchMethod(
Invocation.setter(#profile, value),
@@ -971,6 +985,26 @@ class MockUserProvider extends _i1.Mock implements _i21.UserProvider {
returnValueForMissingStub: null,
);
@override
bool isDashboardWidgetVisible(_i21.DashboardWidget? key) =>
(super.noSuchMethod(
Invocation.method(#isDashboardWidgetVisible, [key]),
returnValue: false,
)
as bool);
@override
_i18.Future<void> setDashboardWidgetVisible(
_i21.DashboardWidget? key,
bool? visible,
) =>
(super.noSuchMethod(
Invocation.method(#setDashboardWidgetVisible, [key, visible]),
returnValue: _i18.Future<void>.value(),
returnValueForMissingStub: _i18.Future<void>.value(),
)
as _i18.Future<void>);
@override
void setThemeMode(_i22.ThemeMode? mode) => super.noSuchMethod(
Invocation.method(#setThemeMode, [mode]),

View File

@@ -389,6 +389,14 @@ class MockUserProvider extends _i1.Mock implements _i17.UserProvider {
)
as _i4.SharedPreferencesAsync);
@override
Map<_i17.DashboardWidget, bool> get dashboardWidgetVisibility =>
(super.noSuchMethod(
Invocation.getter(#dashboardWidgetVisibility),
returnValue: <_i17.DashboardWidget, bool>{},
)
as Map<_i17.DashboardWidget, bool>);
@override
set themeMode(_i18.ThemeMode? value) => super.noSuchMethod(
Invocation.setter(#themeMode, value),
@@ -401,6 +409,12 @@ class MockUserProvider extends _i1.Mock implements _i17.UserProvider {
returnValueForMissingStub: null,
);
@override
set dashboardWidgetVisibility(Map<_i17.DashboardWidget, bool>? value) => super.noSuchMethod(
Invocation.setter(#dashboardWidgetVisibility, value),
returnValueForMissingStub: null,
);
@override
set profile(_i19.Profile? value) => super.noSuchMethod(
Invocation.setter(#profile, value),
@@ -417,6 +431,26 @@ class MockUserProvider extends _i1.Mock implements _i17.UserProvider {
returnValueForMissingStub: null,
);
@override
bool isDashboardWidgetVisible(_i17.DashboardWidget? key) =>
(super.noSuchMethod(
Invocation.method(#isDashboardWidgetVisible, [key]),
returnValue: false,
)
as bool);
@override
_i15.Future<void> setDashboardWidgetVisible(
_i17.DashboardWidget? key,
bool? visible,
) =>
(super.noSuchMethod(
Invocation.method(#setDashboardWidgetVisible, [key, visible]),
returnValue: _i15.Future<void>.value(),
returnValueForMissingStub: _i15.Future<void>.value(),
)
as _i15.Future<void>);
@override
void setThemeMode(_i18.ThemeMode? mode) => super.noSuchMethod(
Invocation.method(#setThemeMode, [mode]),

View File

@@ -231,6 +231,14 @@ class MockUserProvider extends _i1.Mock implements _i13.UserProvider {
)
as _i4.SharedPreferencesAsync);
@override
Map<_i13.DashboardWidget, bool> get dashboardWidgetVisibility =>
(super.noSuchMethod(
Invocation.getter(#dashboardWidgetVisibility),
returnValue: <_i13.DashboardWidget, bool>{},
)
as Map<_i13.DashboardWidget, bool>);
@override
set themeMode(_i14.ThemeMode? value) => super.noSuchMethod(
Invocation.setter(#themeMode, value),
@@ -243,6 +251,12 @@ class MockUserProvider extends _i1.Mock implements _i13.UserProvider {
returnValueForMissingStub: null,
);
@override
set dashboardWidgetVisibility(Map<_i13.DashboardWidget, bool>? value) => super.noSuchMethod(
Invocation.setter(#dashboardWidgetVisibility, value),
returnValueForMissingStub: null,
);
@override
set profile(_i15.Profile? value) => super.noSuchMethod(
Invocation.setter(#profile, value),
@@ -259,6 +273,26 @@ class MockUserProvider extends _i1.Mock implements _i13.UserProvider {
returnValueForMissingStub: null,
);
@override
bool isDashboardWidgetVisible(_i13.DashboardWidget? key) =>
(super.noSuchMethod(
Invocation.method(#isDashboardWidgetVisible, [key]),
returnValue: false,
)
as bool);
@override
_i11.Future<void> setDashboardWidgetVisible(
_i13.DashboardWidget? key,
bool? visible,
) =>
(super.noSuchMethod(
Invocation.method(#setDashboardWidgetVisible, [key, visible]),
returnValue: _i11.Future<void>.value(),
returnValueForMissingStub: _i11.Future<void>.value(),
)
as _i11.Future<void>);
@override
void setThemeMode(_i14.ThemeMode? mode) => super.noSuchMethod(
Invocation.method(#setThemeMode, [mode]),