mirror of
https://github.com/wger-project/flutter.git
synced 2026-12-04 12:42:22 +01:00
Default the measurement charts to one month
This commit is contained in:
@@ -20,10 +20,10 @@ import 'package:collection/collection.dart';
|
||||
import 'package:wger/features/measurements/models/measurement_category.dart';
|
||||
import 'package:wger/l10n/generated/app_localizations.dart';
|
||||
|
||||
/// The range the charts cover until the user picks another one.
|
||||
const defaultChartRange = ChartRange.lastMonth;
|
||||
|
||||
/// Time range the user can pick to limit how far back the charts go.
|
||||
///
|
||||
/// The default is the shortest one: a chart is only readable if the span it
|
||||
/// covers is, and the recent values are what tracking progress is about.
|
||||
enum ChartRange {
|
||||
all(null),
|
||||
lastYear(365),
|
||||
|
||||
@@ -43,7 +43,7 @@ class ChartRangeSetting extends _$ChartRangeSetting {
|
||||
@override
|
||||
ChartRange build() {
|
||||
unawaited(_load());
|
||||
return ChartRange.last3Months;
|
||||
return defaultChartRange;
|
||||
}
|
||||
|
||||
/// The stored pick, applied once it is read; a value this release does not
|
||||
|
||||
@@ -63,7 +63,7 @@ class CategoriesCard extends ConsumerWidget {
|
||||
const CategoriesCard(
|
||||
this.currentCategory, {
|
||||
this.elevation,
|
||||
this.range = ChartRange.last3Months,
|
||||
this.range = defaultChartRange,
|
||||
this.title,
|
||||
this.displayUnit,
|
||||
this.displayUnitLabel,
|
||||
|
||||
@@ -52,7 +52,7 @@ const _heatmapHeight = 58.0;
|
||||
/// as context over the range the filter selects. A tap opens the category's
|
||||
/// entries screen; everything beyond a glance lives there.
|
||||
class MeasurementTile extends ConsumerWidget {
|
||||
const MeasurementTile(this.category, {this.range = ChartRange.last3Months, super.key});
|
||||
const MeasurementTile(this.category, {this.range = defaultChartRange, super.key});
|
||||
|
||||
final MeasurementCategory category;
|
||||
final ChartRange range;
|
||||
|
||||
@@ -40,10 +40,10 @@ void main() {
|
||||
|
||||
group('ChartRangeSetting', () {
|
||||
test('starts at the default while nothing is stored', () async {
|
||||
expect(container.read(chartRangeSettingProvider), ChartRange.last3Months);
|
||||
expect(container.read(chartRangeSettingProvider), defaultChartRange);
|
||||
|
||||
await pumpEventQueue();
|
||||
expect(container.read(chartRangeSettingProvider), ChartRange.last3Months);
|
||||
expect(container.read(chartRangeSettingProvider), defaultChartRange);
|
||||
});
|
||||
|
||||
test('a pick is what every watcher reads afterwards, and it is persisted', () async {
|
||||
@@ -55,7 +55,8 @@ void main() {
|
||||
});
|
||||
|
||||
test('the stored pick survives a restart', () async {
|
||||
await prefs.setString(PREFS_CHART_RANGE, 'lastMonth');
|
||||
// Deliberately not the default, or the test would pass without loading
|
||||
await prefs.setString(PREFS_CHART_RANGE, 'lastYear');
|
||||
|
||||
// A fresh container stands in for the next app run
|
||||
final restarted = ProviderContainer.test(
|
||||
@@ -64,7 +65,7 @@ void main() {
|
||||
restarted.listen(chartRangeSettingProvider, (_, _) {});
|
||||
await pumpEventQueue();
|
||||
|
||||
expect(restarted.read(chartRangeSettingProvider), ChartRange.lastMonth);
|
||||
expect(restarted.read(chartRangeSettingProvider), ChartRange.lastYear);
|
||||
});
|
||||
|
||||
test('a value this release does not know leaves the default', () async {
|
||||
@@ -76,11 +77,11 @@ void main() {
|
||||
restarted.listen(chartRangeSettingProvider, (_, _) {});
|
||||
await pumpEventQueue();
|
||||
|
||||
expect(restarted.read(chartRangeSettingProvider), ChartRange.last3Months);
|
||||
expect(restarted.read(chartRangeSettingProvider), defaultChartRange);
|
||||
});
|
||||
|
||||
test('a pick made before the stored value arrives is not overwritten', () async {
|
||||
await prefs.setString(PREFS_CHART_RANGE, 'lastMonth');
|
||||
await prefs.setString(PREFS_CHART_RANGE, 'lastYear');
|
||||
|
||||
final restarted = ProviderContainer.test(
|
||||
overrides: [appSettingsPrefsProvider.overrideWithValue(prefs)],
|
||||
|
||||
Reference in New Issue
Block a user