Merge branch 'master' into feature/health-sync
# Conflicts: # lib/main.dart # macos/Flutter/GeneratedPluginRegistrant.swift # test/features/account/widgets/settings_test.dart
@@ -87,6 +87,11 @@ sealed class AppSettings with _$AppSettings {
|
||||
/// When true, an invalid TLS certificate is accepted from the self-hosted
|
||||
/// server the app is configured for. Never applies to the official servers.
|
||||
@Default(ALLOW_SELF_SIGNED_CERTS_DEFAULT) bool allowSelfSignedCerts,
|
||||
|
||||
/// When true, the app palette follows the platform dynamic colors
|
||||
/// (system wallpaper on Android 12+) instead of the fixed wger seeds.
|
||||
/// A no-op on platforms without dynamic color support.
|
||||
@Default(USE_DYNAMIC_COLOR_DEFAULT) bool useDynamicColor,
|
||||
}) = _AppSettings;
|
||||
}
|
||||
|
||||
@@ -107,12 +112,14 @@ class AppSettingsNotifier extends _$AppSettingsNotifier {
|
||||
final items = await _loadDashboardItems();
|
||||
final keepDataOnLogout = await _loadKeepDataOnLogout();
|
||||
final allowSelfSignedCerts = await _loadAllowSelfSignedCerts();
|
||||
final useDynamicColor = await _loadUseDynamicColor();
|
||||
return AppSettings(
|
||||
themeMode: themeMode,
|
||||
userLocale: userLocale,
|
||||
dashboardItems: items,
|
||||
keepDataOnLogout: keepDataOnLogout,
|
||||
allowSelfSignedCerts: allowSelfSignedCerts,
|
||||
useDynamicColor: useDynamicColor,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -218,6 +225,19 @@ class AppSettingsNotifier extends _$AppSettingsNotifier {
|
||||
await _prefs.setBool(PREFS_ALLOW_SELF_SIGNED_CERTS, value);
|
||||
}
|
||||
|
||||
//
|
||||
// Use dynamic color
|
||||
//
|
||||
|
||||
Future<bool> _loadUseDynamicColor() async =>
|
||||
(await _prefs.getBool(PREFS_USE_DYNAMIC_COLOR)) ?? USE_DYNAMIC_COLOR_DEFAULT;
|
||||
|
||||
Future<void> setUseDynamicColor(bool value) async {
|
||||
final current = state.asData?.value ?? const AppSettings();
|
||||
state = AsyncData(current.copyWith(useDynamicColor: value));
|
||||
await _prefs.setBool(PREFS_USE_DYNAMIC_COLOR, value);
|
||||
}
|
||||
|
||||
//
|
||||
// Dashboard config
|
||||
//
|
||||
|
||||
@@ -19,7 +19,10 @@ mixin _$AppSettings {
|
||||
/// of wiping it, so the same user signing back in resumes incrementally.
|
||||
bool get keepDataOnLogout;/// When true, an invalid TLS certificate is accepted from the self-hosted
|
||||
/// server the app is configured for. Never applies to the official servers.
|
||||
bool get allowSelfSignedCerts;
|
||||
bool get allowSelfSignedCerts;/// When true, the app palette follows the platform dynamic colors
|
||||
/// (system wallpaper on Android 12+) instead of the fixed wger seeds.
|
||||
/// A no-op on platforms without dynamic color support.
|
||||
bool get useDynamicColor;
|
||||
/// Create a copy of AppSettings
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@@ -30,16 +33,16 @@ $AppSettingsCopyWith<AppSettings> get copyWith => _$AppSettingsCopyWithImpl<AppS
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is AppSettings&&(identical(other.themeMode, themeMode) || other.themeMode == themeMode)&&const DeepCollectionEquality().equals(other.dashboardItems, dashboardItems)&&(identical(other.userLocale, userLocale) || other.userLocale == userLocale)&&(identical(other.keepDataOnLogout, keepDataOnLogout) || other.keepDataOnLogout == keepDataOnLogout)&&(identical(other.allowSelfSignedCerts, allowSelfSignedCerts) || other.allowSelfSignedCerts == allowSelfSignedCerts));
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is AppSettings&&(identical(other.themeMode, themeMode) || other.themeMode == themeMode)&&const DeepCollectionEquality().equals(other.dashboardItems, dashboardItems)&&(identical(other.userLocale, userLocale) || other.userLocale == userLocale)&&(identical(other.keepDataOnLogout, keepDataOnLogout) || other.keepDataOnLogout == keepDataOnLogout)&&(identical(other.allowSelfSignedCerts, allowSelfSignedCerts) || other.allowSelfSignedCerts == allowSelfSignedCerts)&&(identical(other.useDynamicColor, useDynamicColor) || other.useDynamicColor == useDynamicColor));
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(runtimeType,themeMode,const DeepCollectionEquality().hash(dashboardItems),userLocale,keepDataOnLogout,allowSelfSignedCerts);
|
||||
int get hashCode => Object.hash(runtimeType,themeMode,const DeepCollectionEquality().hash(dashboardItems),userLocale,keepDataOnLogout,allowSelfSignedCerts,useDynamicColor);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'AppSettings(themeMode: $themeMode, dashboardItems: $dashboardItems, userLocale: $userLocale, keepDataOnLogout: $keepDataOnLogout, allowSelfSignedCerts: $allowSelfSignedCerts)';
|
||||
return 'AppSettings(themeMode: $themeMode, dashboardItems: $dashboardItems, userLocale: $userLocale, keepDataOnLogout: $keepDataOnLogout, allowSelfSignedCerts: $allowSelfSignedCerts, useDynamicColor: $useDynamicColor)';
|
||||
}
|
||||
|
||||
|
||||
@@ -50,7 +53,7 @@ abstract mixin class $AppSettingsCopyWith<$Res> {
|
||||
factory $AppSettingsCopyWith(AppSettings value, $Res Function(AppSettings) _then) = _$AppSettingsCopyWithImpl;
|
||||
@useResult
|
||||
$Res call({
|
||||
ThemeMode themeMode, List<DashboardItem> dashboardItems, Locale? userLocale, bool keepDataOnLogout, bool allowSelfSignedCerts
|
||||
ThemeMode themeMode, List<DashboardItem> dashboardItems, Locale? userLocale, bool keepDataOnLogout, bool allowSelfSignedCerts, bool useDynamicColor
|
||||
});
|
||||
|
||||
|
||||
@@ -67,13 +70,14 @@ class _$AppSettingsCopyWithImpl<$Res>
|
||||
|
||||
/// Create a copy of AppSettings
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline') @override $Res call({Object? themeMode = null,Object? dashboardItems = null,Object? userLocale = freezed,Object? keepDataOnLogout = null,Object? allowSelfSignedCerts = null,}) {
|
||||
@pragma('vm:prefer-inline') @override $Res call({Object? themeMode = null,Object? dashboardItems = null,Object? userLocale = freezed,Object? keepDataOnLogout = null,Object? allowSelfSignedCerts = null,Object? useDynamicColor = null,}) {
|
||||
return _then(_self.copyWith(
|
||||
themeMode: null == themeMode ? _self.themeMode : themeMode // ignore: cast_nullable_to_non_nullable
|
||||
as ThemeMode,dashboardItems: null == dashboardItems ? _self.dashboardItems : dashboardItems // ignore: cast_nullable_to_non_nullable
|
||||
as List<DashboardItem>,userLocale: freezed == userLocale ? _self.userLocale : userLocale // ignore: cast_nullable_to_non_nullable
|
||||
as Locale?,keepDataOnLogout: null == keepDataOnLogout ? _self.keepDataOnLogout : keepDataOnLogout // ignore: cast_nullable_to_non_nullable
|
||||
as bool,allowSelfSignedCerts: null == allowSelfSignedCerts ? _self.allowSelfSignedCerts : allowSelfSignedCerts // ignore: cast_nullable_to_non_nullable
|
||||
as bool,useDynamicColor: null == useDynamicColor ? _self.useDynamicColor : useDynamicColor // ignore: cast_nullable_to_non_nullable
|
||||
as bool,
|
||||
));
|
||||
}
|
||||
@@ -156,10 +160,10 @@ return $default(_that);case _:
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>(TResult Function( ThemeMode themeMode, List<DashboardItem> dashboardItems, Locale? userLocale, bool keepDataOnLogout, bool allowSelfSignedCerts)? $default,{required TResult orElse(),}) {final _that = this;
|
||||
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>(TResult Function( ThemeMode themeMode, List<DashboardItem> dashboardItems, Locale? userLocale, bool keepDataOnLogout, bool allowSelfSignedCerts, bool useDynamicColor)? $default,{required TResult orElse(),}) {final _that = this;
|
||||
switch (_that) {
|
||||
case _AppSettings() when $default != null:
|
||||
return $default(_that.themeMode,_that.dashboardItems,_that.userLocale,_that.keepDataOnLogout,_that.allowSelfSignedCerts);case _:
|
||||
return $default(_that.themeMode,_that.dashboardItems,_that.userLocale,_that.keepDataOnLogout,_that.allowSelfSignedCerts,_that.useDynamicColor);case _:
|
||||
return orElse();
|
||||
|
||||
}
|
||||
@@ -177,10 +181,10 @@ return $default(_that.themeMode,_that.dashboardItems,_that.userLocale,_that.keep
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult when<TResult extends Object?>(TResult Function( ThemeMode themeMode, List<DashboardItem> dashboardItems, Locale? userLocale, bool keepDataOnLogout, bool allowSelfSignedCerts) $default,) {final _that = this;
|
||||
@optionalTypeArgs TResult when<TResult extends Object?>(TResult Function( ThemeMode themeMode, List<DashboardItem> dashboardItems, Locale? userLocale, bool keepDataOnLogout, bool allowSelfSignedCerts, bool useDynamicColor) $default,) {final _that = this;
|
||||
switch (_that) {
|
||||
case _AppSettings():
|
||||
return $default(_that.themeMode,_that.dashboardItems,_that.userLocale,_that.keepDataOnLogout,_that.allowSelfSignedCerts);}
|
||||
return $default(_that.themeMode,_that.dashboardItems,_that.userLocale,_that.keepDataOnLogout,_that.allowSelfSignedCerts,_that.useDynamicColor);}
|
||||
}
|
||||
/// A variant of `when` that fallback to returning `null`
|
||||
///
|
||||
@@ -194,10 +198,10 @@ return $default(_that.themeMode,_that.dashboardItems,_that.userLocale,_that.keep
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function( ThemeMode themeMode, List<DashboardItem> dashboardItems, Locale? userLocale, bool keepDataOnLogout, bool allowSelfSignedCerts)? $default,) {final _that = this;
|
||||
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function( ThemeMode themeMode, List<DashboardItem> dashboardItems, Locale? userLocale, bool keepDataOnLogout, bool allowSelfSignedCerts, bool useDynamicColor)? $default,) {final _that = this;
|
||||
switch (_that) {
|
||||
case _AppSettings() when $default != null:
|
||||
return $default(_that.themeMode,_that.dashboardItems,_that.userLocale,_that.keepDataOnLogout,_that.allowSelfSignedCerts);case _:
|
||||
return $default(_that.themeMode,_that.dashboardItems,_that.userLocale,_that.keepDataOnLogout,_that.allowSelfSignedCerts,_that.useDynamicColor);case _:
|
||||
return null;
|
||||
|
||||
}
|
||||
@@ -209,7 +213,7 @@ return $default(_that.themeMode,_that.dashboardItems,_that.userLocale,_that.keep
|
||||
|
||||
|
||||
class _AppSettings implements AppSettings {
|
||||
const _AppSettings({this.themeMode = ThemeMode.system, final List<DashboardItem> dashboardItems = const [], this.userLocale, this.keepDataOnLogout = KEEP_DATA_ON_LOGOUT_DEFAULT, this.allowSelfSignedCerts = ALLOW_SELF_SIGNED_CERTS_DEFAULT}): _dashboardItems = dashboardItems;
|
||||
const _AppSettings({this.themeMode = ThemeMode.system, final List<DashboardItem> dashboardItems = const [], this.userLocale, this.keepDataOnLogout = KEEP_DATA_ON_LOGOUT_DEFAULT, this.allowSelfSignedCerts = ALLOW_SELF_SIGNED_CERTS_DEFAULT, this.useDynamicColor = USE_DYNAMIC_COLOR_DEFAULT}): _dashboardItems = dashboardItems;
|
||||
|
||||
|
||||
@override@JsonKey() final ThemeMode themeMode;
|
||||
@@ -228,6 +232,10 @@ class _AppSettings implements AppSettings {
|
||||
/// When true, an invalid TLS certificate is accepted from the self-hosted
|
||||
/// server the app is configured for. Never applies to the official servers.
|
||||
@override@JsonKey() final bool allowSelfSignedCerts;
|
||||
/// When true, the app palette follows the platform dynamic colors
|
||||
/// (system wallpaper on Android 12+) instead of the fixed wger seeds.
|
||||
/// A no-op on platforms without dynamic color support.
|
||||
@override@JsonKey() final bool useDynamicColor;
|
||||
|
||||
/// Create a copy of AppSettings
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@@ -239,16 +247,16 @@ _$AppSettingsCopyWith<_AppSettings> get copyWith => __$AppSettingsCopyWithImpl<_
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is _AppSettings&&(identical(other.themeMode, themeMode) || other.themeMode == themeMode)&&const DeepCollectionEquality().equals(other._dashboardItems, _dashboardItems)&&(identical(other.userLocale, userLocale) || other.userLocale == userLocale)&&(identical(other.keepDataOnLogout, keepDataOnLogout) || other.keepDataOnLogout == keepDataOnLogout)&&(identical(other.allowSelfSignedCerts, allowSelfSignedCerts) || other.allowSelfSignedCerts == allowSelfSignedCerts));
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is _AppSettings&&(identical(other.themeMode, themeMode) || other.themeMode == themeMode)&&const DeepCollectionEquality().equals(other._dashboardItems, _dashboardItems)&&(identical(other.userLocale, userLocale) || other.userLocale == userLocale)&&(identical(other.keepDataOnLogout, keepDataOnLogout) || other.keepDataOnLogout == keepDataOnLogout)&&(identical(other.allowSelfSignedCerts, allowSelfSignedCerts) || other.allowSelfSignedCerts == allowSelfSignedCerts)&&(identical(other.useDynamicColor, useDynamicColor) || other.useDynamicColor == useDynamicColor));
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(runtimeType,themeMode,const DeepCollectionEquality().hash(_dashboardItems),userLocale,keepDataOnLogout,allowSelfSignedCerts);
|
||||
int get hashCode => Object.hash(runtimeType,themeMode,const DeepCollectionEquality().hash(_dashboardItems),userLocale,keepDataOnLogout,allowSelfSignedCerts,useDynamicColor);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'AppSettings(themeMode: $themeMode, dashboardItems: $dashboardItems, userLocale: $userLocale, keepDataOnLogout: $keepDataOnLogout, allowSelfSignedCerts: $allowSelfSignedCerts)';
|
||||
return 'AppSettings(themeMode: $themeMode, dashboardItems: $dashboardItems, userLocale: $userLocale, keepDataOnLogout: $keepDataOnLogout, allowSelfSignedCerts: $allowSelfSignedCerts, useDynamicColor: $useDynamicColor)';
|
||||
}
|
||||
|
||||
|
||||
@@ -259,7 +267,7 @@ abstract mixin class _$AppSettingsCopyWith<$Res> implements $AppSettingsCopyWith
|
||||
factory _$AppSettingsCopyWith(_AppSettings value, $Res Function(_AppSettings) _then) = __$AppSettingsCopyWithImpl;
|
||||
@override @useResult
|
||||
$Res call({
|
||||
ThemeMode themeMode, List<DashboardItem> dashboardItems, Locale? userLocale, bool keepDataOnLogout, bool allowSelfSignedCerts
|
||||
ThemeMode themeMode, List<DashboardItem> dashboardItems, Locale? userLocale, bool keepDataOnLogout, bool allowSelfSignedCerts, bool useDynamicColor
|
||||
});
|
||||
|
||||
|
||||
@@ -276,13 +284,14 @@ class __$AppSettingsCopyWithImpl<$Res>
|
||||
|
||||
/// Create a copy of AppSettings
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override @pragma('vm:prefer-inline') $Res call({Object? themeMode = null,Object? dashboardItems = null,Object? userLocale = freezed,Object? keepDataOnLogout = null,Object? allowSelfSignedCerts = null,}) {
|
||||
@override @pragma('vm:prefer-inline') $Res call({Object? themeMode = null,Object? dashboardItems = null,Object? userLocale = freezed,Object? keepDataOnLogout = null,Object? allowSelfSignedCerts = null,Object? useDynamicColor = null,}) {
|
||||
return _then(_AppSettings(
|
||||
themeMode: null == themeMode ? _self.themeMode : themeMode // ignore: cast_nullable_to_non_nullable
|
||||
as ThemeMode,dashboardItems: null == dashboardItems ? _self._dashboardItems : dashboardItems // ignore: cast_nullable_to_non_nullable
|
||||
as List<DashboardItem>,userLocale: freezed == userLocale ? _self.userLocale : userLocale // ignore: cast_nullable_to_non_nullable
|
||||
as Locale?,keepDataOnLogout: null == keepDataOnLogout ? _self.keepDataOnLogout : keepDataOnLogout // ignore: cast_nullable_to_non_nullable
|
||||
as bool,allowSelfSignedCerts: null == allowSelfSignedCerts ? _self.allowSelfSignedCerts : allowSelfSignedCerts // ignore: cast_nullable_to_non_nullable
|
||||
as bool,useDynamicColor: null == useDynamicColor ? _self.useDynamicColor : useDynamicColor // ignore: cast_nullable_to_non_nullable
|
||||
as bool,
|
||||
));
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ final class AppSettingsNotifierProvider
|
||||
AppSettingsNotifier create() => AppSettingsNotifier();
|
||||
}
|
||||
|
||||
String _$appSettingsNotifierHash() => r'499323f5b84feb0c395538db14e4d0a7de831b7c';
|
||||
String _$appSettingsNotifierHash() => r'71c64280cc0755452c9610247852a982be21a157';
|
||||
|
||||
abstract class _$AppSettingsNotifier extends $AsyncNotifier<AppSettings> {
|
||||
FutureOr<AppSettings> build();
|
||||
|
||||
@@ -1,49 +1,67 @@
|
||||
/*
|
||||
* This file is part of wger Workout Manager <https://github.com/wger-project>.
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import 'package:flex_color_scheme/flex_color_scheme.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
const LIST_OF_COLORS8 = [
|
||||
Color(0xFF2A4C7D),
|
||||
Color(0xFF5B5291),
|
||||
Color(0xFF8E5298),
|
||||
Color(0xFFBF5092),
|
||||
Color(0xFFE7537E),
|
||||
Color(0xFFFF6461),
|
||||
Color(0xFFFF813D),
|
||||
Color(0xFFFFA600),
|
||||
];
|
||||
|
||||
const LIST_OF_COLORS5 = [
|
||||
Color(0xFF2A4C7D),
|
||||
Color(0xFF825298),
|
||||
Color(0xFFD45089),
|
||||
Color(0xFFFF6A59),
|
||||
Color(0xFFFFA600),
|
||||
];
|
||||
|
||||
const LIST_OF_COLORS3 = [
|
||||
Color(0xFF2A4C7D),
|
||||
Color(0xFFD45089),
|
||||
Color(0xFFFFA600),
|
||||
];
|
||||
|
||||
const COLOR_SURPLUS = Color.fromARGB(255, 231, 71, 71);
|
||||
|
||||
Iterable<Color> generateChartColors(int nrOfItems) sync* {
|
||||
final List<Color> colors;
|
||||
const _CHART_CHROMA = 60.0;
|
||||
const _CHART_TONE_LIGHT = (from: 32.0, to: 75.0);
|
||||
const _CHART_TONE_DARK = (from: 58.0, to: 80.0);
|
||||
|
||||
if (nrOfItems <= 3) {
|
||||
colors = LIST_OF_COLORS3;
|
||||
} else if (nrOfItems <= 5) {
|
||||
colors = LIST_OF_COLORS5;
|
||||
} else {
|
||||
colors = LIST_OF_COLORS8;
|
||||
}
|
||||
/// [nrOfItems] chart colors derived from the scheme's primary hue.
|
||||
///
|
||||
/// Hue is spread evenly around the wheel and tone ramps across the palette, so
|
||||
/// neighbouring series differ in both. The lightness difference is what carries
|
||||
/// in greyscale and with a color vision deficiency. The tones follow the
|
||||
/// scheme's brightness, and the first color always matches the theme.
|
||||
List<Color> chartColorPalette(int nrOfItems, ColorScheme scheme) {
|
||||
final count = nrOfItems < 1 ? 1 : nrOfItems;
|
||||
final baseHue = Hct.fromInt(scheme.primary.toARGB32()).hue;
|
||||
final tones = scheme.brightness == Brightness.dark ? _CHART_TONE_DARK : _CHART_TONE_LIGHT;
|
||||
|
||||
for (final color in colors) {
|
||||
yield color;
|
||||
}
|
||||
return List.generate(count, (i) {
|
||||
final hue = (baseHue + 360 / count * i) % 360;
|
||||
final tone = count == 1 ? tones.from : tones.from + (tones.to - tones.from) * i / (count - 1);
|
||||
|
||||
return Color(Hct.from(hue, _CHART_CHROMA, tone).toInt());
|
||||
});
|
||||
}
|
||||
|
||||
/// Black or white, whichever contrasts more with [background].
|
||||
///
|
||||
/// For labels drawn directly on a data color, which has no matching `on` role
|
||||
/// the way a scheme surface does.
|
||||
Color onChartColor(Color background) {
|
||||
final luminance = background.computeLuminance();
|
||||
final contrastWithBlack = (luminance + 0.05) / 0.05;
|
||||
final contrastWithWhite = 1.05 / (luminance + 0.05);
|
||||
|
||||
return contrastWithBlack >= contrastWithWhite ? Colors.black : Colors.white;
|
||||
}
|
||||
|
||||
/// The palette from [chartColorPalette], repeating once exhausted so a caller
|
||||
/// pulling more colors than it asked for can never run out.
|
||||
Iterable<Color> generateChartColors(int nrOfItems, ColorScheme scheme) sync* {
|
||||
final colors = chartColorPalette(nrOfItems, scheme);
|
||||
|
||||
// Always return black after generating nrOfItems colors
|
||||
while (true) {
|
||||
yield Colors.black;
|
||||
yield* colors;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,6 +59,16 @@ const PREFS_USER_DARK_THEME = 'userDarkMode';
|
||||
const PREFS_USER_LOCALE = 'userLocale';
|
||||
const PREFS_LAST_SERVER = 'lastServer';
|
||||
|
||||
/// User preference: use Material You dynamic colors from the platform instead
|
||||
/// of the fixed wger seed palette. Defaults to [USE_DYNAMIC_COLOR_DEFAULT].
|
||||
///
|
||||
/// Android 12+ supplies a wallpaper palette, macOS (10.14+), Windows and
|
||||
/// GTK-based Linux a system accent color. iOS and the web have no
|
||||
/// implementation, so the setting is only offered where dynamicColorAvailable
|
||||
/// reports true.
|
||||
const PREFS_USE_DYNAMIC_COLOR = 'useDynamicColor';
|
||||
const USE_DYNAMIC_COLOR_DEFAULT = false;
|
||||
|
||||
/// Headless JWT auth: SharedPreferences keys.
|
||||
///
|
||||
/// Read in parallel with the legacy `PREFS_USER` blob during the migration
|
||||
|
||||
@@ -179,7 +179,10 @@ void showGeneralErrorDialog(dynamic error, StackTrace? stackTrace, {BuildContext
|
||||
child: SingleChildScrollView(
|
||||
child: Text(
|
||||
fullStackTrace,
|
||||
style: TextStyle(fontSize: 12.0, color: Colors.grey[700]),
|
||||
style: TextStyle(
|
||||
fontSize: 12.0,
|
||||
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -201,7 +204,10 @@ void showGeneralErrorDialog(dynamic error, StackTrace? stackTrace, {BuildContext
|
||||
...applicationLogs.map(
|
||||
(entry) => Text(
|
||||
entry,
|
||||
style: TextStyle(fontSize: 12.0, color: Colors.grey[700]),
|
||||
style: TextStyle(
|
||||
fontSize: 12.0,
|
||||
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
@@ -51,7 +51,7 @@ class Pill extends StatelessWidget {
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 7),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).primaryColorLight.withValues(alpha: 0.15),
|
||||
border: Border.all(color: Colors.grey[300]!),
|
||||
border: Border.all(color: Theme.of(context).colorScheme.outlineVariant),
|
||||
borderRadius: BorderRadius.circular(5),
|
||||
),
|
||||
child: Text(title),
|
||||
@@ -63,14 +63,15 @@ class CircleIconAvatar extends StatelessWidget {
|
||||
final double radius;
|
||||
final Icon _icon;
|
||||
|
||||
final Color color;
|
||||
/// Defaults to the theme's highest container tone.
|
||||
final Color? color;
|
||||
|
||||
const CircleIconAvatar(this._icon, {this.radius = 20, this.color = Colors.black12});
|
||||
const CircleIconAvatar(this._icon, {this.radius = 20, this.color});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return CircleAvatar(
|
||||
backgroundColor: color,
|
||||
backgroundColor: color ?? Theme.of(context).colorScheme.surfaceContainerHighest,
|
||||
radius: radius,
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(50.0),
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:wger/core/form_screen.dart';
|
||||
import 'package:wger/theme/theme.dart';
|
||||
|
||||
class NothingFound extends StatelessWidget {
|
||||
final String _title;
|
||||
@@ -38,7 +37,8 @@ class NothingFound extends StatelessWidget {
|
||||
if (_titleForm != null && _form != null)
|
||||
IconButton(
|
||||
iconSize: 30,
|
||||
icon: const Icon(Icons.add_box, color: wgerPrimaryButtonColor),
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
icon: const Icon(Icons.add_box),
|
||||
onPressed: () {
|
||||
Navigator.pushNamed(
|
||||
context,
|
||||
|
||||
@@ -32,7 +32,6 @@ import 'package:wger/features/routines/screens/gym_mode.dart';
|
||||
import 'package:wger/features/routines/screens/routine_screen.dart';
|
||||
import 'package:wger/features/routines/widgets/forms/routine.dart';
|
||||
import 'package:wger/l10n/generated/app_localizations.dart';
|
||||
import 'package:wger/theme/theme.dart';
|
||||
|
||||
class DashboardRoutineWidget extends ConsumerStatefulWidget {
|
||||
const DashboardRoutineWidget();
|
||||
@@ -248,7 +247,7 @@ class DetailContentWidget extends StatelessWidget {
|
||||
IconButton(
|
||||
tooltip: AppLocalizations.of(context).gymMode,
|
||||
icon: const Icon(Icons.play_arrow),
|
||||
color: wgerPrimaryButtonColor,
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
onPressed: () {
|
||||
Navigator.of(context).pushNamed(
|
||||
GymModeScreen.routeName,
|
||||
|
||||
@@ -154,7 +154,11 @@ class _PlainErrorBody extends StatelessWidget {
|
||||
const SizedBox(height: 8),
|
||||
SelectableText(
|
||||
stacktrace.toString(),
|
||||
style: const TextStyle(fontFamily: 'monospace', fontSize: 11, color: Colors.grey),
|
||||
style: TextStyle(
|
||||
fontFamily: 'monospace',
|
||||
fontSize: 11,
|
||||
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
|
||||
@@ -44,12 +44,12 @@ class FormProgressIndicator extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const SizedBox(
|
||||
return SizedBox(
|
||||
height: 20,
|
||||
width: 20,
|
||||
child: CircularProgressIndicator(
|
||||
valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
|
||||
),
|
||||
// Takes the surrounding foreground: the label color inside a button, the
|
||||
// leading icon color inside a ListTile.
|
||||
child: CircularProgressIndicator(color: IconTheme.of(context).color),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
*/
|
||||
|
||||
import 'package:drift/drift.dart' as drift;
|
||||
import 'package:wger/core/consts.dart';
|
||||
import 'package:wger/database/powersync/database.dart';
|
||||
|
||||
/// The user's editable profile preferences.
|
||||
@@ -28,6 +29,9 @@ class UserProfile {
|
||||
|
||||
bool get isMetric => weightUnitStr == 'kg';
|
||||
|
||||
/// Weight unit implied by the metric preference: kg for metric users, lb otherwise.
|
||||
int get defaultWeightUnitId => isMetric ? WEIGHT_UNIT_KG : WEIGHT_UNIT_LB;
|
||||
|
||||
/// Drift companion for local UPDATE writes routed through PowerSync.
|
||||
UserProfileTableCompanion toCompanion() {
|
||||
return UserProfileTableCompanion(
|
||||
|
||||
@@ -28,7 +28,6 @@ import 'package:wger/features/account/models/user_profile.dart';
|
||||
import 'package:wger/features/account/providers/account_notifier.dart';
|
||||
import 'package:wger/features/account/providers/user_profile_notifier.dart';
|
||||
import 'package:wger/l10n/generated/app_localizations.dart';
|
||||
import 'package:wger/theme/theme.dart';
|
||||
|
||||
/// Shows the user's account data and lets them edit the profile preferences.
|
||||
///
|
||||
@@ -83,7 +82,7 @@ class _UserProfileFormState extends ConsumerState<UserProfileForm> {
|
||||
child: Column(
|
||||
children: [
|
||||
ListTile(
|
||||
leading: const Icon(Icons.person, color: wgerPrimaryColor),
|
||||
leading: Icon(Icons.person, color: Theme.of(context).colorScheme.primary),
|
||||
title: Text(i18n.username),
|
||||
subtitle: Text(account.username),
|
||||
),
|
||||
@@ -99,7 +98,7 @@ class _UserProfileFormState extends ConsumerState<UserProfileForm> {
|
||||
dense: true,
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.email_rounded, color: wgerPrimaryColor),
|
||||
leading: Icon(Icons.email_rounded, color: Theme.of(context).colorScheme.primary),
|
||||
title: TextFormField(
|
||||
decoration: InputDecoration(
|
||||
labelText: account.emailVerified ? i18n.verifiedEmail : i18n.unVerifiedEmail,
|
||||
@@ -135,7 +134,7 @@ class _UserProfileFormState extends ConsumerState<UserProfileForm> {
|
||||
const Divider(height: 32),
|
||||
ListTile(
|
||||
key: const Key('manageAccountOnWebTile'),
|
||||
leading: const Icon(Icons.open_in_new, color: wgerPrimaryColor),
|
||||
leading: Icon(Icons.open_in_new, color: Theme.of(context).colorScheme.primary),
|
||||
title: Text(i18n.manageAccountOnWeb),
|
||||
subtitle: Text(i18n.manageAccountOnWebSubtitle),
|
||||
enabled: isOnline,
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:wger/core/app_settings_notifier.dart';
|
||||
import 'package:wger/core/consts.dart';
|
||||
import 'package:wger/l10n/generated/app_localizations.dart';
|
||||
import 'package:wger/theme/dynamic_color.dart';
|
||||
|
||||
class SettingsTheme extends ConsumerWidget {
|
||||
const SettingsTheme({super.key});
|
||||
@@ -12,32 +14,51 @@ class SettingsTheme extends ConsumerWidget {
|
||||
final currentMode = ref.watch(
|
||||
appSettingsProvider.select((s) => s.value?.themeMode ?? ThemeMode.system),
|
||||
);
|
||||
final useDynamicColor = ref.watch(
|
||||
appSettingsProvider.select((s) => s.value?.useDynamicColor ?? USE_DYNAMIC_COLOR_DEFAULT),
|
||||
);
|
||||
// Hidden while the probe is still running and where it comes back negative:
|
||||
// the toggle does nothing on a platform without a dynamic palette.
|
||||
final showDynamicColor = ref.watch(dynamicColorAvailableProvider).value ?? false;
|
||||
|
||||
return ListTile(
|
||||
title: Text(i18n.themeMode),
|
||||
trailing: DropdownButton<ThemeMode>(
|
||||
key: const ValueKey('themeModeDropdown'),
|
||||
value: currentMode,
|
||||
onChanged: (ThemeMode? newValue) {
|
||||
if (newValue != null) {
|
||||
ref.read(appSettingsProvider.notifier).setThemeMode(newValue);
|
||||
}
|
||||
},
|
||||
items: ThemeMode.values.map<DropdownMenuItem<ThemeMode>>((ThemeMode value) {
|
||||
final label = (() {
|
||||
switch (value) {
|
||||
case ThemeMode.system:
|
||||
return i18n.systemMode;
|
||||
case ThemeMode.light:
|
||||
return i18n.lightMode;
|
||||
case ThemeMode.dark:
|
||||
return i18n.darkMode;
|
||||
}
|
||||
})();
|
||||
return Column(
|
||||
children: [
|
||||
ListTile(
|
||||
title: Text(i18n.themeMode),
|
||||
trailing: DropdownButton<ThemeMode>(
|
||||
key: const ValueKey('themeModeDropdown'),
|
||||
value: currentMode,
|
||||
onChanged: (ThemeMode? newValue) {
|
||||
if (newValue != null) {
|
||||
ref.read(appSettingsProvider.notifier).setThemeMode(newValue);
|
||||
}
|
||||
},
|
||||
items: ThemeMode.values.map<DropdownMenuItem<ThemeMode>>((ThemeMode value) {
|
||||
final label = (() {
|
||||
switch (value) {
|
||||
case ThemeMode.system:
|
||||
return i18n.systemMode;
|
||||
case ThemeMode.light:
|
||||
return i18n.lightMode;
|
||||
case ThemeMode.dark:
|
||||
return i18n.darkMode;
|
||||
}
|
||||
})();
|
||||
|
||||
return DropdownMenuItem<ThemeMode>(value: value, child: Text(label));
|
||||
}).toList(),
|
||||
),
|
||||
return DropdownMenuItem<ThemeMode>(value: value, child: Text(label));
|
||||
}).toList(),
|
||||
),
|
||||
),
|
||||
if (showDynamicColor)
|
||||
SwitchListTile(
|
||||
key: const ValueKey('useDynamicColorSwitch'),
|
||||
title: Text(i18n.useDynamicColor),
|
||||
value: useDynamicColor,
|
||||
onChanged: (bool value) {
|
||||
ref.read(appSettingsProvider.notifier).setUseDynamicColor(value);
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:wger/features/auth/widgets/auth_card.dart';
|
||||
import 'package:wger/theme/theme.dart';
|
||||
|
||||
class AuthScreen extends StatelessWidget {
|
||||
const AuthScreen();
|
||||
@@ -28,8 +27,15 @@ class AuthScreen extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final deviceSize = MediaQuery.sizeOf(context);
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
// The banner carries the white logo, so it has to stay dark in both modes.
|
||||
// primary is the dark tone in light mode, primaryContainer in dark mode.
|
||||
final isDark = scheme.brightness == Brightness.dark;
|
||||
final bannerColor = isDark ? scheme.primaryContainer : scheme.primary;
|
||||
final onBannerColor = isDark ? scheme.onPrimaryContainer : scheme.onPrimary;
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: Theme.of(context).colorScheme.surface,
|
||||
backgroundColor: scheme.surface,
|
||||
body: Stack(
|
||||
children: [
|
||||
Positioned(
|
||||
@@ -38,7 +44,7 @@ class AuthScreen extends StatelessWidget {
|
||||
left: 0,
|
||||
child: Container(
|
||||
height: 0.55 * deviceSize.height,
|
||||
color: wgerPrimaryColor,
|
||||
color: bannerColor,
|
||||
),
|
||||
),
|
||||
SingleChildScrollView(
|
||||
@@ -61,10 +67,10 @@ class AuthScreen extends StatelessWidget {
|
||||
vertical: 8.0,
|
||||
horizontal: 94.0,
|
||||
),
|
||||
child: const Text(
|
||||
child: Text(
|
||||
'wger',
|
||||
style: TextStyle(
|
||||
color: Colors.white70,
|
||||
color: onBannerColor.withValues(alpha: 0.7),
|
||||
fontSize: 30,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
|
||||
@@ -28,6 +28,11 @@ class _AddExerciseMultiselectButtonState<T> extends State<AddExerciseMultiselect
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
// Dimmed once something is selected: the chips below carry the content and
|
||||
// the title drops back to a caption.
|
||||
final labelColor = _selectedItems.isEmpty ? scheme.onSurfaceVariant : scheme.outline;
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: MultiSelectDialogField(
|
||||
@@ -53,19 +58,13 @@ class _AddExerciseMultiselectButtonState<T> extends State<AddExerciseMultiselect
|
||||
icon: const Icon(Icons.close),
|
||||
),
|
||||
title: Text(widget.title),
|
||||
buttonText: Text(
|
||||
widget.title,
|
||||
style: TextStyle(
|
||||
color: _selectedItems.isEmpty ? Colors.grey[700] : Colors.grey,
|
||||
),
|
||||
),
|
||||
buttonIcon: Icon(
|
||||
Icons.arrow_drop_down,
|
||||
color: _selectedItems.isEmpty ? Colors.grey[700] : Colors.grey,
|
||||
),
|
||||
buttonText: Text(widget.title, style: TextStyle(color: labelColor)),
|
||||
buttonIcon: Icon(Icons.arrow_drop_down, color: labelColor),
|
||||
decoration: BoxDecoration(
|
||||
// Once chips carry the selection the outline is dropped, the same way
|
||||
// a filled input field loses its placeholder framing.
|
||||
border: Border.all(
|
||||
color: _selectedItems.isEmpty ? Colors.grey : Colors.transparent,
|
||||
color: _selectedItems.isEmpty ? scheme.outline : Colors.transparent,
|
||||
),
|
||||
borderRadius: const BorderRadius.all(Radius.circular(10)),
|
||||
),
|
||||
|
||||
@@ -155,13 +155,13 @@ class _ImageDetailsFormState extends State<ImageDetailsForm> {
|
||||
widget.onAdd(widget.submissionImage);
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Theme.of(context).primaryColor,
|
||||
foregroundColor: Colors.white,
|
||||
backgroundColor: Theme.of(context).colorScheme.primary,
|
||||
foregroundColor: Theme.of(context).colorScheme.onPrimary,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 32, vertical: 12),
|
||||
),
|
||||
child: Text(
|
||||
AppLocalizations.of(context).add,
|
||||
style: const TextStyle(fontWeight: FontWeight.bold, color: Colors.white),
|
||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -181,7 +181,7 @@ class ImagePreview extends StatelessWidget {
|
||||
constraints: const BoxConstraints(maxWidth: 300, maxHeight: 200),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(color: Colors.grey.shade300),
|
||||
border: Border.all(color: Theme.of(context).colorScheme.outlineVariant),
|
||||
),
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
|
||||
@@ -203,13 +203,17 @@ class _Step5ImagesState extends ConsumerState<Step5Images> with ExerciseImagePic
|
||||
return Column(
|
||||
children: [
|
||||
const SizedBox(height: 20),
|
||||
Icon(Icons.add_photo_alternate, size: 80, color: Colors.grey.shade400),
|
||||
Icon(
|
||||
Icons.add_photo_alternate,
|
||||
size: 80,
|
||||
color: Theme.of(context).colorScheme.outline,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'No images selected',
|
||||
style: Theme.of(
|
||||
context,
|
||||
).textTheme.titleMedium?.copyWith(color: Colors.grey.shade600),
|
||||
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
||||
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
// Camera and Gallery buttons
|
||||
@@ -240,9 +244,9 @@ class _Step5ImagesState extends ConsumerState<Step5Images> with ExerciseImagePic
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16.0),
|
||||
child: Text(
|
||||
'Only JPEG, PNG and WEBP files below 20 MB are supported',
|
||||
style: Theme.of(
|
||||
context,
|
||||
).textTheme.bodySmall?.copyWith(color: Colors.grey.shade600),
|
||||
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
||||
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
|
||||
@@ -206,7 +206,9 @@ class _CarouselImagesState extends State<CarouselImages> {
|
||||
height: 8,
|
||||
width: 8,
|
||||
decoration: BoxDecoration(
|
||||
color: pageIndex == index ? Colors.black : Colors.black26,
|
||||
color: pageIndex == index
|
||||
? Theme.of(context).colorScheme.primary
|
||||
: Theme.of(context).colorScheme.onSurface.withValues(alpha: 0.26),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
),
|
||||
|
||||
@@ -69,9 +69,6 @@ class _FilterRowState extends ConsumerState<FilterRow> {
|
||||
decoration: InputDecoration(
|
||||
hintText: '${AppLocalizations.of(context).exerciseName}...',
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 10),
|
||||
border: const OutlineInputBorder(
|
||||
borderSide: BorderSide(color: Colors.black),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -396,10 +396,10 @@ class _MeasurementChartWidgetFlState extends State<MeasurementChartWidgetFl> {
|
||||
// horizontalInterval: 1,
|
||||
// verticalInterval: 1,
|
||||
getDrawingHorizontalLine: (value) {
|
||||
return FlLine(color: Theme.of(context).colorScheme.primaryContainer, strokeWidth: 1);
|
||||
return FlLine(color: Theme.of(context).colorScheme.outlineVariant, strokeWidth: 1);
|
||||
},
|
||||
getDrawingVerticalLine: (value) {
|
||||
return FlLine(color: Theme.of(context).colorScheme.primaryContainer, strokeWidth: 1);
|
||||
return FlLine(color: Theme.of(context).colorScheme.outlineVariant, strokeWidth: 1);
|
||||
},
|
||||
),
|
||||
titlesData: FlTitlesData(
|
||||
@@ -456,7 +456,7 @@ class _MeasurementChartWidgetFlState extends State<MeasurementChartWidgetFl> {
|
||||
),
|
||||
borderData: FlBorderData(
|
||||
show: true,
|
||||
border: Border.all(color: Theme.of(context).colorScheme.primaryContainer),
|
||||
border: Border.all(color: Theme.of(context).colorScheme.outlineVariant),
|
||||
),
|
||||
lineBarsData: bars,
|
||||
);
|
||||
|
||||
@@ -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) 2020 - 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.
|
||||
@@ -53,6 +53,10 @@ class FlNutritionalPlanGoalWidget extends StatelessWidget {
|
||||
double? plan,
|
||||
double val,
|
||||
) {
|
||||
// Four gauges of the same measure, not four categories, so they share the
|
||||
// theme's primary rather than pulling from the chart palette.
|
||||
final barColor = Theme.of(context).colorScheme.primary;
|
||||
|
||||
Container segment(double width, Color color) {
|
||||
return Container(
|
||||
height: 16,
|
||||
@@ -66,7 +70,7 @@ class FlNutritionalPlanGoalWidget extends StatelessWidget {
|
||||
|
||||
// paint a simple bar
|
||||
if (plan == null || val == plan) {
|
||||
return segment(normWidth, LIST_OF_COLORS8[0]);
|
||||
return segment(normWidth, barColor);
|
||||
}
|
||||
|
||||
// paint a surplus
|
||||
@@ -74,7 +78,7 @@ class FlNutritionalPlanGoalWidget extends StatelessWidget {
|
||||
return Stack(
|
||||
children: [
|
||||
segment(normWidth * val / plan, COLOR_SURPLUS),
|
||||
segment(normWidth, LIST_OF_COLORS8[0]),
|
||||
segment(normWidth, barColor),
|
||||
],
|
||||
);
|
||||
}
|
||||
@@ -83,7 +87,7 @@ class FlNutritionalPlanGoalWidget extends StatelessWidget {
|
||||
return Stack(
|
||||
children: [
|
||||
segment(normWidth, Theme.of(context).colorScheme.surface),
|
||||
segment(normWidth * val / plan, LIST_OF_COLORS8[0]),
|
||||
segment(normWidth * val / plan, barColor),
|
||||
],
|
||||
);
|
||||
}
|
||||
@@ -212,6 +216,9 @@ class FlNutritionalPlanPieChartWidget extends StatefulWidget {
|
||||
class FlNutritionalPlanPieChartState extends State<FlNutritionalPlanPieChartWidget> {
|
||||
int touchedIndex = -1;
|
||||
|
||||
/// Shared by the sections and the legend so both stay in sync.
|
||||
List<Color> get _macroColors => chartColorPalette(3, Theme.of(context).colorScheme);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Row(
|
||||
@@ -248,9 +255,9 @@ class FlNutritionalPlanPieChartState extends State<FlNutritionalPlanPieChartWidg
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children:
|
||||
[
|
||||
(AppLocalizations.of(context).protein, LIST_OF_COLORS3[1]),
|
||||
(AppLocalizations.of(context).carbohydrates, LIST_OF_COLORS3[0]),
|
||||
(AppLocalizations.of(context).fat, LIST_OF_COLORS3[2]),
|
||||
(AppLocalizations.of(context).protein, _macroColors[1]),
|
||||
(AppLocalizations.of(context).carbohydrates, _macroColors[0]),
|
||||
(AppLocalizations.of(context).fat, _macroColors[2]),
|
||||
]
|
||||
.map(
|
||||
(e) => Padding(
|
||||
@@ -267,9 +274,9 @@ class FlNutritionalPlanPieChartState extends State<FlNutritionalPlanPieChartWidg
|
||||
|
||||
List<PieChartSectionData> showingSections() {
|
||||
return [
|
||||
(0, LIST_OF_COLORS3[1], widget.nutritionalValues.protein),
|
||||
(1, LIST_OF_COLORS3[0], widget.nutritionalValues.carbohydrates),
|
||||
(2, LIST_OF_COLORS3[2], widget.nutritionalValues.fat),
|
||||
(0, _macroColors[1], widget.nutritionalValues.protein),
|
||||
(1, _macroColors[0], widget.nutritionalValues.carbohydrates),
|
||||
(2, _macroColors[2], widget.nutritionalValues.fat),
|
||||
].map((e) {
|
||||
final isTouched = e.$1 == touchedIndex;
|
||||
final radius = isTouched ? 92.0 : 80.0;
|
||||
@@ -278,6 +285,8 @@ class FlNutritionalPlanPieChartState extends State<FlNutritionalPlanPieChartWidg
|
||||
color: e.$2,
|
||||
value: e.$3,
|
||||
title: '${e.$3.toStringAsFixed(0)}g',
|
||||
// Merged onto the ambient style, so only the color is overridden.
|
||||
titleStyle: TextStyle(color: onChartColor(e.$2)),
|
||||
titlePositionPercentageOffset: 0.5,
|
||||
radius: radius,
|
||||
);
|
||||
@@ -336,7 +345,10 @@ class NutritionalDiaryChartWidgetFlState extends State<NutritionalDiaryChartWidg
|
||||
final loggedToday = widget._nutritionalPlan.loggedNutritionalValuesToday;
|
||||
final logged7DayAvg = widget._nutritionalPlan.loggedNutritionalValues7DayAvg;
|
||||
|
||||
final [colorPlanned, colorLoggedToday, colorLogged7Day] = LIST_OF_COLORS3;
|
||||
final [colorPlanned, colorLoggedToday, colorLogged7Day] = chartColorPalette(
|
||||
3,
|
||||
Theme.of(context).colorScheme,
|
||||
);
|
||||
|
||||
BarChartGroupData barchartGroup(
|
||||
int x,
|
||||
@@ -424,8 +436,8 @@ class NutritionalDiaryChartWidgetFlState extends State<NutritionalDiaryChartWidg
|
||||
gridData: FlGridData(
|
||||
show: true,
|
||||
checkToShowHorizontalLine: (value) => value % 10 == 0,
|
||||
getDrawingHorizontalLine: (value) => const FlLine(
|
||||
color: Colors.black,
|
||||
getDrawingHorizontalLine: (value) => FlLine(
|
||||
color: Theme.of(context).colorScheme.outlineVariant,
|
||||
strokeWidth: 1,
|
||||
),
|
||||
drawVerticalLine: false,
|
||||
@@ -570,8 +582,8 @@ class MealDiaryBarChartWidgetState extends State<MealDiaryBarChartWidget> {
|
||||
),
|
||||
gridData: FlGridData(
|
||||
show: true,
|
||||
getDrawingHorizontalLine: (value) => const FlLine(
|
||||
color: Colors.black,
|
||||
getDrawingHorizontalLine: (value) => FlLine(
|
||||
color: Theme.of(context).colorScheme.outlineVariant,
|
||||
strokeWidth: 1,
|
||||
),
|
||||
drawVerticalLine: false,
|
||||
@@ -586,7 +598,7 @@ class MealDiaryBarChartWidgetState extends State<MealDiaryBarChartWidget> {
|
||||
barRods: [
|
||||
BarChartRodData(
|
||||
toY: _safePercent(widget._logged.energy, widget._planned.energy),
|
||||
color: LIST_OF_COLORS3.first,
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
width: barsWidth,
|
||||
),
|
||||
],
|
||||
@@ -597,7 +609,7 @@ class MealDiaryBarChartWidgetState extends State<MealDiaryBarChartWidget> {
|
||||
barRods: [
|
||||
BarChartRodData(
|
||||
toY: _safePercent(widget._logged.protein, widget._planned.protein),
|
||||
color: LIST_OF_COLORS3.first,
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
width: barsWidth,
|
||||
),
|
||||
],
|
||||
@@ -611,7 +623,7 @@ class MealDiaryBarChartWidgetState extends State<MealDiaryBarChartWidget> {
|
||||
widget._logged.carbohydrates,
|
||||
widget._planned.carbohydrates,
|
||||
),
|
||||
color: LIST_OF_COLORS3.first,
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
width: barsWidth,
|
||||
),
|
||||
],
|
||||
@@ -622,7 +634,7 @@ class MealDiaryBarChartWidgetState extends State<MealDiaryBarChartWidget> {
|
||||
barRods: [
|
||||
BarChartRodData(
|
||||
toY: _safePercent(widget._logged.fat, widget._planned.fat),
|
||||
color: LIST_OF_COLORS3.first,
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
width: barsWidth,
|
||||
),
|
||||
],
|
||||
|
||||
@@ -68,9 +68,6 @@ class _IngredientFilterRowState extends ConsumerState<IngredientFilterRow> {
|
||||
hintText: '${i18n.searchIngredient}...',
|
||||
prefixIcon: const Icon(Icons.search),
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 10),
|
||||
border: const OutlineInputBorder(
|
||||
borderSide: BorderSide(color: Colors.black),
|
||||
),
|
||||
suffixIcon: _ClearSearchTermButton(controller: _ingredientNameController),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:wger/core/colors.dart';
|
||||
import 'package:wger/features/nutrition/models/nutritional_goals.dart';
|
||||
import 'package:wger/features/nutrition/models/nutritional_plan.dart';
|
||||
import 'package:wger/features/nutrition/models/nutritional_values.dart';
|
||||
@@ -80,14 +79,14 @@ class NutritionalDiaryTable extends StatelessWidget {
|
||||
) {
|
||||
return TableRow(
|
||||
decoration: BoxDecoration(
|
||||
border: Border(top: BorderSide(color: Colors.grey[300]!)),
|
||||
border: Border(top: BorderSide(color: Theme.of(context).colorScheme.outlineVariant)),
|
||||
),
|
||||
children:
|
||||
[
|
||||
Text(
|
||||
style: Theme.of(
|
||||
context,
|
||||
).textTheme.titleMedium?.copyWith(color: LIST_OF_COLORS3.first),
|
||||
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
),
|
||||
DateFormat.Md(Localizations.localeOf(context).languageCode).format(date),
|
||||
),
|
||||
Text(
|
||||
|
||||
@@ -111,7 +111,9 @@ class Log {
|
||||
|
||||
weight = setConfig.weight;
|
||||
weightTarget = setConfig.weight;
|
||||
weightUnitId = setConfig.weightUnitId ?? WEIGHT_UNIT_KG;
|
||||
// Fall back to the resolved unit object (set during routine hydration from
|
||||
// the user's metric preference) when the config carries no explicit unit.
|
||||
weightUnitId = setConfig.weightUnitId ?? setConfig.weightUnit?.id ?? WEIGHT_UNIT_KG;
|
||||
weightUnitObj = setConfig.weightUnit;
|
||||
|
||||
repetitions = setConfig.repetitions;
|
||||
|
||||
@@ -107,7 +107,7 @@ class SetConfigData {
|
||||
this.maxNrOfSets,
|
||||
this.weight,
|
||||
this.maxWeight,
|
||||
this.weightUnitId = WEIGHT_UNIT_KG,
|
||||
this.weightUnitId,
|
||||
this.weightRounding,
|
||||
this.repetitions,
|
||||
this.maxRepetitions,
|
||||
|
||||
@@ -40,7 +40,7 @@ SetConfigData _$SetConfigDataFromJson(Map<String, dynamic> json) {
|
||||
maxNrOfSets: json['max_sets'] as num?,
|
||||
weight: stringToNumNull(json['weight'] as String?),
|
||||
maxWeight: stringToNumNull(json['max_weight'] as String?),
|
||||
weightUnitId: (json['weight_unit'] as num?)?.toInt() ?? WEIGHT_UNIT_KG,
|
||||
weightUnitId: (json['weight_unit'] as num?)?.toInt(),
|
||||
weightRounding: stringToNumNull(json['weight_rounding'] as String?),
|
||||
repetitions: stringToNumNull(json['repetitions'] as String?),
|
||||
maxRepetitions: stringToNumNull(json['max_repetitions'] as String?),
|
||||
|
||||
@@ -130,6 +130,7 @@ class SlotEntry {
|
||||
@JsonKey(required: false, name: 'max_repetitions_configs', includeToJson: false)
|
||||
late List<BaseConfig> maxRepetitionsConfigs = [];
|
||||
|
||||
/// Null means no explicit unit; the user's profile default (kg/lb) applies.
|
||||
@JsonKey(required: true, name: 'weight_unit')
|
||||
late int? weightUnitId;
|
||||
|
||||
@@ -210,7 +211,7 @@ class SlotEntry {
|
||||
int? order,
|
||||
SlotEntryType? type,
|
||||
required Exercise exercise,
|
||||
int? weightUnitId,
|
||||
this.weightUnitId,
|
||||
this.weightRounding,
|
||||
int? repetitionUnitId,
|
||||
this.repetitionRounding,
|
||||
@@ -221,8 +222,6 @@ class SlotEntry {
|
||||
this.type = type ?? SlotEntryType.normal;
|
||||
exerciseObj = exercise;
|
||||
exerciseId = exercise.id;
|
||||
this.weightUnitId = weightUnitId ?? WEIGHT_UNIT_KG;
|
||||
|
||||
this.repetitionUnitId = repetitionUnitId ?? REP_UNIT_REPETITIONS_ID;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,13 +20,17 @@ import 'package:clock/clock.dart';
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:wger/core/consts.dart';
|
||||
import 'package:wger/core/shared_preferences.dart';
|
||||
import 'package:wger/features/account/providers/user_profile_notifier.dart';
|
||||
import 'package:wger/features/exercises/models/exercise.dart';
|
||||
import 'package:wger/features/routines/models/log.dart';
|
||||
import 'package:wger/features/routines/models/routine.dart';
|
||||
import 'package:wger/features/routines/models/set_config_data.dart';
|
||||
import 'package:wger/features/routines/models/weight_unit.dart';
|
||||
import 'package:wger/features/routines/providers/gym_log_notifier.dart';
|
||||
import 'package:wger/features/routines/providers/gym_state.dart';
|
||||
import 'package:wger/features/routines/providers/routines_notifier.dart';
|
||||
|
||||
part 'gym_state_notifier.g.dart';
|
||||
|
||||
@@ -431,6 +435,14 @@ class GymStateNotifier extends _$GymStateNotifier {
|
||||
String pageEntryUUID, {
|
||||
required Exercise newExercise,
|
||||
}) {
|
||||
// Ad-hoc set configs bypass routine hydration, so resolve the profile
|
||||
// default weight unit (kg/lb) here; the log draft picks it up from the
|
||||
// unit object.
|
||||
final profile = ref.read(userProfileProvider).value;
|
||||
final weightUnits = ref.read(routineWeightUnitProvider).value ?? const <WeightUnit>[];
|
||||
final defaultWeightUnitId = profile?.defaultWeightUnitId ?? WEIGHT_UNIT_KG;
|
||||
final defaultWeightUnit = weightUnits.firstWhereOrNull((u) => u.id == defaultWeightUnitId);
|
||||
|
||||
final List<PageEntry> pages = [];
|
||||
for (final page in state.pages) {
|
||||
pages.add(page);
|
||||
@@ -450,6 +462,7 @@ class GymStateNotifier extends _$GymStateNotifier {
|
||||
exerciseId: newExercise.id,
|
||||
exercise: newExercise,
|
||||
slotEntryId: setConfigData.slotEntryId,
|
||||
weightUnit: defaultWeightUnit,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -40,7 +40,7 @@ final class GymStateNotifierProvider extends $NotifierProvider<GymStateNotifier,
|
||||
}
|
||||
}
|
||||
|
||||
String _$gymStateNotifierHash() => r'53db98cc8dacabe415f9986e8fae3fa745965c99';
|
||||
String _$gymStateNotifierHash() => r'018852d495cd23fd0f765591a02b9369764c2161';
|
||||
|
||||
abstract class _$GymStateNotifier extends $Notifier<GymModeState> {
|
||||
GymModeState build();
|
||||
|
||||
@@ -19,7 +19,9 @@
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:wger/core/consts.dart';
|
||||
import 'package:wger/core/helpers.dart';
|
||||
import 'package:wger/features/account/providers/user_profile_notifier.dart';
|
||||
import 'package:wger/features/exercises/providers/exercises_notifier.dart';
|
||||
import 'package:wger/features/routines/models/day.dart';
|
||||
import 'package:wger/features/routines/models/day_data.dart';
|
||||
@@ -111,6 +113,9 @@ class RoutinesRiverpod extends _$RoutinesRiverpod {
|
||||
ref.listen(exercisesProvider, (_, _) => _rehydrate());
|
||||
ref.listen(routineRepetitionUnitProvider, (_, _) => _rehydrate());
|
||||
ref.listen(routineWeightUnitProvider, (_, _) => _rehydrate());
|
||||
// The default weight unit for set configs without an explicit one depends
|
||||
// on the user's metric preference, so re-hydrate when the profile arrives.
|
||||
ref.listen(userProfileProvider, (_, _) => _rehydrate());
|
||||
|
||||
return repo.watchAllDrift().map((freshRoutines) {
|
||||
final existing = state.value?.routines ?? const <Routine>[];
|
||||
@@ -140,6 +145,13 @@ class RoutinesRiverpod extends _$RoutinesRiverpod {
|
||||
final repetitionUnits =
|
||||
ref.read(routineRepetitionUnitProvider).value ?? const <RepetitionUnit>[];
|
||||
final weightUnits = ref.read(routineWeightUnitProvider).value ?? const <WeightUnit>[];
|
||||
final profile = ref.read(userProfileProvider).value;
|
||||
|
||||
// Used for slot entries and set configs that don't carry an explicit
|
||||
// weight unit. Defaults to kg while the profile is still syncing (the
|
||||
// profile listener re-hydrates once it arrives).
|
||||
final defaultWeightUnitId = profile?.defaultWeightUnitId ?? WEIGHT_UNIT_KG;
|
||||
final defaultWeightUnit = weightUnits.firstWhereOrNull((u) => u.id == defaultWeightUnitId);
|
||||
|
||||
routine.sessions = sessions.where((s) => s.routineId == routine.id).toList();
|
||||
|
||||
@@ -168,9 +180,9 @@ class RoutinesRiverpod extends _$RoutinesRiverpod {
|
||||
entry.repetitionUnitObj = repetitionUnits.firstWhereOrNull(
|
||||
(u) => u.id == entry.repetitionUnitId,
|
||||
);
|
||||
entry.weightUnitObj = weightUnits.firstWhereOrNull(
|
||||
(u) => u.id == entry.weightUnitId,
|
||||
);
|
||||
entry.weightUnitObj = entry.weightUnitId != null
|
||||
? weightUnits.firstWhereOrNull((u) => u.id == entry.weightUnitId)
|
||||
: defaultWeightUnit;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -189,9 +201,9 @@ class RoutinesRiverpod extends _$RoutinesRiverpod {
|
||||
setConfig.repetitionsUnit = repetitionUnits.firstWhereOrNull(
|
||||
(u) => u.id == setConfig.repetitionsUnitId,
|
||||
);
|
||||
setConfig.weightUnit = weightUnits.firstWhereOrNull(
|
||||
(u) => u.id == setConfig.weightUnitId,
|
||||
);
|
||||
setConfig.weightUnit = setConfig.weightUnitId != null
|
||||
? weightUnits.firstWhereOrNull((u) => u.id == setConfig.weightUnitId)
|
||||
: defaultWeightUnit;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -260,6 +272,7 @@ class RoutinesRiverpod extends _$RoutinesRiverpod {
|
||||
await ref.awaitFirstValue(routineRepetitionUnitProvider);
|
||||
await ref.awaitFirstValue(routineWeightUnitProvider);
|
||||
await ref.awaitFirstValue(workoutSessionProvider);
|
||||
await ref.awaitFirstValue(userProfileProvider);
|
||||
|
||||
final routine = await repo.fetchAndSetRoutineFullServer(routineId);
|
||||
_hydrateRoutine(routine);
|
||||
|
||||
@@ -111,7 +111,7 @@ final class RoutinesRiverpodProvider
|
||||
RoutinesRiverpod create() => RoutinesRiverpod();
|
||||
}
|
||||
|
||||
String _$routinesRiverpodHash() => r'32b35ad1f9f0caa96b4503bbb6c0e28c8bb8492c';
|
||||
String _$routinesRiverpodHash() => r'3f627206b93257ff84e54e6029a1e3dab6a43418';
|
||||
|
||||
abstract class _$RoutinesRiverpod extends $StreamNotifier<RoutinesState> {
|
||||
Stream<RoutinesState> build();
|
||||
|
||||
@@ -73,7 +73,10 @@ class _LogChartWidgetFlState extends State<LogChartWidgetFl> {
|
||||
}
|
||||
|
||||
LineChartData mainData() {
|
||||
final colors = generateChartColors(widget._data.keys.length).iterator;
|
||||
final colors = generateChartColors(
|
||||
widget._data.keys.length,
|
||||
Theme.of(context).colorScheme,
|
||||
).iterator;
|
||||
|
||||
return LineChartData(
|
||||
lineTouchData: tooltipData(),
|
||||
@@ -81,10 +84,10 @@ class _LogChartWidgetFlState extends State<LogChartWidgetFl> {
|
||||
show: true,
|
||||
drawVerticalLine: true,
|
||||
getDrawingHorizontalLine: (value) {
|
||||
return const FlLine(color: Colors.grey, strokeWidth: 1);
|
||||
return FlLine(color: Theme.of(context).colorScheme.outlineVariant, strokeWidth: 1);
|
||||
},
|
||||
getDrawingVerticalLine: (value) {
|
||||
return const FlLine(color: Colors.grey, strokeWidth: 1);
|
||||
return FlLine(color: Theme.of(context).colorScheme.outlineVariant, strokeWidth: 1);
|
||||
},
|
||||
),
|
||||
titlesData: FlTitlesData(
|
||||
@@ -136,11 +139,15 @@ class _LogChartWidgetFlState extends State<LogChartWidgetFl> {
|
||||
),
|
||||
borderData: FlBorderData(
|
||||
show: true,
|
||||
border: Border.all(color: const Color(0xff37434d)),
|
||||
border: Border.all(color: Theme.of(context).colorScheme.outlineVariant),
|
||||
),
|
||||
lineBarsData: [
|
||||
...widget._data.keys.map((reps) {
|
||||
colors.moveNext();
|
||||
// Captured: getDotPainter runs while painting, when the shared
|
||||
// iterator has already moved on to the last series.
|
||||
final color = colors.current;
|
||||
|
||||
return LineChartBarData(
|
||||
spots: [
|
||||
...widget._data[reps]!.map(
|
||||
@@ -151,14 +158,14 @@ class _LogChartWidgetFlState extends State<LogChartWidgetFl> {
|
||||
),
|
||||
],
|
||||
isCurved: true,
|
||||
color: colors.current,
|
||||
color: color,
|
||||
barWidth: 2,
|
||||
isStrokeCapRound: true,
|
||||
dotData: FlDotData(
|
||||
show: true,
|
||||
getDotPainter: (p0, p1, p2, p3) => FlDotCirclePainter(
|
||||
radius: 2,
|
||||
color: Colors.black,
|
||||
color: color,
|
||||
strokeWidth: 0,
|
||||
),
|
||||
),
|
||||
|
||||
@@ -225,10 +225,7 @@ class _SlotEntryFormState extends ConsumerState<SlotEntryForm> {
|
||||
if (!widget.simpleMode)
|
||||
WeightUnitInputWidget(
|
||||
widget.entry.weightUnitObj,
|
||||
onChanged: (value) {
|
||||
widget.entry.weightUnitObj = null;
|
||||
widget.entry.weightUnitId = null;
|
||||
},
|
||||
onChanged: (value) => widget.entry.weightUnit = value,
|
||||
),
|
||||
Row(
|
||||
spacing: 10,
|
||||
@@ -259,10 +256,7 @@ class _SlotEntryFormState extends ConsumerState<SlotEntryForm> {
|
||||
if (!widget.simpleMode)
|
||||
RepetitionUnitInputWidget(
|
||||
widget.entry.repetitionUnitObj,
|
||||
onChanged: (value) {
|
||||
widget.entry.repetitionUnitObj = null;
|
||||
widget.entry.repetitionUnitId = null;
|
||||
},
|
||||
onChanged: (value) => widget.entry.repetitionUnit = value,
|
||||
),
|
||||
Row(
|
||||
spacing: 10,
|
||||
|
||||
@@ -22,7 +22,6 @@ import 'package:wger/core/consts.dart';
|
||||
import 'package:wger/features/routines/providers/gym_state_notifier.dart';
|
||||
import 'package:wger/features/routines/widgets/gym_mode/elapsed_time.dart';
|
||||
import 'package:wger/features/routines/widgets/gym_mode/workout_menu.dart';
|
||||
import 'package:wger/theme/theme.dart';
|
||||
|
||||
class NavigationHeader extends StatelessWidget {
|
||||
final PageController _controller;
|
||||
@@ -116,7 +115,6 @@ class NavigationFooter extends ConsumerWidget {
|
||||
child: LinearProgressIndicator(
|
||||
minHeight: 3,
|
||||
value: gymState.ratioCompleted,
|
||||
valueColor: const AlwaysStoppedAnimation<Color>(wgerPrimaryColor),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -24,7 +24,6 @@ import 'package:intl/intl.dart';
|
||||
import 'package:wger/features/routines/providers/gym_state_notifier.dart';
|
||||
import 'package:wger/features/routines/widgets/gym_mode/navigation.dart';
|
||||
import 'package:wger/l10n/generated/app_localizations.dart';
|
||||
import 'package:wger/theme/theme.dart';
|
||||
|
||||
class TimerWidget extends StatefulWidget {
|
||||
final PageController _controller;
|
||||
@@ -75,7 +74,9 @@ class _TimerWidgetState extends State<TimerWidget> {
|
||||
child: Center(
|
||||
child: Text(
|
||||
DateFormat('m:ss').format(displayTime),
|
||||
style: Theme.of(context).textTheme.displayLarge!.copyWith(color: wgerPrimaryColor),
|
||||
style: Theme.of(
|
||||
context,
|
||||
).textTheme.displayLarge!.copyWith(color: Theme.of(context).colorScheme.primary),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -155,7 +156,9 @@ class _TimerCountdownWidgetState extends ConsumerState<TimerCountdownWidget> {
|
||||
children: [
|
||||
Text(
|
||||
DateFormat('m:ss').format(displayTime),
|
||||
style: Theme.of(context).textTheme.displayLarge!.copyWith(color: wgerPrimaryColor),
|
||||
style: Theme.of(
|
||||
context,
|
||||
).textTheme.displayLarge!.copyWith(color: Theme.of(context).colorScheme.primary),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
],
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:wger/core/colors.dart';
|
||||
import 'package:wger/core/misc.dart';
|
||||
import 'package:wger/features/measurements/widgets/charts.dart';
|
||||
@@ -30,7 +30,10 @@ class ExerciseLogChart extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final colors = generateChartColors(_logs.keys.length).iterator;
|
||||
final colors = generateChartColors(
|
||||
_logs.keys.length,
|
||||
Theme.of(context).colorScheme,
|
||||
).iterator;
|
||||
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:fl_chart/fl_chart.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:wger/core/colors.dart';
|
||||
import 'package:wger/features/routines/models/log.dart';
|
||||
import 'package:wger/l10n/generated/app_localizations.dart';
|
||||
|
||||
@@ -44,31 +45,12 @@ class MuscleGroupsCard extends StatelessWidget {
|
||||
}
|
||||
final muscleCounts = allMuscles.groupListsBy((muscle) => muscle.nameTranslated(context));
|
||||
final total = allMuscles.length;
|
||||
final colors = chartColorPalette(muscleCounts.length, Theme.of(context).colorScheme);
|
||||
|
||||
int colorIndex = 0;
|
||||
final colors = [
|
||||
Colors.blue,
|
||||
Colors.green,
|
||||
Colors.orange,
|
||||
Colors.purple,
|
||||
Colors.red,
|
||||
Colors.teal,
|
||||
Colors.deepOrange,
|
||||
Colors.indigo,
|
||||
Colors.pink,
|
||||
Colors.brown,
|
||||
Colors.cyan,
|
||||
Colors.lime,
|
||||
Colors.amber,
|
||||
Colors.lightGreen,
|
||||
Colors.deepPurple,
|
||||
];
|
||||
|
||||
return muscleCounts.entries.map((entry) {
|
||||
return muscleCounts.entries.mapIndexed((index, entry) {
|
||||
final percentage = (entry.value.length / total) * 100;
|
||||
final color = colors[colorIndex % colors.length];
|
||||
colorIndex++;
|
||||
return MuscleGroup(entry.key, percentage, color);
|
||||
|
||||
return MuscleGroup(entry.key, percentage, colors[index]);
|
||||
}).toList();
|
||||
}
|
||||
|
||||
@@ -102,7 +84,7 @@ class MuscleGroupsCard extends StatelessWidget {
|
||||
titleStyle: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: theme.colorScheme.onPrimary,
|
||||
color: onChartColor(muscle.color),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
|
||||
@@ -34,7 +34,9 @@ class PlateWeight extends StatelessWidget {
|
||||
alignment: Alignment.center,
|
||||
margin: EdgeInsets.all(margin),
|
||||
decoration: BoxDecoration(
|
||||
color: isSelected ? color : Colors.black12,
|
||||
// Selected shows the real plate color, so its rim and label stay
|
||||
// black whatever the theme. Unselected sits on the surface instead.
|
||||
color: isSelected ? color : Theme.of(context).colorScheme.surfaceContainerHighest,
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(color: Colors.black, width: isSelected ? 2 : 0),
|
||||
),
|
||||
@@ -44,7 +46,7 @@ class PlateWeight extends StatelessWidget {
|
||||
value.toString(),
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
color: isSelected ? Colors.black : Colors.black87,
|
||||
color: isSelected ? Colors.black : Theme.of(context).colorScheme.onSurfaceVariant,
|
||||
fontWeight: isSelected ? FontWeight.bold : FontWeight.normal,
|
||||
),
|
||||
),
|
||||
|
||||
@@ -1445,6 +1445,10 @@
|
||||
"darkMode": "Always dark mode",
|
||||
"lightMode": "Always light mode",
|
||||
"systemMode": "System settings",
|
||||
"useDynamicColor": "Use dynamic color",
|
||||
"@useDynamicColor": {
|
||||
"description": "Settings toggle to follow the system wallpaper colors (Material You) on supported platforms"
|
||||
},
|
||||
"youAreOffline": "You are offline",
|
||||
"appLanguage": "App language",
|
||||
"@appLanguage": {
|
||||
|
||||
157
lib/main.dart
@@ -18,6 +18,7 @@
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:dynamic_color/dynamic_color.dart';
|
||||
import 'package:extended_image/extended_image.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -71,6 +72,7 @@ import 'package:wger/features/routines/screens/routine_screen.dart';
|
||||
import 'package:wger/features/routines/screens/settings_plates_screen.dart';
|
||||
import 'package:wger/features/trophies/screens/trophy_screen.dart';
|
||||
import 'package:wger/l10n/generated/app_localizations.dart';
|
||||
import 'package:wger/theme/dynamic_color.dart';
|
||||
import 'package:wger/theme/theme.dart';
|
||||
|
||||
void _setupLogging() {
|
||||
@@ -187,67 +189,104 @@ class MainApp extends ConsumerWidget {
|
||||
// incoming deep links as a side effect of being read.
|
||||
ref.watch(appLinkRouterProvider);
|
||||
|
||||
return authAsync.when(
|
||||
loading: () => const MaterialApp(home: SplashScreen()),
|
||||
error: (error, stack) => MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: AutoLoginErrorScreen(error: error),
|
||||
),
|
||||
data: (authState) {
|
||||
final themeMode = ref.watch(
|
||||
appSettingsProvider.select((s) => s.value?.themeMode ?? ThemeMode.system),
|
||||
);
|
||||
final userLocale = ref.watch(
|
||||
appSettingsProvider.select((s) => s.value?.userLocale),
|
||||
);
|
||||
// Read before the builder below: its callback runs during the child's
|
||||
// build, where ref.watch would be out of phase.
|
||||
final themeMode = ref.watch(
|
||||
appSettingsProvider.select((s) => s.value?.themeMode ?? ThemeMode.system),
|
||||
);
|
||||
final userLocale = ref.watch(
|
||||
appSettingsProvider.select((s) => s.value?.userLocale),
|
||||
);
|
||||
final useDynamicColor = ref.watch(
|
||||
appSettingsProvider.select((s) => s.value?.useDynamicColor ?? USE_DYNAMIC_COLOR_DEFAULT),
|
||||
);
|
||||
|
||||
return MaterialApp(
|
||||
title: 'wger',
|
||||
navigatorKey: navigatorKey,
|
||||
scaffoldMessengerKey: scaffoldMessengerKey,
|
||||
theme: wgerLightTheme,
|
||||
darkTheme: wgerDarkTheme,
|
||||
highContrastTheme: wgerLightThemeHc,
|
||||
highContrastDarkTheme: wgerDarkThemeHc,
|
||||
themeMode: themeMode,
|
||||
locale: userLocale,
|
||||
home: _getHomeScreen(authState),
|
||||
routes: {
|
||||
DashboardScreen.routeName: (ctx) => const DashboardScreen(),
|
||||
FormScreen.routeName: (ctx) => const FormScreen(),
|
||||
GalleryScreen.routeName: (ctx) => const GalleryScreen(),
|
||||
GymModeScreen.routeName: (ctx) => const GymModeScreen(),
|
||||
HomeTabsScreen.routeName: (ctx) => const HomeTabsScreen(),
|
||||
MeasurementCategoriesScreen.routeName: (ctx) => const MeasurementCategoriesScreen(),
|
||||
MeasurementCategorySortScreen.routeName: (ctx) => const MeasurementCategorySortScreen(),
|
||||
MeasurementEntriesScreen.routeName: (ctx) => const MeasurementEntriesScreen(),
|
||||
NutritionalPlansScreen.routeName: (ctx) => const NutritionalPlansScreen(),
|
||||
NutritionalDiaryScreen.routeName: (ctx) => const NutritionalDiaryScreen(),
|
||||
NutritionalPlanScreen.routeName: (ctx) => const NutritionalPlanScreen(),
|
||||
IngredientDetailScreen.routeName: (ctx) => const IngredientDetailScreen(),
|
||||
IngredientsScreen.routeName: (ctx) => const IngredientsScreen(),
|
||||
LogMealsScreen.routeName: (ctx) => const LogMealsScreen(),
|
||||
LogMealScreen.routeName: (ctx) => const LogMealScreen(),
|
||||
WeightScreen.routeName: (ctx) => const WeightScreen(),
|
||||
RoutineScreen.routeName: (ctx) => const RoutineScreen(),
|
||||
RoutineEditScreen.routeName: (ctx) => const RoutineEditScreen(),
|
||||
WorkoutLogsScreen.routeName: (ctx) => const WorkoutLogsScreen(),
|
||||
RoutineListScreen.routeName: (ctx) => const RoutineListScreen(),
|
||||
ExercisesScreen.routeName: (ctx) => const ExercisesScreen(),
|
||||
ExerciseDetailScreen.routeName: (ctx) => const ExerciseDetailScreen(),
|
||||
AddExerciseScreen.routeName: (ctx) => const AddExerciseScreen(),
|
||||
AboutPage.routeName: (ctx) => const AboutPage(),
|
||||
SettingsPage.routeName: (ctx) => const SettingsPage(),
|
||||
LogOverviewPage.routeName: (ctx) => const LogOverviewPage(),
|
||||
ConfigurePlatesScreen.routeName: (ctx) => const ConfigurePlatesScreen(),
|
||||
ConfigureDashboardWidgetsScreen.routeName: (ctx) =>
|
||||
const ConfigureDashboardWidgetsScreen(),
|
||||
TrophyScreen.routeName: (ctx) => const TrophyScreen(),
|
||||
// Above the auth switch so the platform call is already in flight while the
|
||||
// splash screen is up. Below it, the first frame after login renders the
|
||||
// fixed palette and then repaints.
|
||||
return DynamicColorBuilder(
|
||||
builder: (lightDynamic, darkDynamic) {
|
||||
final seed = appThemeSeed(
|
||||
useDynamicColor: useDynamicColor,
|
||||
lightDynamic: lightDynamic,
|
||||
darkDynamic: darkDynamic,
|
||||
);
|
||||
final light = seed == null ? wgerLightTheme : wgerThemeFromSeed(seed, Brightness.light);
|
||||
final dark = seed == null ? wgerDarkTheme : wgerThemeFromSeed(seed, Brightness.dark);
|
||||
// The OS accessibility setting swaps to these, so they follow the seed
|
||||
// too rather than dropping back to the fixed palette.
|
||||
final lightHc = seed == null
|
||||
? wgerLightThemeHc
|
||||
: wgerThemeFromSeed(seed, Brightness.light, highContrast: true);
|
||||
final darkHc = seed == null
|
||||
? wgerDarkThemeHc
|
||||
: wgerThemeFromSeed(seed, Brightness.dark, highContrast: true);
|
||||
|
||||
return authAsync.when(
|
||||
loading: () => MaterialApp(
|
||||
theme: light,
|
||||
darkTheme: dark,
|
||||
themeMode: themeMode,
|
||||
home: const SplashScreen(),
|
||||
),
|
||||
error: (error, stack) => MaterialApp(
|
||||
theme: light,
|
||||
darkTheme: dark,
|
||||
themeMode: themeMode,
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: AutoLoginErrorScreen(error: error),
|
||||
),
|
||||
data: (authState) {
|
||||
return MaterialApp(
|
||||
title: 'wger',
|
||||
navigatorKey: navigatorKey,
|
||||
scaffoldMessengerKey: scaffoldMessengerKey,
|
||||
theme: light,
|
||||
darkTheme: dark,
|
||||
highContrastTheme: lightHc,
|
||||
highContrastDarkTheme: darkHc,
|
||||
themeMode: themeMode,
|
||||
locale: userLocale,
|
||||
home: _getHomeScreen(authState),
|
||||
routes: {
|
||||
DashboardScreen.routeName: (ctx) => const DashboardScreen(),
|
||||
FormScreen.routeName: (ctx) => const FormScreen(),
|
||||
GalleryScreen.routeName: (ctx) => const GalleryScreen(),
|
||||
GymModeScreen.routeName: (ctx) => const GymModeScreen(),
|
||||
HomeTabsScreen.routeName: (ctx) => const HomeTabsScreen(),
|
||||
MeasurementCategoriesScreen.routeName: (ctx) => const MeasurementCategoriesScreen(),
|
||||
MeasurementCategorySortScreen.routeName: (ctx) =>
|
||||
const MeasurementCategorySortScreen(),
|
||||
MeasurementEntriesScreen.routeName: (ctx) => const MeasurementEntriesScreen(),
|
||||
NutritionalPlansScreen.routeName: (ctx) => const NutritionalPlansScreen(),
|
||||
NutritionalDiaryScreen.routeName: (ctx) => const NutritionalDiaryScreen(),
|
||||
NutritionalPlanScreen.routeName: (ctx) => const NutritionalPlanScreen(),
|
||||
IngredientDetailScreen.routeName: (ctx) => const IngredientDetailScreen(),
|
||||
IngredientsScreen.routeName: (ctx) => const IngredientsScreen(),
|
||||
LogMealsScreen.routeName: (ctx) => const LogMealsScreen(),
|
||||
LogMealScreen.routeName: (ctx) => const LogMealScreen(),
|
||||
WeightScreen.routeName: (ctx) => const WeightScreen(),
|
||||
RoutineScreen.routeName: (ctx) => const RoutineScreen(),
|
||||
RoutineEditScreen.routeName: (ctx) => const RoutineEditScreen(),
|
||||
WorkoutLogsScreen.routeName: (ctx) => const WorkoutLogsScreen(),
|
||||
RoutineListScreen.routeName: (ctx) => const RoutineListScreen(),
|
||||
ExercisesScreen.routeName: (ctx) => const ExercisesScreen(),
|
||||
ExerciseDetailScreen.routeName: (ctx) => const ExerciseDetailScreen(),
|
||||
AddExerciseScreen.routeName: (ctx) => const AddExerciseScreen(),
|
||||
AboutPage.routeName: (ctx) => const AboutPage(),
|
||||
SettingsPage.routeName: (ctx) => const SettingsPage(),
|
||||
LogOverviewPage.routeName: (ctx) => const LogOverviewPage(),
|
||||
ConfigurePlatesScreen.routeName: (ctx) => const ConfigurePlatesScreen(),
|
||||
ConfigureDashboardWidgetsScreen.routeName: (ctx) =>
|
||||
const ConfigureDashboardWidgetsScreen(),
|
||||
TrophyScreen.routeName: (ctx) => const TrophyScreen(),
|
||||
},
|
||||
localeListResolutionCallback: resolveLocale,
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
);
|
||||
},
|
||||
localeListResolutionCallback: resolveLocale,
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
57
lib/theme/dynamic_color.dart
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* This file is part of wger Workout Manager <https://github.com/wger-project>.
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import 'package:dynamic_color/dynamic_color.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
/// Whether the platform can supply a dynamic color palette.
|
||||
///
|
||||
/// True on Android 12+, which exposes a wallpaper palette, and on macOS,
|
||||
/// Windows and GTK-based Linux, which expose a system accent color. False
|
||||
/// everywhere else, including iOS, the web and Android below 12, where the
|
||||
/// dynamic color setting would be a silent no-op.
|
||||
final dynamicColorAvailableProvider = FutureProvider<bool>((ref) async {
|
||||
try {
|
||||
if (await DynamicColorPlugin.getCorePalette() != null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return await DynamicColorPlugin.getAccentColor() != null;
|
||||
} on PlatformException {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
/// The color to seed the app themes from, or null to keep the fixed palette.
|
||||
///
|
||||
/// Null whenever the setting is off or the platform returned nothing. A single
|
||||
/// seed drives both brightnesses: re-tonalising normalises the hue, so it does
|
||||
/// not matter which of the two platform schemes it is taken from.
|
||||
Color? appThemeSeed({
|
||||
required bool useDynamicColor,
|
||||
required ColorScheme? lightDynamic,
|
||||
required ColorScheme? darkDynamic,
|
||||
}) {
|
||||
if (!useDynamicColor) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (lightDynamic ?? darkDynamic)?.primary;
|
||||
}
|
||||
@@ -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.
|
||||
@@ -151,7 +151,41 @@ final wgerDarkThemeHc = FlexThemeData.dark(
|
||||
textTheme: wgerTextTheme,
|
||||
);
|
||||
|
||||
/// Builds a wger theme for [brightness] with the palette generated from [seed],
|
||||
/// e.g. the platform's dynamic color. Sub-themes, app bar style and typography
|
||||
/// match the fixed themes, so only the hues change.
|
||||
///
|
||||
/// With [highContrast] the palette is spread over a wider tonal range, matching
|
||||
/// the fixed high contrast themes the OS accessibility setting switches to.
|
||||
ThemeData wgerThemeFromSeed(
|
||||
Color seed,
|
||||
Brightness brightness, {
|
||||
bool highContrast = false,
|
||||
}) {
|
||||
final isDark = brightness == Brightness.dark;
|
||||
return (isDark ? FlexThemeData.dark : FlexThemeData.light)(
|
||||
colorScheme: SeedColorScheme.fromSeeds(
|
||||
primaryKey: seed,
|
||||
brightness: brightness,
|
||||
tones: highContrast ? FlexTones.ultraContrast(brightness) : FlexTones.vivid(brightness),
|
||||
),
|
||||
useMaterial3: true,
|
||||
appBarStyle: isDark ? null : FlexAppBarStyle.primary,
|
||||
subThemesData: wgerSubThemeData,
|
||||
textTheme: wgerTextTheme,
|
||||
);
|
||||
}
|
||||
|
||||
CalendarStyle getWgerCalendarStyle(ThemeData theme) {
|
||||
final scheme = theme.colorScheme;
|
||||
final selectedDecoration = BoxDecoration(
|
||||
color: scheme.secondary,
|
||||
shape: BoxShape.circle,
|
||||
);
|
||||
// table_calendar defaults these to a near-white that only works on a dark
|
||||
// circle, and secondary is light in dark mode.
|
||||
final selectedTextStyle = TextStyle(color: scheme.onSecondary, fontSize: 16);
|
||||
|
||||
return CalendarStyle(
|
||||
outsideDaysVisible: false,
|
||||
todayDecoration: const BoxDecoration(
|
||||
@@ -162,19 +196,13 @@ CalendarStyle getWgerCalendarStyle(ThemeData theme) {
|
||||
color: theme.textTheme.headlineLarge?.color,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
selectedDecoration: const BoxDecoration(
|
||||
color: wgerSecondaryColor,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
rangeStartDecoration: const BoxDecoration(
|
||||
color: wgerSecondaryColor,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
rangeEndDecoration: const BoxDecoration(
|
||||
color: wgerSecondaryColor,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
rangeHighlightColor: wgerSecondaryColorLight,
|
||||
weekendTextStyle: const TextStyle(color: wgerSecondaryColor),
|
||||
selectedDecoration: selectedDecoration,
|
||||
selectedTextStyle: selectedTextStyle,
|
||||
rangeStartDecoration: selectedDecoration,
|
||||
rangeStartTextStyle: selectedTextStyle,
|
||||
rangeEndDecoration: selectedDecoration,
|
||||
rangeEndTextStyle: selectedTextStyle,
|
||||
rangeHighlightColor: scheme.secondaryContainer,
|
||||
weekendTextStyle: TextStyle(color: scheme.secondary),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -6,12 +6,16 @@
|
||||
|
||||
#include "generated_plugin_registrant.h"
|
||||
|
||||
#include <dynamic_color/dynamic_color_plugin.h>
|
||||
#include <file_selector_linux/file_selector_plugin.h>
|
||||
#include <flutter_secure_storage_linux/flutter_secure_storage_linux_plugin.h>
|
||||
#include <gtk/gtk_plugin.h>
|
||||
#include <url_launcher_linux/url_launcher_plugin.h>
|
||||
|
||||
void fl_register_plugins(FlPluginRegistry* registry) {
|
||||
g_autoptr(FlPluginRegistrar) dynamic_color_registrar =
|
||||
fl_plugin_registry_get_registrar_for_plugin(registry, "DynamicColorPlugin");
|
||||
dynamic_color_plugin_register_with_registrar(dynamic_color_registrar);
|
||||
g_autoptr(FlPluginRegistrar) file_selector_linux_registrar =
|
||||
fl_plugin_registry_get_registrar_for_plugin(registry, "FileSelectorPlugin");
|
||||
file_selector_plugin_register_with_registrar(file_selector_linux_registrar);
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#
|
||||
|
||||
list(APPEND FLUTTER_PLUGIN_LIST
|
||||
dynamic_color
|
||||
file_selector_linux
|
||||
flutter_secure_storage_linux
|
||||
gtk
|
||||
|
||||
@@ -8,6 +8,7 @@ import Foundation
|
||||
import app_links
|
||||
import connectivity_plus
|
||||
import device_info_plus
|
||||
import dynamic_color
|
||||
import file_selector_macos
|
||||
import flutter_secure_storage_darwin
|
||||
import package_info_plus
|
||||
@@ -19,6 +20,7 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
|
||||
AppLinksMacosPlugin.register(with: registry.registrar(forPlugin: "AppLinksMacosPlugin"))
|
||||
ConnectivityPlusPlugin.register(with: registry.registrar(forPlugin: "ConnectivityPlusPlugin"))
|
||||
DeviceInfoPlusMacosPlugin.register(with: registry.registrar(forPlugin: "DeviceInfoPlusMacosPlugin"))
|
||||
DynamicColorPlugin.register(with: registry.registrar(forPlugin: "DynamicColorPlugin"))
|
||||
FileSelectorPlugin.register(with: registry.registrar(forPlugin: "FileSelectorPlugin"))
|
||||
FlutterSecureStorageDarwinPlugin.register(with: registry.registrar(forPlugin: "FlutterSecureStorageDarwinPlugin"))
|
||||
FPPPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FPPPackageInfoPlusPlugin"))
|
||||
|
||||
24
pubspec.lock
@@ -381,10 +381,10 @@ packages:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: drift
|
||||
sha256: "84688491040b0ceb26575709a84d701c84ad4df4d8aff020adf6d85f155fb0dd"
|
||||
sha256: "3a3f1f6f905037d7426e4c445854139fd6a3d592135f7c96d7931682b73d16f4"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.34.2"
|
||||
version: "2.34.3"
|
||||
drift_dev:
|
||||
dependency: "direct dev"
|
||||
description:
|
||||
@@ -401,6 +401,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.3.1"
|
||||
dynamic_color:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: dynamic_color
|
||||
sha256: "43a5a6679649a7731ab860334a5812f2067c2d9ce6452cf069c5e0c25336c17c"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.8.1"
|
||||
equatable:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@@ -413,10 +421,10 @@ packages:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: extended_image
|
||||
sha256: f6cbb1d798f51262ed1a3d93b4f1f2aa0d76128df39af18ecb77fa740f88b2e0
|
||||
sha256: e81d801cd692921f152834e01f39bba8b3d6302c48ad420d499c6062a7e24737
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "10.0.1"
|
||||
version: "10.1.0"
|
||||
extended_image_library:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -921,10 +929,10 @@ packages:
|
||||
dependency: "direct dev"
|
||||
description:
|
||||
name: json_serializable
|
||||
sha256: ffcd10cde35a93b2abbbcc26bd9971f4ca93763e8abe78d855e3c4177797e501
|
||||
sha256: e45aefa0324f08c683caafbb94b72837aa6193c61822799c916e45f4a263113d
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "6.14.0"
|
||||
version: "6.14.1"
|
||||
leak_tracker:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -1209,10 +1217,10 @@ packages:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: powersync
|
||||
sha256: "11a43bd499ad9fe8b573e93a0f2702fe695f4f3c3d20c40306468c7d985a90ae"
|
||||
sha256: "0cd58b2fb4b2eec9b2952647c25b05801ec36cdd3f6ea0763c8f76e53345c18b"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.3.2"
|
||||
version: "2.3.3"
|
||||
powersync_flutter_libs:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
||||
@@ -37,9 +37,10 @@ dependencies:
|
||||
clock: ^1.1.2
|
||||
collection: ^1.19.1
|
||||
cupertino_icons: ^1.0.9
|
||||
drift: ^2.34.2
|
||||
drift: ^2.34.3
|
||||
dynamic_color: ^1.8.1
|
||||
equatable: ^2.1.0
|
||||
extended_image: ^10.0.1
|
||||
extended_image: ^10.1.0
|
||||
fl_chart: ^1.2.0
|
||||
flex_color_scheme: ^8.4.0
|
||||
flutter_html: ^3.0.0
|
||||
@@ -81,7 +82,7 @@ dependencies:
|
||||
stream_transform: ^2.1.1
|
||||
state_notifier: ^1.0.0
|
||||
connectivity_plus: ^7.3.1
|
||||
powersync: ^2.3.2
|
||||
powersync: ^2.3.3
|
||||
|
||||
dependency_overrides:
|
||||
# health -> device_info_plus ^12.1.0 pins win32 5.x, which conflicts with
|
||||
@@ -106,7 +107,7 @@ dev_dependencies:
|
||||
flutter_lints: ^6.0.0
|
||||
flutter_native_splash: ^2.4.8
|
||||
freezed: ^3.2.0
|
||||
json_serializable: ^6.14.0
|
||||
json_serializable: ^6.14.1
|
||||
mockito: ^5.6.4
|
||||
network_image_mock: ^2.1.1
|
||||
plugin_platform_interface: ^2.1.8
|
||||
|
||||
@@ -359,4 +359,41 @@ void main() {
|
||||
expect(await prefs.getBool(PREFS_ALLOW_SELF_SIGNED_CERTS), true);
|
||||
});
|
||||
});
|
||||
|
||||
group('use dynamic color', () {
|
||||
test('defaults to false', () async {
|
||||
final settings = await container.read(appSettingsProvider.future);
|
||||
expect(settings.useDynamicColor, false);
|
||||
});
|
||||
|
||||
test('loads true from prefs', () async {
|
||||
SharedPreferencesAsyncPlatform.instance = InMemorySharedPreferencesAsync.empty();
|
||||
final prefs = SharedPreferencesAsync();
|
||||
await prefs.setBool(PREFS_USE_DYNAMIC_COLOR, true);
|
||||
|
||||
container.dispose();
|
||||
container = ProviderContainer(
|
||||
overrides: [appSettingsPrefsProvider.overrideWithValue(prefs)],
|
||||
);
|
||||
|
||||
final settings = await container.read(appSettingsProvider.future);
|
||||
expect(settings.useDynamicColor, true);
|
||||
});
|
||||
|
||||
test('setUseDynamicColor persists the toggle', () async {
|
||||
SharedPreferencesAsyncPlatform.instance = InMemorySharedPreferencesAsync.empty();
|
||||
final prefs = SharedPreferencesAsync();
|
||||
|
||||
container.dispose();
|
||||
container = ProviderContainer(
|
||||
overrides: [appSettingsPrefsProvider.overrideWithValue(prefs)],
|
||||
);
|
||||
|
||||
await container.read(appSettingsProvider.future);
|
||||
await container.read(appSettingsProvider.notifier).setUseDynamicColor(true);
|
||||
|
||||
expect(container.read(appSettingsProvider).requireValue.useDynamicColor, true);
|
||||
expect(await prefs.getBool(PREFS_USE_DYNAMIC_COLOR), true);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -16,91 +16,139 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import 'package:flex_color_scheme/flex_color_scheme.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:wger/core/colors.dart';
|
||||
import 'package:wger/theme/theme.dart';
|
||||
|
||||
void main() {
|
||||
final light = wgerLightTheme.colorScheme;
|
||||
final dark = wgerDarkTheme.colorScheme;
|
||||
|
||||
double hueOf(Color c) => Hct.fromInt(c.toARGB32()).hue;
|
||||
double toneOf(Color c) => Hct.fromInt(c.toARGB32()).tone;
|
||||
|
||||
group('chartColorPalette', () {
|
||||
test('returns as many colors as requested', () {
|
||||
for (final count in [1, 3, 5, 8, 15]) {
|
||||
expect(chartColorPalette(count, light), hasLength(count));
|
||||
}
|
||||
});
|
||||
|
||||
test('falls back to a single color for zero or negative counts', () {
|
||||
expect(chartColorPalette(0, light), hasLength(1));
|
||||
expect(chartColorPalette(-5, light), hasLength(1));
|
||||
});
|
||||
|
||||
test('starts at the scheme primary hue', () {
|
||||
expect(
|
||||
hueOf(chartColorPalette(5, light).first),
|
||||
closeTo(hueOf(light.primary), 1),
|
||||
);
|
||||
});
|
||||
|
||||
test('spreads the hues evenly around the wheel', () {
|
||||
for (final count in [3, 6]) {
|
||||
final hues = chartColorPalette(count, light).map(hueOf).toList();
|
||||
|
||||
for (var i = 1; i < count; i++) {
|
||||
final delta = (hues[i] - hues[i - 1] + 360) % 360;
|
||||
expect(delta, closeTo(360 / count, 2), reason: 'uneven step at n=$count');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test('yields distinct colors', () {
|
||||
expect(chartColorPalette(8, light).toSet(), hasLength(8));
|
||||
});
|
||||
|
||||
test('ramps the tone across the palette', () {
|
||||
for (final scheme in [light, dark]) {
|
||||
final tones = chartColorPalette(5, scheme).map(toneOf).toList();
|
||||
|
||||
for (var i = 1; i < tones.length; i++) {
|
||||
expect(tones[i], greaterThan(tones[i - 1]));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test('keeps the dark palette light enough for a dark surface', () {
|
||||
// The old fixed palette was tuned for light backgrounds only.
|
||||
expect(chartColorPalette(6, dark).every((c) => toneOf(c) >= 55), isTrue);
|
||||
});
|
||||
});
|
||||
|
||||
group('onChartColor', () {
|
||||
double contrast(Color a, Color b) {
|
||||
final values = [a.computeLuminance(), b.computeLuminance()]..sort();
|
||||
|
||||
return (values.last + 0.05) / (values.first + 0.05);
|
||||
}
|
||||
|
||||
test('switches between white and black along the tone ramp', () {
|
||||
expect(
|
||||
chartColorPalette(6, light).map(onChartColor).toSet(),
|
||||
containsAll(<Color>[Colors.white, Colors.black]),
|
||||
);
|
||||
});
|
||||
|
||||
test('always picks the higher-contrast option', () {
|
||||
final colors = [
|
||||
...chartColorPalette(8, light),
|
||||
...chartColorPalette(8, dark),
|
||||
COLOR_SURPLUS,
|
||||
Colors.white,
|
||||
Colors.black,
|
||||
];
|
||||
|
||||
for (final color in colors) {
|
||||
final picked = onChartColor(color);
|
||||
final other = picked == Colors.black ? Colors.white : Colors.black;
|
||||
expect(
|
||||
contrast(color, picked),
|
||||
greaterThanOrEqualTo(contrast(color, other)),
|
||||
reason: 'wrong pick for $color',
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test('clears 4.5:1 on the generated palette', () {
|
||||
for (final scheme in [light, dark]) {
|
||||
for (final color in chartColorPalette(8, scheme)) {
|
||||
expect(contrast(color, onChartColor(color)), greaterThan(4.5));
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
group('generateChartColors', () {
|
||||
test('should generate 3 colors for 3 items', () {
|
||||
final iterator = generateChartColors(3).iterator;
|
||||
final expectedColors = LIST_OF_COLORS3.iterator;
|
||||
test('yields the palette in order', () {
|
||||
final palette = chartColorPalette(5, light);
|
||||
final iterator = generateChartColors(5, light).iterator;
|
||||
|
||||
while (expectedColors.moveNext()) {
|
||||
for (final expected in palette) {
|
||||
expect(iterator.moveNext(), isTrue);
|
||||
expect(iterator.current, equals(expectedColors.current));
|
||||
}
|
||||
|
||||
expect(iterator.moveNext(), isTrue);
|
||||
expect(iterator.current, equals(Colors.black));
|
||||
});
|
||||
|
||||
test('should generate 5 colors for 5 items', () {
|
||||
final iterator = generateChartColors(5).iterator;
|
||||
final expectedColors = LIST_OF_COLORS5.iterator;
|
||||
|
||||
while (expectedColors.moveNext()) {
|
||||
expect(iterator.moveNext(), isTrue);
|
||||
expect(iterator.current, equals(expectedColors.current));
|
||||
}
|
||||
|
||||
expect(iterator.moveNext(), isTrue);
|
||||
expect(iterator.current, equals(Colors.black));
|
||||
});
|
||||
|
||||
test('should generate 8 colors for 8 items', () {
|
||||
final iterator = generateChartColors(8).iterator;
|
||||
final expectedColors = LIST_OF_COLORS8.iterator;
|
||||
|
||||
while (expectedColors.moveNext()) {
|
||||
expect(iterator.moveNext(), isTrue);
|
||||
expect(iterator.current, equals(expectedColors.current));
|
||||
}
|
||||
|
||||
expect(iterator.moveNext(), isTrue);
|
||||
expect(iterator.current, equals(Colors.black));
|
||||
});
|
||||
|
||||
test('should generate surplus color for more than 8 items', () {
|
||||
final iterator = generateChartColors(10).iterator;
|
||||
final expectedColors = LIST_OF_COLORS8.iterator;
|
||||
|
||||
while (expectedColors.moveNext()) {
|
||||
expect(iterator.moveNext(), isTrue);
|
||||
expect(iterator.current, equals(expectedColors.current));
|
||||
}
|
||||
|
||||
// After exhausting the 8 colors, it should always return black
|
||||
for (int i = 0; i < 12; i++) {
|
||||
expect(iterator.moveNext(), isTrue);
|
||||
expect(iterator.current, equals(Colors.black));
|
||||
expect(iterator.current, equals(expected));
|
||||
}
|
||||
});
|
||||
|
||||
test('should generate 3 colors for 0 items', () {
|
||||
final iterator = generateChartColors(0).iterator;
|
||||
final expectedColors = LIST_OF_COLORS3.iterator;
|
||||
test('repeats instead of running out or falling back to black', () {
|
||||
final palette = chartColorPalette(3, light);
|
||||
final iterator = generateChartColors(3, light).iterator;
|
||||
|
||||
while (expectedColors.moveNext()) {
|
||||
for (var i = 0; i < 12; i++) {
|
||||
expect(iterator.moveNext(), isTrue);
|
||||
expect(iterator.current, equals(expectedColors.current));
|
||||
expect(iterator.current, equals(palette[i % palette.length]));
|
||||
expect(iterator.current, isNot(equals(Colors.black)));
|
||||
}
|
||||
|
||||
expect(iterator.moveNext(), isTrue);
|
||||
expect(iterator.current, equals(Colors.black));
|
||||
});
|
||||
|
||||
test('should generate 3 colors for negative number of items', () {
|
||||
final iterator = generateChartColors(-5).iterator;
|
||||
final expectedColors = LIST_OF_COLORS3.iterator;
|
||||
|
||||
while (expectedColors.moveNext()) {
|
||||
expect(iterator.moveNext(), isTrue);
|
||||
expect(iterator.current, equals(expectedColors.current));
|
||||
}
|
||||
test('keeps yielding for zero items', () {
|
||||
final iterator = generateChartColors(0, light).iterator;
|
||||
|
||||
expect(iterator.moveNext(), isTrue);
|
||||
expect(iterator.current, equals(Colors.black));
|
||||
expect(iterator.moveNext(), isTrue);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import 'package:wger/features/account/widgets/settings.dart';
|
||||
import 'package:wger/features/health/providers/health_repository.dart';
|
||||
import 'package:wger/features/health/providers/health_sync.dart';
|
||||
import 'package:wger/l10n/generated/app_localizations.dart';
|
||||
import 'package:wger/theme/dynamic_color.dart';
|
||||
|
||||
import 'settings_test.mocks.dart';
|
||||
|
||||
@@ -64,11 +65,14 @@ void main() {
|
||||
).thenAnswer((_) async {});
|
||||
});
|
||||
|
||||
Widget createSettingsScreen({locale = 'en'}) {
|
||||
Widget createSettingsScreen({locale = 'en', bool dynamicColorAvailable = true}) {
|
||||
return riverpod.ProviderScope(
|
||||
overrides: [
|
||||
appSettingsPrefsProvider.overrideWithValue(mockSharedPreferences),
|
||||
healthSyncProvider.overrideWith(_FakeHealthSyncNotifier.new),
|
||||
// The plugin has no test implementation and would report the toggle as
|
||||
// unsupported, which hides it.
|
||||
dynamicColorAvailableProvider.overrideWith((ref) async => dynamicColorAvailable),
|
||||
],
|
||||
child: MaterialApp(
|
||||
locale: Locale(locale),
|
||||
@@ -90,6 +94,38 @@ void main() {
|
||||
|
||||
verify(mockSharedPreferences.setBool(PREFS_USER_DARK_THEME, false)).called(1);
|
||||
});
|
||||
|
||||
testWidgets('toggling dynamic color persists the preference', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(createSettingsScreen());
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.tap(find.byKey(const ValueKey('useDynamicColorSwitch')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
verify(mockSharedPreferences.setBool(PREFS_USE_DYNAMIC_COLOR, true)).called(1);
|
||||
});
|
||||
|
||||
testWidgets('dynamic color switch reflects a stored preference', (WidgetTester tester) async {
|
||||
when(mockSharedPreferences.getBool(PREFS_USE_DYNAMIC_COLOR)).thenAnswer((_) async => true);
|
||||
|
||||
await tester.pumpWidget(createSettingsScreen());
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final switchWidget = tester.widget<SwitchListTile>(
|
||||
find.byKey(const ValueKey('useDynamicColorSwitch')),
|
||||
);
|
||||
expect(switchWidget.value, true);
|
||||
});
|
||||
|
||||
testWidgets('dynamic color switch is hidden where the platform has none', (
|
||||
WidgetTester tester,
|
||||
) async {
|
||||
await tester.pumpWidget(createSettingsScreen(dynamicColorAvailable: false));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byKey(const ValueKey('useDynamicColorSwitch')), findsNothing);
|
||||
expect(find.byKey(const ValueKey('themeModeDropdown')), findsOneWidget);
|
||||
});
|
||||
});
|
||||
|
||||
group('Language switcher', () {
|
||||
|
||||
|
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 20 KiB |
|
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 19 KiB |
|
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 20 KiB |
@@ -19,6 +19,7 @@
|
||||
import 'package:flutter_riverpod/misc.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:wger/features/account/providers/user_profile_repository.dart';
|
||||
import 'package:wger/features/exercises/models/exercise.dart';
|
||||
import 'package:wger/features/exercises/providers/exercise_repository.dart';
|
||||
import 'package:wger/features/exercises/providers/exercises_notifier.dart';
|
||||
@@ -31,9 +32,9 @@ import 'package:wger/features/routines/providers/workout_session_repository.dart
|
||||
import 'routine_form_test_overrides.mocks.dart';
|
||||
|
||||
export 'routine_form_test_overrides.mocks.dart'
|
||||
show MockExerciseRepository, MockWorkoutSessionRepository;
|
||||
show MockExerciseRepository, MockWorkoutSessionRepository, MockUserProfileRepository;
|
||||
|
||||
@GenerateMocks([ExerciseRepository, WorkoutSessionRepository])
|
||||
@GenerateMocks([ExerciseRepository, WorkoutSessionRepository, UserProfileRepository])
|
||||
/// Repository overrides for the two reference-data notifiers that
|
||||
/// `RoutinesRiverpod.fetchAndSetRoutineFull` `awaitFirstValue`s on:
|
||||
/// `exercisesProvider` and `workoutSessionProvider`. Both notifiers read
|
||||
@@ -46,15 +47,27 @@ export 'routine_form_test_overrides.mocks.dart'
|
||||
List<Override> exerciseAndSessionRepoOverrides({
|
||||
MockExerciseRepository? exercise,
|
||||
MockWorkoutSessionRepository? session,
|
||||
MockUserProfileRepository? userProfile,
|
||||
}) {
|
||||
final exerciseRepo = exercise ?? _emptyExerciseRepoMock();
|
||||
final sessionRepo = session ?? _emptySessionRepoMock();
|
||||
return [
|
||||
exerciseRepositoryProvider.overrideWithValue(exerciseRepo),
|
||||
workoutSessionRepositoryProvider.overrideWithValue(sessionRepo),
|
||||
// RoutinesRiverpod.build listens to the user profile to pick the default
|
||||
// weight unit; stub it so the real Drift-backed repo isn't pulled in.
|
||||
// Defaults to a null (metric) profile; pass [userProfile] to exercise the
|
||||
// imperial default-unit path.
|
||||
userProfileRepositoryProvider.overrideWithValue(userProfile ?? _emptyUserProfileRepoMock()),
|
||||
];
|
||||
}
|
||||
|
||||
MockUserProfileRepository _emptyUserProfileRepoMock() {
|
||||
final mock = MockUserProfileRepository();
|
||||
when(mock.watchDrift()).thenAnswer((_) => Stream.value(null));
|
||||
return mock;
|
||||
}
|
||||
|
||||
MockExerciseRepository _emptyExerciseRepoMock() {
|
||||
final mock = MockExerciseRepository();
|
||||
when(
|
||||
@@ -80,10 +93,15 @@ MockWorkoutSessionRepository _emptySessionRepoMock() {
|
||||
List<Override> routineFormAmbientOverrides({
|
||||
MockExerciseRepository? exercise,
|
||||
MockWorkoutSessionRepository? session,
|
||||
MockUserProfileRepository? userProfile,
|
||||
List<RepetitionUnit> repetitionUnits = const [],
|
||||
List<WeightUnit> weightUnits = const [],
|
||||
}) => [
|
||||
...exerciseAndSessionRepoOverrides(exercise: exercise, session: session),
|
||||
...exerciseAndSessionRepoOverrides(
|
||||
exercise: exercise,
|
||||
session: session,
|
||||
userProfile: userProfile,
|
||||
),
|
||||
routineRepetitionUnitProvider.overrideWith(
|
||||
(ref) => Stream<List<RepetitionUnit>>.value(repetitionUnits),
|
||||
),
|
||||
|
||||
@@ -8,6 +8,8 @@ import 'dart:async' as _i4;
|
||||
import 'package:mockito/mockito.dart' as _i1;
|
||||
import 'package:wger/core/language.dart' as _i11;
|
||||
import 'package:wger/core/search_options.dart' as _i5;
|
||||
import 'package:wger/features/account/models/user_profile.dart' as _i14;
|
||||
import 'package:wger/features/account/providers/user_profile_repository.dart' as _i13;
|
||||
import 'package:wger/features/exercises/models/category.dart' as _i7;
|
||||
import 'package:wger/features/exercises/models/equipment.dart' as _i9;
|
||||
import 'package:wger/features/exercises/models/exercise_filters.dart' as _i6;
|
||||
@@ -172,3 +174,29 @@ class MockWorkoutSessionRepository extends _i1.Mock implements _i12.WorkoutSessi
|
||||
)
|
||||
as _i4.Future<_i2.WorkoutSession>);
|
||||
}
|
||||
|
||||
/// A class which mocks [UserProfileRepository].
|
||||
///
|
||||
/// See the documentation for Mockito's code generation for more information.
|
||||
class MockUserProfileRepository extends _i1.Mock implements _i13.UserProfileRepository {
|
||||
MockUserProfileRepository() {
|
||||
_i1.throwOnMissingStub(this);
|
||||
}
|
||||
|
||||
@override
|
||||
_i4.Stream<_i14.UserProfile?> watchDrift() =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#watchDrift, []),
|
||||
returnValue: _i4.Stream<_i14.UserProfile?>.empty(),
|
||||
)
|
||||
as _i4.Stream<_i14.UserProfile?>);
|
||||
|
||||
@override
|
||||
_i4.Future<void> editLocalDrift(_i14.UserProfile? profile) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#editLocalDrift, [profile]),
|
||||
returnValue: _i4.Future<void>.value(),
|
||||
returnValueForMissingStub: _i4.Future<void>.value(),
|
||||
)
|
||||
as _i4.Future<void>);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of wger Workout Manager <https://github.com/wger-project>.
|
||||
* Copyright (c) 2020, 2025 wger Team
|
||||
* Copyright (c) 2020 - 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
|
||||
@@ -22,6 +22,7 @@ import 'package:wger/features/exercises/models/category.dart';
|
||||
import 'package:wger/features/exercises/models/exercise.dart';
|
||||
import 'package:wger/features/routines/models/log.dart';
|
||||
import 'package:wger/features/routines/models/set_config_data.dart';
|
||||
import 'package:wger/features/routines/models/weight_unit.dart';
|
||||
|
||||
import '../../../../test_data/exercises.dart';
|
||||
|
||||
@@ -180,6 +181,24 @@ void main() {
|
||||
expect(log.repetitionsUnitId, REP_UNIT_TILL_FAILURE_ID);
|
||||
});
|
||||
|
||||
test('derives the unit ID from the resolved unit object when no explicit ID is set', () {
|
||||
// Imperial users: routine hydration leaves weightUnitId null and only
|
||||
// resolves the weightUnit object (lb) from the profile. The log must pick
|
||||
// up lb for *both* the ID and the object
|
||||
const lb = WeightUnit(id: WEIGHT_UNIT_LB, name: 'lb');
|
||||
final setConfig = SetConfigData(
|
||||
exerciseId: 1,
|
||||
slotEntryId: 1,
|
||||
exercise: exercise,
|
||||
weightUnit: lb,
|
||||
);
|
||||
|
||||
final log = Log.fromSetConfigData(setConfig);
|
||||
|
||||
expect(log.weightUnitId, WEIGHT_UNIT_LB);
|
||||
expect(log.weightUnitObj, lb);
|
||||
});
|
||||
|
||||
test('copies weight and repetitions values', () {
|
||||
final setConfig = SetConfigData(
|
||||
exerciseId: 1,
|
||||
|
||||
@@ -52,6 +52,13 @@ void main() {
|
||||
expect(slotEntry.maxRestTimeConfigs.length, 1);
|
||||
});
|
||||
|
||||
test('withData leaves the weight unit unset so the profile default applies', () {
|
||||
final slotEntry = SlotEntry.withData(slotId: 1, exercise: testSquats);
|
||||
|
||||
expect(slotEntry.weightUnitId, isNull);
|
||||
expect(slotEntry.weightUnitObj, isNull);
|
||||
});
|
||||
|
||||
test('Checks that an empty model correctly calculates hasProgressionRules', () {
|
||||
final slotEntry = SlotEntry.empty();
|
||||
expect(slotEntry.hasProgressionRules, false);
|
||||
|
||||
@@ -20,14 +20,20 @@ import 'package:clock/clock.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:shared_preferences_platform_interface/in_memory_shared_preferences_async.dart';
|
||||
import 'package:shared_preferences_platform_interface/shared_preferences_async_platform_interface.dart';
|
||||
import 'package:wger/core/shared_preferences.dart';
|
||||
import 'package:wger/features/account/models/user_profile.dart';
|
||||
import 'package:wger/features/account/providers/user_profile_notifier.dart';
|
||||
import 'package:wger/features/account/providers/user_profile_repository.dart';
|
||||
import 'package:wger/features/routines/providers/gym_state.dart';
|
||||
import 'package:wger/features/routines/providers/gym_state_notifier.dart';
|
||||
import 'package:wger/features/routines/providers/routines_notifier.dart';
|
||||
|
||||
import '../../../../test_data/exercises.dart';
|
||||
import '../../../../test_data/routines.dart';
|
||||
import '../helpers/routine_form_test_overrides.dart';
|
||||
|
||||
void main() {
|
||||
late GymStateNotifier notifier;
|
||||
@@ -171,6 +177,52 @@ void main() {
|
||||
});
|
||||
});
|
||||
|
||||
group('GymStateNotifier.addExerciseAfterPage', () {
|
||||
test('Stamps the profile default weight unit on the ad-hoc set configs', () async {
|
||||
// Ad-hoc exercises bypass routine hydration, so the notifier itself
|
||||
// resolves the profile default: lb (id 2) for an imperial user.
|
||||
final profileRepo = MockUserProfileRepository();
|
||||
when(
|
||||
profileRepo.watchDrift(),
|
||||
).thenAnswer((_) => Stream.value(UserProfile(id: 1, weightUnitStr: 'lb')));
|
||||
|
||||
final imperialContainer = ProviderContainer.test(
|
||||
overrides: [
|
||||
userProfileRepositoryProvider.overrideWithValue(profileRepo),
|
||||
routineWeightUnitProvider.overrideWith((ref) => Stream.value(testWeightUnits)),
|
||||
],
|
||||
);
|
||||
// Let both streams emit before the notifier reads them (in the app the
|
||||
// dashboard keeps them alive long before gym mode starts).
|
||||
imperialContainer.listen(userProfileProvider, (_, _) {});
|
||||
imperialContainer.listen(routineWeightUnitProvider, (_, _) {});
|
||||
await pumpEventQueue();
|
||||
|
||||
final imperialNotifier = imperialContainer.read(gymStateProvider.notifier);
|
||||
imperialNotifier.state = imperialNotifier.state.copyWith(
|
||||
showExercisePages: true,
|
||||
showTimerPages: true,
|
||||
dayId: 1,
|
||||
iteration: 1,
|
||||
routine: getTestRoutine(),
|
||||
);
|
||||
imperialNotifier.calculatePages();
|
||||
final setPage = imperialNotifier.state.pages.firstWhere((p) => p.type == PageType.set);
|
||||
|
||||
imperialNotifier.addExerciseAfterPage(setPage.uuid, newExercise: testSquats);
|
||||
|
||||
// recalculateIndices copies the page objects, so look the page up by uuid.
|
||||
final pages = imperialNotifier.state.pages;
|
||||
final newPage = pages[pages.indexWhere((p) => p.uuid == setPage.uuid) + 1];
|
||||
expect(newPage.slotPages, isNotEmpty);
|
||||
for (final slotPage in newPage.slotPages) {
|
||||
// testWeightUnit2 has id 2 == WEIGHT_UNIT_LB.
|
||||
expect(slotPage.setConfigData!.weightUnit, testWeightUnit2);
|
||||
expect(slotPage.setConfigData!.weightUnitId, isNull);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
group('GymStateNotifier.calculatePages', () {
|
||||
test(
|
||||
'Correctly generates pages - exercise and timer',
|
||||
|
||||
@@ -16,18 +16,24 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_riverpod/misc.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:wger/features/account/models/user_profile.dart';
|
||||
import 'package:wger/features/exercises/models/exercise.dart';
|
||||
import 'package:wger/features/exercises/providers/exercises_notifier.dart';
|
||||
import 'package:wger/features/routines/models/day.dart';
|
||||
import 'package:wger/features/routines/models/day_data.dart';
|
||||
import 'package:wger/features/routines/models/log.dart';
|
||||
import 'package:wger/features/routines/models/routine.dart';
|
||||
import 'package:wger/features/routines/models/session.dart';
|
||||
import 'package:wger/features/routines/models/set_config_data.dart';
|
||||
import 'package:wger/features/routines/models/slot.dart';
|
||||
import 'package:wger/features/routines/models/slot_data.dart';
|
||||
import 'package:wger/features/routines/models/slot_entry.dart';
|
||||
import 'package:wger/features/routines/providers/routines_notifier.dart';
|
||||
import 'package:wger/features/routines/providers/routines_repository.dart';
|
||||
@@ -359,6 +365,135 @@ void main() {
|
||||
// Assert: `_fullFetchInFlight` collapses them into a single roundtrip.
|
||||
verify(mockRepo.fetchAndSetRoutineFullServer(101)).called(1);
|
||||
});
|
||||
|
||||
test('resolves the default weight unit from an imperial profile', () async {
|
||||
// A slot entry or set config without an explicit weight unit must inherit
|
||||
// the unit implied by the profile: lb (id 2) for an imperial user, not kg.
|
||||
overrideStreams(mockExerciseRepo);
|
||||
final setConfig = SetConfigData(
|
||||
exerciseId: 1,
|
||||
slotEntryId: 1,
|
||||
exercise: getTestExercises()[0],
|
||||
// No weightUnit / weightUnitId: the server omits it, the default applies.
|
||||
);
|
||||
final routine = Routine(id: 101, name: 'Test routine')
|
||||
..days = [
|
||||
Day(id: 1, routineId: 101, name: 'Test', order: 1)
|
||||
..slots = [
|
||||
Slot.withData(id: 1, day: 1, order: 1)
|
||||
..entries.add(
|
||||
SlotEntry(
|
||||
id: 1,
|
||||
slotId: 1,
|
||||
exerciseId: 1,
|
||||
repetitionUnitId: 1,
|
||||
repetitionRounding: null,
|
||||
weightUnitId: null,
|
||||
weightRounding: null,
|
||||
),
|
||||
),
|
||||
],
|
||||
]
|
||||
..dayDataGym = [
|
||||
DayData(
|
||||
iteration: 1,
|
||||
date: DateTime(2024, 11, 1),
|
||||
label: '',
|
||||
day: Day(id: 1, routineId: 101, name: 'Test', order: 1),
|
||||
slots: [
|
||||
SlotData(comment: '', isSuperset: false, exerciseIds: [1], setConfigs: [setConfig]),
|
||||
],
|
||||
),
|
||||
];
|
||||
when(mockRepo.fetchAndSetRoutineFullServer(101)).thenAnswer((_) async => routine);
|
||||
|
||||
final imperialProfileRepo = MockUserProfileRepository();
|
||||
when(
|
||||
imperialProfileRepo.watchDrift(),
|
||||
).thenAnswer((_) => Stream.value(UserProfile(id: 1, weightUnitStr: 'lb')));
|
||||
|
||||
final container = ProviderContainer.test(
|
||||
overrides: [
|
||||
routinesRepositoryProvider.overrideWithValue(mockRepo),
|
||||
...routineFormAmbientOverrides(
|
||||
exercise: mockExerciseRepo,
|
||||
session: mockSessionRepo,
|
||||
userProfile: imperialProfileRepo,
|
||||
repetitionUnits: testRepetitionUnits,
|
||||
weightUnits: testWeightUnits,
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
final notifier = container.read(routinesRiverpodProvider.notifier);
|
||||
final result = await notifier.fetchAndSetRoutineFull(101);
|
||||
|
||||
// testWeightUnit2 has id 2 == WEIGHT_UNIT_LB.
|
||||
final hydratedConfig = result.dayDataGym[0].slots[0].setConfigs[0];
|
||||
expect(hydratedConfig.weightUnit, testWeightUnit2);
|
||||
final hydratedEntry = result.days[0].slots[0].entries[0];
|
||||
expect(hydratedEntry.weightUnitObj, testWeightUnit2);
|
||||
});
|
||||
|
||||
test('waits for the profile before hydrating and re-hydrates when it changes', () async {
|
||||
overrideStreams(mockExerciseRepo);
|
||||
final setConfig = SetConfigData(
|
||||
exerciseId: 1,
|
||||
slotEntryId: 1,
|
||||
exercise: getTestExercises()[0],
|
||||
);
|
||||
final routine = Routine(id: 101, name: 'Test routine')
|
||||
..dayDataGym = [
|
||||
DayData(
|
||||
iteration: 1,
|
||||
date: DateTime(2024, 11, 1),
|
||||
label: '',
|
||||
day: Day(id: 1, routineId: 101, name: 'Test', order: 1),
|
||||
slots: [
|
||||
SlotData(comment: '', isSuperset: false, exerciseIds: [1], setConfigs: [setConfig]),
|
||||
],
|
||||
),
|
||||
];
|
||||
when(mockRepo.fetchAndSetRoutineFullServer(101)).thenAnswer((_) async => routine);
|
||||
|
||||
final profileController = StreamController<UserProfile?>();
|
||||
addTearDown(profileController.close);
|
||||
final profileRepo = MockUserProfileRepository();
|
||||
when(profileRepo.watchDrift()).thenAnswer((_) => profileController.stream);
|
||||
|
||||
final container = ProviderContainer.test(
|
||||
overrides: [
|
||||
routinesRepositoryProvider.overrideWithValue(mockRepo),
|
||||
...routineFormAmbientOverrides(
|
||||
exercise: mockExerciseRepo,
|
||||
session: mockSessionRepo,
|
||||
userProfile: profileRepo,
|
||||
repetitionUnits: testRepetitionUnits,
|
||||
weightUnits: testWeightUnits,
|
||||
),
|
||||
],
|
||||
);
|
||||
container.listen(routinesRiverpodProvider, (_, _) {});
|
||||
|
||||
// The fetch must park on the profile instead of hydrating with the kg
|
||||
// fallback while the profile row hasn't synced yet. Snapshot the unit
|
||||
// the moment the fetch resolves: later re-hydration mutates the same
|
||||
// routine instance and would mask a too-early completion.
|
||||
final notifier = container.read(routinesRiverpodProvider.notifier);
|
||||
final unitAtFetchCompletion = notifier
|
||||
.fetchAndSetRoutineFull(101)
|
||||
.then((r) => r.dayDataGym[0].slots[0].setConfigs[0].weightUnit);
|
||||
await pumpEventQueue();
|
||||
profileController.add(UserProfile(id: 1, weightUnitStr: 'lb'));
|
||||
expect(await unitAtFetchCompletion, testWeightUnit2);
|
||||
|
||||
// A later profile change (settings switch to metric) re-hydrates in place.
|
||||
profileController.add(UserProfile(id: 1, weightUnitStr: 'kg'));
|
||||
await pumpEventQueue();
|
||||
final routines = container.read(routinesRiverpodProvider).value!.routines;
|
||||
final rehydrated = routines.singleWhere((r) => r.id == 101);
|
||||
expect(rehydrated.dayDataGym[0].slots[0].setConfigs[0].weightUnit, testWeightUnit1);
|
||||
});
|
||||
});
|
||||
|
||||
group('routineHydration family', () {
|
||||
|
||||
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
@@ -28,6 +28,7 @@ import 'package:shared_preferences_platform_interface/shared_preferences_async_p
|
||||
import 'package:wger/core/network/network_provider.dart';
|
||||
import 'package:wger/core/shared_preferences.dart';
|
||||
import 'package:wger/core/widgets/error.dart';
|
||||
import 'package:wger/features/account/providers/user_profile_repository.dart';
|
||||
import 'package:wger/features/exercises/providers/exercise_repository.dart';
|
||||
import 'package:wger/features/exercises/providers/exercises_notifier.dart';
|
||||
import 'package:wger/features/routines/models/repetition_unit.dart';
|
||||
@@ -61,6 +62,7 @@ import 'gym_mode_test.mocks.dart';
|
||||
RoutinesRepository,
|
||||
TrophyRepository,
|
||||
WorkoutLogRepository,
|
||||
UserProfileRepository,
|
||||
])
|
||||
void main() {
|
||||
installFakeConnectivity();
|
||||
@@ -74,9 +76,11 @@ void main() {
|
||||
final mockExerciseRepo = MockExerciseRepository();
|
||||
final mockRoutinesRepo = MockRoutinesRepository();
|
||||
final mockLogRepo = MockWorkoutLogRepository();
|
||||
final mockUserProfileRepo = MockUserProfileRepository();
|
||||
|
||||
setUp(() {
|
||||
SharedPreferencesAsyncPlatform.instance = InMemorySharedPreferencesAsync.empty();
|
||||
when(mockUserProfileRepo.watchDrift()).thenAnswer((_) => Stream.value(null));
|
||||
when(mockSessionRepo.watchAllDrift()).thenAnswer(
|
||||
(_) => Stream<List<WorkoutSession>>.multi((controller) {
|
||||
controller.add(testRoutine.sessions);
|
||||
@@ -123,6 +127,7 @@ void main() {
|
||||
exerciseRepositoryProvider.overrideWithValue(mockExerciseRepo),
|
||||
workoutSessionRepositoryProvider.overrideWithValue(mockSessionRepo),
|
||||
workoutLogRepositoryProvider.overrideWithValue(mockLogRepo),
|
||||
userProfileRepositoryProvider.overrideWithValue(mockUserProfileRepo),
|
||||
...extraOverrides,
|
||||
// The repetition + weight unit catalogues are tiny direct-Drift
|
||||
// stream providers, overriding them inline is the established
|
||||
|
||||
@@ -10,6 +10,8 @@ import 'package:mockito/src/dummies.dart' as _i23;
|
||||
import 'package:wger/core/language.dart' as _i18;
|
||||
import 'package:wger/core/network/base_provider.dart' as _i8;
|
||||
import 'package:wger/core/search_options.dart' as _i12;
|
||||
import 'package:wger/features/account/models/user_profile.dart' as _i30;
|
||||
import 'package:wger/features/account/providers/user_profile_repository.dart' as _i29;
|
||||
import 'package:wger/features/exercises/models/category.dart' as _i14;
|
||||
import 'package:wger/features/exercises/models/equipment.dart' as _i16;
|
||||
import 'package:wger/features/exercises/models/exercise_filters.dart' as _i13;
|
||||
@@ -576,3 +578,29 @@ class MockWorkoutLogRepository extends _i1.Mock implements _i27.WorkoutLogReposi
|
||||
)
|
||||
as _i10.Future<void>);
|
||||
}
|
||||
|
||||
/// A class which mocks [UserProfileRepository].
|
||||
///
|
||||
/// See the documentation for Mockito's code generation for more information.
|
||||
class MockUserProfileRepository extends _i1.Mock implements _i29.UserProfileRepository {
|
||||
MockUserProfileRepository() {
|
||||
_i1.throwOnMissingStub(this);
|
||||
}
|
||||
|
||||
@override
|
||||
_i10.Stream<_i30.UserProfile?> watchDrift() =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#watchDrift, []),
|
||||
returnValue: _i10.Stream<_i30.UserProfile?>.empty(),
|
||||
)
|
||||
as _i10.Stream<_i30.UserProfile?>);
|
||||
|
||||
@override
|
||||
_i10.Future<void> editLocalDrift(_i30.UserProfile? profile) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#editLocalDrift, [profile]),
|
||||
returnValue: _i10.Future<void>.value(),
|
||||
returnValueForMissingStub: _i10.Future<void>.value(),
|
||||
)
|
||||
as _i10.Future<void>);
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ import 'package:wger/core/consts.dart';
|
||||
import 'package:wger/core/exceptions/http_exception.dart';
|
||||
import 'package:wger/core/network/network_provider.dart';
|
||||
import 'package:wger/core/widgets/form_submit_button.dart';
|
||||
import 'package:wger/features/account/providers/user_profile_repository.dart';
|
||||
import 'package:wger/features/exercises/models/exercise.dart';
|
||||
import 'package:wger/features/exercises/providers/exercise_repository.dart';
|
||||
import 'package:wger/features/exercises/providers/exercises_notifier.dart';
|
||||
@@ -46,13 +47,19 @@ import '../../../../../test_data/routines.dart';
|
||||
import '../../../../fake_connectivity.dart';
|
||||
import './routine_form_test.mocks.dart';
|
||||
|
||||
@GenerateMocks([RoutinesRepository, WorkoutSessionRepository, ExerciseRepository])
|
||||
@GenerateMocks([
|
||||
RoutinesRepository,
|
||||
WorkoutSessionRepository,
|
||||
ExerciseRepository,
|
||||
UserProfileRepository,
|
||||
])
|
||||
void main() {
|
||||
installFakeConnectivity();
|
||||
|
||||
late MockRoutinesRepository mockRoutinesRepository;
|
||||
late MockWorkoutSessionRepository mockSessionRepo;
|
||||
late MockExerciseRepository mockExerciseRepo;
|
||||
late MockUserProfileRepository mockUserProfileRepo;
|
||||
late StreamController<List<Routine>> routineStream;
|
||||
late Routine existingRoutine;
|
||||
late Routine newRoutine;
|
||||
@@ -92,6 +99,10 @@ void main() {
|
||||
when(
|
||||
mockExerciseRepo.watchAllDrift(),
|
||||
).thenAnswer((_) => Stream.value(ExerciseState(const <Exercise>[])));
|
||||
// RoutinesRiverpod.build() also listens to the user profile for the default
|
||||
// weight unit; stub it so the real PowerSync DB isn't pulled in.
|
||||
mockUserProfileRepo = MockUserProfileRepository();
|
||||
when(mockUserProfileRepo.watchDrift()).thenAnswer((_) => Stream.value(null));
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
@@ -106,6 +117,7 @@ void main() {
|
||||
routinesRepositoryProvider.overrideWithValue(mockRoutinesRepository),
|
||||
workoutSessionRepositoryProvider.overrideWithValue(mockSessionRepo),
|
||||
exerciseRepositoryProvider.overrideWithValue(mockExerciseRepo),
|
||||
userProfileRepositoryProvider.overrideWithValue(mockUserProfileRepo),
|
||||
networkStatusProvider.overrideWithValue(isOnline),
|
||||
routineRepetitionUnitProvider.overrideWith(
|
||||
(ref) => Stream<List<RepetitionUnit>>.value(testRepetitionUnits),
|
||||
|
||||
@@ -8,6 +8,8 @@ import 'dart:async' as _i9;
|
||||
import 'package:mockito/mockito.dart' as _i1;
|
||||
import 'package:wger/core/language.dart' as _i20;
|
||||
import 'package:wger/core/search_options.dart' as _i14;
|
||||
import 'package:wger/features/account/models/user_profile.dart' as _i22;
|
||||
import 'package:wger/features/account/providers/user_profile_repository.dart' as _i21;
|
||||
import 'package:wger/features/exercises/models/category.dart' as _i16;
|
||||
import 'package:wger/features/exercises/models/equipment.dart' as _i18;
|
||||
import 'package:wger/features/exercises/models/exercise_filters.dart' as _i15;
|
||||
@@ -418,3 +420,29 @@ class MockExerciseRepository extends _i1.Mock implements _i13.ExerciseRepository
|
||||
)
|
||||
as _i9.Stream<List<_i20.Language>>);
|
||||
}
|
||||
|
||||
/// A class which mocks [UserProfileRepository].
|
||||
///
|
||||
/// See the documentation for Mockito's code generation for more information.
|
||||
class MockUserProfileRepository extends _i1.Mock implements _i21.UserProfileRepository {
|
||||
MockUserProfileRepository() {
|
||||
_i1.throwOnMissingStub(this);
|
||||
}
|
||||
|
||||
@override
|
||||
_i9.Stream<_i22.UserProfile?> watchDrift() =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#watchDrift, []),
|
||||
returnValue: _i9.Stream<_i22.UserProfile?>.empty(),
|
||||
)
|
||||
as _i9.Stream<_i22.UserProfile?>);
|
||||
|
||||
@override
|
||||
_i9.Future<void> editLocalDrift(_i22.UserProfile? profile) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#editLocalDrift, [profile]),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value(),
|
||||
)
|
||||
as _i9.Future<void>);
|
||||
}
|
||||
|
||||
@@ -129,6 +129,16 @@ void main() {
|
||||
await tester.tap(find.byKey(const ValueKey('slot-entry-type-option-myo')), warnIfMissed: false);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Set the units (select by name, the item keys collide between the dropdowns)
|
||||
await tester.tap(find.byType(WeightUnitInputWidget));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text(testWeightUnit2.name).last, warnIfMissed: false);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byType(RepetitionUnitInputWidget));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text(testRepetitionUnit2.name).last, warnIfMissed: false);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.tap(find.byKey(const ValueKey(SUBMIT_BUTTON_KEY_NAME)));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
@@ -139,7 +149,9 @@ void main() {
|
||||
.having((d) => d.id, 'id', null)
|
||||
.having((d) => d.slotId, 'slotId', 1)
|
||||
.having((d) => d.order, 'order', 1)
|
||||
.having((d) => d.type, 'type', SlotEntryType.myo),
|
||||
.having((d) => d.type, 'type', SlotEntryType.myo)
|
||||
.having((d) => d.weightUnitId, 'weightUnitId', testWeightUnit2.id)
|
||||
.having((d) => d.repetitionUnitId, 'repetitionUnitId', testRepetitionUnit2.id),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
59
test/theme/dynamic_color_test.dart
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* This file is part of wger Workout Manager <https://github.com/wger-project>.
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:wger/theme/dynamic_color.dart';
|
||||
|
||||
void main() {
|
||||
final light = ColorScheme.fromSeed(seedColor: const Color(0xFF6750A4));
|
||||
final dark = ColorScheme.fromSeed(
|
||||
seedColor: const Color(0xFFB3261E),
|
||||
brightness: Brightness.dark,
|
||||
);
|
||||
|
||||
group('appThemeSeed', () {
|
||||
test('is null while the setting is off, whatever the platform offers', () {
|
||||
expect(
|
||||
appThemeSeed(useDynamicColor: false, lightDynamic: light, darkDynamic: dark),
|
||||
isNull,
|
||||
);
|
||||
});
|
||||
|
||||
test('is null when the platform offers nothing', () {
|
||||
expect(
|
||||
appThemeSeed(useDynamicColor: true, lightDynamic: null, darkDynamic: null),
|
||||
isNull,
|
||||
);
|
||||
});
|
||||
|
||||
test('prefers the light scheme when both are present', () {
|
||||
expect(
|
||||
appThemeSeed(useDynamicColor: true, lightDynamic: light, darkDynamic: dark),
|
||||
light.primary,
|
||||
);
|
||||
});
|
||||
|
||||
test('falls back to the dark scheme on its own', () {
|
||||
expect(
|
||||
appThemeSeed(useDynamicColor: true, lightDynamic: null, darkDynamic: dark),
|
||||
dark.primary,
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
88
test/theme/theme_test.dart
Normal file
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* This file is part of wger Workout Manager <https://github.com/wger-project>.
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import 'package:flex_color_scheme/flex_color_scheme.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:wger/theme/theme.dart';
|
||||
|
||||
void main() {
|
||||
group('wgerThemeFromSeed', () {
|
||||
const seed = Color(0xFF6750A4);
|
||||
|
||||
test('applies the requested brightness', () {
|
||||
expect(wgerThemeFromSeed(seed, Brightness.light).brightness, Brightness.light);
|
||||
expect(wgerThemeFromSeed(seed, Brightness.dark).brightness, Brightness.dark);
|
||||
});
|
||||
|
||||
test('derives the palette from the seed hue', () {
|
||||
final scheme = wgerThemeFromSeed(seed, Brightness.light).colorScheme;
|
||||
|
||||
expect(
|
||||
Hct.fromInt(scheme.primary.toARGB32()).hue,
|
||||
closeTo(Hct.fromInt(seed.toARGB32()).hue, 5),
|
||||
);
|
||||
});
|
||||
|
||||
test('generates a distinct surface container ramp', () {
|
||||
// A platform scheme used as-is leaves these unset, which flattens every
|
||||
// elevated surface onto the scaffold color.
|
||||
for (final brightness in Brightness.values) {
|
||||
final scheme = wgerThemeFromSeed(seed, brightness).colorScheme;
|
||||
|
||||
expect(
|
||||
{
|
||||
scheme.surface,
|
||||
scheme.surfaceContainerLowest,
|
||||
scheme.surfaceContainerLow,
|
||||
scheme.surfaceContainer,
|
||||
scheme.surfaceContainerHigh,
|
||||
scheme.surfaceContainerHighest,
|
||||
},
|
||||
hasLength(6),
|
||||
reason: 'surface tones collapsed in $brightness',
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test('high contrast spreads the palette further apart', () {
|
||||
double contrast(Color a, Color b) {
|
||||
final values = [a.computeLuminance(), b.computeLuminance()]..sort();
|
||||
|
||||
return (values.last + 0.05) / (values.first + 0.05);
|
||||
}
|
||||
|
||||
for (final brightness in Brightness.values) {
|
||||
final normal = wgerThemeFromSeed(seed, brightness).colorScheme;
|
||||
final hc = wgerThemeFromSeed(seed, brightness, highContrast: true).colorScheme;
|
||||
|
||||
expect(
|
||||
contrast(hc.onSurface, hc.surface),
|
||||
greaterThan(contrast(normal.onSurface, normal.surface)),
|
||||
reason: 'no extra contrast in $brightness',
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test('keeps the wger typography', () {
|
||||
final theme = wgerThemeFromSeed(seed, Brightness.light);
|
||||
|
||||
expect(theme.textTheme.headlineLarge?.fontFamily, wgerDisplayFont);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include <app_links/app_links_plugin_c_api.h>
|
||||
#include <connectivity_plus/connectivity_plus_windows_plugin.h>
|
||||
#include <dynamic_color/dynamic_color_plugin_c_api.h>
|
||||
#include <file_selector_windows/file_selector_windows.h>
|
||||
#include <flutter_secure_storage_windows/flutter_secure_storage_windows_plugin.h>
|
||||
#include <url_launcher_windows/url_launcher_windows.h>
|
||||
@@ -17,6 +18,8 @@ void RegisterPlugins(flutter::PluginRegistry* registry) {
|
||||
registry->GetRegistrarForPlugin("AppLinksPluginCApi"));
|
||||
ConnectivityPlusWindowsPluginRegisterWithRegistrar(
|
||||
registry->GetRegistrarForPlugin("ConnectivityPlusWindowsPlugin"));
|
||||
DynamicColorPluginCApiRegisterWithRegistrar(
|
||||
registry->GetRegistrarForPlugin("DynamicColorPluginCApi"));
|
||||
FileSelectorWindowsRegisterWithRegistrar(
|
||||
registry->GetRegistrarForPlugin("FileSelectorWindows"));
|
||||
FlutterSecureStorageWindowsPluginRegisterWithRegistrar(
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
list(APPEND FLUTTER_PLUGIN_LIST
|
||||
app_links
|
||||
connectivity_plus
|
||||
dynamic_color
|
||||
file_selector_windows
|
||||
flutter_secure_storage_windows
|
||||
url_launcher_windows
|
||||
|
||||