From 34b9b97081543b058a754ffd2f65973cabcff59e Mon Sep 17 00:00:00 2001 From: Roland Geider Date: Thu, 20 Aug 2026 18:56:51 +0200 Subject: [PATCH] Allow disabling the average and the trend lines --- .../widgets/dashboard/widgets/weight.dart | 2 +- lib/features/measurements/charts/data.dart | 5 ++- .../models/measurement_category.dart | 22 +++++++++--- .../measurements/widgets/forms/category.dart | 7 ++-- .../measurements/widgets/helpers.dart | 32 ++++++++++++----- .../widgets/ingredient_filter_dialog.dart | 4 +-- .../widgets/nutritional_plans_list.dart | 3 +- .../nutrition/widgets/plan_weight_chart.dart | 3 +- lib/l10n/app_de.arb | 6 ++-- lib/l10n/app_en.arb | 6 ++-- lib/l10n/app_es.arb | 6 ++-- lib/l10n/app_fr.arb | 10 +++--- lib/l10n/app_hr.arb | 6 ++-- lib/l10n/app_hu.arb | 6 ++-- lib/l10n/app_id.arb | 6 ++-- lib/l10n/app_it.arb | 6 ++-- lib/l10n/app_nl.arb | 6 ++-- lib/l10n/app_pt.arb | 6 ++-- lib/l10n/app_pt_BR.arb | 6 ++-- lib/l10n/app_sl.arb | 6 ++-- lib/l10n/app_zh_Hant.arb | 6 ++-- .../models/measurement_category_test.dart | 16 +++++++-- .../widgets/forms/category_test.dart | 34 ++++++++++++++++--- 23 files changed, 142 insertions(+), 68 deletions(-) diff --git a/lib/core/widgets/dashboard/widgets/weight.dart b/lib/core/widgets/dashboard/widgets/weight.dart index b9605e9ca..1ce39754e 100644 --- a/lib/core/widgets/dashboard/widgets/weight.dart +++ b/lib/core/widgets/dashboard/widgets/weight.dart @@ -143,7 +143,7 @@ class DashboardWeightWidget extends ConsumerWidget { final (entriesAll, average) = sensibleRange( points, - averageDays: category.chartSettings.averageWindow, + averageDays: category.chartSettings.averageWindow ?? ChartSettings.fallbackWindow, ); return Column( diff --git a/lib/features/measurements/charts/data.dart b/lib/features/measurements/charts/data.dart index a89857a8a..862610f3c 100644 --- a/lib/features/measurements/charts/data.dart +++ b/lib/features/measurements/charts/data.dart @@ -260,7 +260,10 @@ MeasurementBucketLevel chartBucketLevel(MetricType metricType, ChartType chartTy ChartRange range, ChartSettings settings, ) { - final average = movingAverage(points, days: settings.averageWindow); + final average = movingAverage( + points, + days: settings.averageWindow ?? ChartSettings.fallbackWindow, + ); final cutoff = range.cutoff; return cutoff == null diff --git a/lib/features/measurements/models/measurement_category.dart b/lib/features/measurements/models/measurement_category.dart index 47cccb031..17ff475a8 100644 --- a/lib/features/measurements/models/measurement_category.dart +++ b/lib/features/measurements/models/measurement_category.dart @@ -92,17 +92,24 @@ enum ChartType { ); } +/// What both line settings take when the user turns their line off +const chartLineOff = 'none'; + /// How closely the trend line follows the values, as the EMA period it maps to. /// /// Stored as the character rather than the number, so the periods stay tunable /// without touching what users configured. enum TrendCharacter { + /// No trend line at all, see [chartLineOff] + none(chartLineOff, null), reactive('reactive', 5), balanced('balanced', 10), sluggish('sluggish', 20); final String wireValue; - final int emaPeriod; + + /// Null for [TrendCharacter.none], which draws nothing + final int? emaPeriod; const TrendCharacter(this.wireValue, this.emaPeriod); /// Falls back to [TrendCharacter.balanced], which is the unconfigured chart. @@ -117,6 +124,7 @@ extension MeasurementTrendCharacterL10n on TrendCharacter { String localized(BuildContext context) { final l10n = AppLocalizations.of(context); return switch (this) { + TrendCharacter.none => l10n.off, TrendCharacter.reactive => l10n.trendReactive, TrendCharacter.balanced => l10n.trendBalanced, TrendCharacter.sluggish => l10n.trendSluggish, @@ -133,10 +141,14 @@ class ChartSettings { /// Windows the moving average may be computed over, in days. static const averageWindows = [7, 14, 30]; + /// Window the numbers derived from the average use when the line is off + static const fallbackWindow = 7; + final TrendCharacter trend; - /// Window the moving average covers, in days - final int averageWindow; + /// Window the moving average covers, in days, null when the user turned the + /// average line off + final int? averageWindow; const ChartSettings({ this.trend = TrendCharacter.balanced, @@ -152,7 +164,9 @@ class ChartSettings { return ChartSettings( trend: TrendCharacter.fromWire(config?['trend']), - averageWindow: window is int && averageWindows.contains(window) + averageWindow: window == chartLineOff + ? null + : window is int && averageWindows.contains(window) ? window : averageWindows.first, ); diff --git a/lib/features/measurements/widgets/forms/category.dart b/lib/features/measurements/widgets/forms/category.dart index 4a6e1e252..f56067a86 100644 --- a/lib/features/measurements/widgets/forms/category.dart +++ b/lib/features/measurements/widgets/forms/category.dart @@ -366,10 +366,13 @@ class _ChartSettingsSection extends StatelessWidget { } : null, ), - DropdownButtonFormField( - initialValue: settings.averageWindow, + // The window is a number, "off" is the string the server stores, so + // the two share one field only as objects + DropdownButtonFormField( + initialValue: settings.averageWindow ?? chartLineOff, decoration: InputDecoration(labelText: i18n.chartAverageWindow), items: [ + DropdownMenuItem(value: chartLineOff, child: Text(i18n.off)), for (final days in ChartSettings.averageWindows) DropdownMenuItem(value: days, child: Text(i18n.chartAverageWindowDays(days))), ], diff --git a/lib/features/measurements/widgets/helpers.dart b/lib/features/measurements/widgets/helpers.dart index 554510a18..aee986ab6 100644 --- a/lib/features/measurements/widgets/helpers.dart +++ b/lib/features/measurements/widgets/helpers.dart @@ -50,7 +50,9 @@ List buildChartSection( : buildChartForMetricType( metricType, raw, - avg, + // The average is still computed for the number below, the + // setting only decides whether the line is drawn + settings.averageWindow == null ? const [] : avg, unit, planPeriods: planPeriods, trend: trend, @@ -64,6 +66,16 @@ List buildChartSection( ]; } +/// The trend over [raw], null when the user turned the trend line off +List? _trendlineFor( + List raw, + ChartSettings settings, +) { + final period = settings.trend.emaPeriod; + + return period == null ? null : smoothedTrendline(raw, period: period); +} + /// The chart of a measurement series: [buildChartSection] for the chart the /// type resolves to, plus the legend naming the lines it draws. List buildSeriesChartSection( @@ -113,7 +125,8 @@ List buildSeriesChartSection( // The points arrive condensed, so the trend follows the shape across weeks // rather than the swings within a single day final summed = metricType.isSummedPerDay; - final trendAll = summed ? null : smoothedTrendline(entriesAll, period: settings.trend.emaPeriod); + final period = settings.trend.emaPeriod; + final trendAll = summed || period == null ? null : smoothedTrendline(entriesAll, period: period); return [ ...buildChartSection( context, @@ -134,12 +147,13 @@ List buildSeriesChartSection( text: AppLocalizations.of(context).indicatorRaw, isSquare: true, ), - Indicator( - color: Theme.of(context).colorScheme.tertiary, - text: AppLocalizations.of(context).indicatorAvg, - isSquare: true, - ), - if (!metricType.isSummedPerDay) + if (settings.averageWindow != null) + Indicator( + color: Theme.of(context).colorScheme.tertiary, + text: AppLocalizations.of(context).indicatorAvg, + isSquare: true, + ), + if (trendAll != null) Indicator( color: Theme.of(context).colorScheme.secondary, text: AppLocalizations.of(context).indicatorTrend, @@ -416,7 +430,7 @@ Widget buildChartForMetricType( raw, unit, avgs: avg, - trend: trend ?? smoothedTrendline(raw, period: settings.trend.emaPeriod), + trend: trend ?? _trendlineFor(raw, settings), planPeriods: planPeriods, ); } diff --git a/lib/features/nutrition/widgets/ingredient_filter_dialog.dart b/lib/features/nutrition/widgets/ingredient_filter_dialog.dart index 8232c9efd..7c9693a7c 100644 --- a/lib/features/nutrition/widgets/ingredient_filter_dialog.dart +++ b/lib/features/nutrition/widgets/ingredient_filter_dialog.dart @@ -158,7 +158,7 @@ class _NutriscoreSlider extends StatelessWidget { min: 0, max: maxIndex.toDouble(), divisions: maxIndex, - label: value == null ? i18n.filterNutriscoreOff : value!.name.toUpperCase(), + label: value == null ? i18n.off : value!.name.toUpperCase(), onChanged: (v) => onChanged(_indexToValue(v.round())), ), Padding( @@ -167,7 +167,7 @@ class _NutriscoreSlider extends StatelessWidget { mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text( - i18n.filterNutriscoreOff, + i18n.off, style: Theme.of(context).textTheme.labelSmall, ), ...NutriScore.values.map( diff --git a/lib/features/nutrition/widgets/nutritional_plans_list.dart b/lib/features/nutrition/widgets/nutritional_plans_list.dart index 50c358554..ec9213ccf 100644 --- a/lib/features/nutrition/widgets/nutritional_plans_list.dart +++ b/lib/features/nutrition/widgets/nutritional_plans_list.dart @@ -26,6 +26,7 @@ import 'package:wger/features/account/providers/user_profile_notifier.dart'; import 'package:wger/features/measurements/charts/data.dart'; import 'package:wger/features/measurements/measurements.dart'; import 'package:wger/features/measurements/models/measurement_bucket.dart'; +import 'package:wger/features/measurements/models/measurement_category.dart'; import 'package:wger/features/measurements/models/unit_conversion.dart'; import 'package:wger/features/measurements/providers/body_weight_provider.dart'; import 'package:wger/features/measurements/providers/measurement_notifier.dart'; @@ -78,7 +79,7 @@ class NutritionalPlansList extends riverpod.ConsumerWidget { ); final average = movingAverage( entriesAll, - days: category.chartSettings.averageWindow, + days: category.chartSettings.averageWindow ?? ChartSettings.fallbackWindow, ).whereDateWithInterpolation(startDate, endDate); if (average.length < 2) { return const SizedBox.shrink(); diff --git a/lib/features/nutrition/widgets/plan_weight_chart.dart b/lib/features/nutrition/widgets/plan_weight_chart.dart index 12f2dcf04..bf3a3f94b 100644 --- a/lib/features/nutrition/widgets/plan_weight_chart.dart +++ b/lib/features/nutrition/widgets/plan_weight_chart.dart @@ -21,6 +21,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:wger/features/account/providers/user_profile_notifier.dart'; import 'package:wger/features/measurements/charts/data.dart'; import 'package:wger/features/measurements/models/measurement_bucket.dart'; +import 'package:wger/features/measurements/models/measurement_category.dart'; import 'package:wger/features/measurements/models/unit_conversion.dart'; import 'package:wger/features/measurements/providers/body_weight_provider.dart'; import 'package:wger/features/measurements/providers/measurement_notifier.dart'; @@ -79,7 +80,7 @@ class PlanWeightChart extends ConsumerWidget { } final settings = category.chartSettings; - final avg = movingAverage(points, days: settings.averageWindow); + final avg = movingAverage(points, days: settings.averageWindow ?? ChartSettings.fallbackWindow); return Column( children: buildChartSection( diff --git a/lib/l10n/app_de.arb b/lib/l10n/app_de.arb index 9fe235749..dec55aa12 100644 --- a/lib/l10n/app_de.arb +++ b/lib/l10n/app_de.arb @@ -1011,9 +1011,9 @@ "@filterNutriscore": { "description": "Heading for the Nutri-Score slider in the ingredient search filter dialog" }, - "filterNutriscoreOff": "Aus", - "@filterNutriscoreOff": { - "description": "Label for the first slider stop, which disables the Nutri-Score filter" + "off": "Aus", + "@off": { + "description": "Generic label for the option that switches something off, e.g. a filter or a line of a chart" }, "filterNutriscoreNoFilter": "Kein Filter", "@filterNutriscoreNoFilter": { diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index 4b56e5ff5..b040cc7e0 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -1726,9 +1726,9 @@ "@filterNutriscore": { "description": "Heading for the Nutri-Score slider in the ingredient search filter dialog" }, - "filterNutriscoreOff": "Off", - "@filterNutriscoreOff": { - "description": "Label for the first slider stop, which disables the Nutri-Score filter" + "off": "Off", + "@off": { + "description": "Generic label for the option that switches something off, e.g. a filter or a line of a chart" }, "filterNutriscoreNoFilter": "No filter", "@filterNutriscoreNoFilter": { diff --git a/lib/l10n/app_es.arb b/lib/l10n/app_es.arb index f391134d9..dc8510fd3 100644 --- a/lib/l10n/app_es.arb +++ b/lib/l10n/app_es.arb @@ -1046,9 +1046,9 @@ "@filterNutriscore": { "description": "Heading for the Nutri-Score slider in the ingredient search filter dialog" }, - "filterNutriscoreOff": "Apagado", - "@filterNutriscoreOff": { - "description": "Label for the first slider stop, which disables the Nutri-Score filter" + "off": "Apagado", + "@off": { + "description": "Generic label for the option that switches something off, e.g. a filter or a line of a chart" }, "filterNutriscoreNoFilter": "Sin filtro", "@filterNutriscoreNoFilter": { diff --git a/lib/l10n/app_fr.arb b/lib/l10n/app_fr.arb index a12b750eb..88f4ecd2d 100644 --- a/lib/l10n/app_fr.arb +++ b/lib/l10n/app_fr.arb @@ -1017,9 +1017,9 @@ "@filterNutriscore": { "description": "Heading for the Nutri-Score slider in the ingredient search filter dialog" }, - "filterNutriscoreOff": "Off", - "@filterNutriscoreOff": { - "description": "Label for the first slider stop, which disables the Nutri-Score filter" + "off": "Off", + "@off": { + "description": "Generic label for the option that switches something off, e.g. a filter or a line of a chart" }, "filterNutriscoreNoFilter": "Pas de filtre", "@filterNutriscoreNoFilter": { @@ -1217,11 +1217,11 @@ "calculationDuplicate": "Vous avez déjà une catégorie {name} avec ces réglages", "calculationLocked": "Le calcul ne peut pas être modifié. Supprimez la catégorie pour arrêter de la calculer.", "calculationMissingHeight": "La taille manque dans votre profil, aucune valeur ne peut donc encore être calculée.", - "calculationNoSourceCategory": "Vous n'avez pas encore d'autre catégorie à lire.", + "calculationNoSourceCategory": "Vous n'avez pas encore d'autre catégorie dans laquelle puiser.", "calculationBadge": "Calculé", "calculationEntryInfo": "Cette valeur est calculée par wger et ne peut pas être modifiée", "calculationNameBmi": "IMC", - "calculationNameWhtr": "Rapport tour de taille sur taille", + "calculationNameWhtr": "Rapport taille-hauteur", "calculationNameOneRepMax": "1RM", "calculationNameOneRmTotal": "Total 1RM", "calculationDescriptionBmi": "À partir de votre poids et de la taille indiquée dans votre profil", diff --git a/lib/l10n/app_hr.arb b/lib/l10n/app_hr.arb index 941e0736c..5031a74c9 100644 --- a/lib/l10n/app_hr.arb +++ b/lib/l10n/app_hr.arb @@ -1082,9 +1082,9 @@ "@filterNutriscore": { "description": "Heading for the Nutri-Score slider in the ingredient search filter dialog" }, - "filterNutriscoreOff": "Isključeno", - "@filterNutriscoreOff": { - "description": "Label for the first slider stop, which disables the Nutri-Score filter" + "off": "Isključeno", + "@off": { + "description": "Generic label for the option that switches something off, e.g. a filter or a line of a chart" }, "filterNutriscoreNoFilter": "Bez filtra", "@filterNutriscoreNoFilter": { diff --git a/lib/l10n/app_hu.arb b/lib/l10n/app_hu.arb index 0f87adca3..412ddf210 100644 --- a/lib/l10n/app_hu.arb +++ b/lib/l10n/app_hu.arb @@ -1305,9 +1305,9 @@ "@filterNutriscore": { "description": "Heading for the Nutri-Score slider in the ingredient search filter dialog" }, - "filterNutriscoreOff": "Ki", - "@filterNutriscoreOff": { - "description": "Label for the first slider stop, which disables the Nutri-Score filter" + "off": "Ki", + "@off": { + "description": "Generic label for the option that switches something off, e.g. a filter or a line of a chart" }, "filterNutriscoreNoFilter": "Nincs szűrés", "@filterNutriscoreNoFilter": { diff --git a/lib/l10n/app_id.arb b/lib/l10n/app_id.arb index d692e6610..fb5605f6a 100644 --- a/lib/l10n/app_id.arb +++ b/lib/l10n/app_id.arb @@ -1117,9 +1117,9 @@ "@filterNutriscore": { "description": "Heading for the Nutri-Score slider in the ingredient search filter dialog" }, - "filterNutriscoreOff": "Mati", - "@filterNutriscoreOff": { - "description": "Label for the first slider stop, which disables the Nutri-Score filter" + "off": "Mati", + "@off": { + "description": "Generic label for the option that switches something off, e.g. a filter or a line of a chart" }, "filterNutriscoreNoFilter": "Tanpa filter", "@filterNutriscoreNoFilter": { diff --git a/lib/l10n/app_it.arb b/lib/l10n/app_it.arb index fddc9652c..2c79be5c1 100644 --- a/lib/l10n/app_it.arb +++ b/lib/l10n/app_it.arb @@ -1112,9 +1112,9 @@ "@filterNutriscore": { "description": "Heading for the Nutri-Score slider in the ingredient search filter dialog" }, - "filterNutriscoreOff": "Spento", - "@filterNutriscoreOff": { - "description": "Label for the first slider stop, which disables the Nutri-Score filter" + "off": "Spento", + "@off": { + "description": "Generic label for the option that switches something off, e.g. a filter or a line of a chart" }, "filterNutriscoreNoFilter": "Nessun filtro", "@filterNutriscoreNoFilter": { diff --git a/lib/l10n/app_nl.arb b/lib/l10n/app_nl.arb index b0ef13ede..26621c8a8 100644 --- a/lib/l10n/app_nl.arb +++ b/lib/l10n/app_nl.arb @@ -1050,9 +1050,9 @@ }, "editorItalic": "Cursief", "editorList": "Lijst", - "filterNutriscoreOff": "Uit", - "@filterNutriscoreOff": { - "description": "Label for the first slider stop, which disables the Nutri-Score filter" + "off": "Uit", + "@off": { + "description": "Generic label for the option that switches something off, e.g. a filter or a line of a chart" }, "searchModeExact": "Exact", "@searchModeExact": { diff --git a/lib/l10n/app_pt.arb b/lib/l10n/app_pt.arb index 6588a6860..330b94703 100644 --- a/lib/l10n/app_pt.arb +++ b/lib/l10n/app_pt.arb @@ -1004,9 +1004,9 @@ "@filterNutriscore": { "description": "Heading for the Nutri-Score slider in the ingredient search filter dialog" }, - "filterNutriscoreOff": "Desligado", - "@filterNutriscoreOff": { - "description": "Label for the first slider stop, which disables the Nutri-Score filter" + "off": "Desligado", + "@off": { + "description": "Generic label for the option that switches something off, e.g. a filter or a line of a chart" }, "filterNutriscoreNoFilter": "Sem filtro", "@filterNutriscoreNoFilter": { diff --git a/lib/l10n/app_pt_BR.arb b/lib/l10n/app_pt_BR.arb index d6ebd9ce6..da6fa0b07 100644 --- a/lib/l10n/app_pt_BR.arb +++ b/lib/l10n/app_pt_BR.arb @@ -1090,9 +1090,9 @@ "@filterNutriscore": { "description": "Heading for the Nutri-Score slider in the ingredient search filter dialog" }, - "filterNutriscoreOff": "Desligado", - "@filterNutriscoreOff": { - "description": "Label for the first slider stop, which disables the Nutri-Score filter" + "off": "Desligado", + "@off": { + "description": "Generic label for the option that switches something off, e.g. a filter or a line of a chart" }, "filterNutriscoreNoFilter": "Sem filtro", "@filterNutriscoreNoFilter": { diff --git a/lib/l10n/app_sl.arb b/lib/l10n/app_sl.arb index def7511d1..14a7debd4 100644 --- a/lib/l10n/app_sl.arb +++ b/lib/l10n/app_sl.arb @@ -1350,9 +1350,9 @@ "@filterNutriscore": { "description": "Heading for the Nutri-Score slider in the ingredient search filter dialog" }, - "filterNutriscoreOff": "Izklopljeno", - "@filterNutriscoreOff": { - "description": "Label for the first slider stop, which disables the Nutri-Score filter" + "off": "Izklopljeno", + "@off": { + "description": "Generic label for the option that switches something off, e.g. a filter or a line of a chart" }, "filterNutriscoreNoFilter": "Brez filtra", "@filterNutriscoreNoFilter": { diff --git a/lib/l10n/app_zh_Hant.arb b/lib/l10n/app_zh_Hant.arb index f3b61a969..62a08ddd4 100644 --- a/lib/l10n/app_zh_Hant.arb +++ b/lib/l10n/app_zh_Hant.arb @@ -991,9 +991,9 @@ "@filterNutriscore": { "description": "Heading for the Nutri-Score slider in the ingredient search filter dialog" }, - "filterNutriscoreOff": "關閉", - "@filterNutriscoreOff": { - "description": "Label for the first slider stop, which disables the Nutri-Score filter" + "off": "關閉", + "@off": { + "description": "Generic label for the option that switches something off, e.g. a filter or a line of a chart" }, "filterNutriscoreNoFilter": "不套用篩選", "@filterNutriscoreNoFilter": { diff --git a/test/features/measurements/models/measurement_category_test.dart b/test/features/measurements/models/measurement_category_test.dart index 4213b2fb3..1a21cabbe 100644 --- a/test/features/measurements/models/measurement_category_test.dart +++ b/test/features/measurements/models/measurement_category_test.dart @@ -112,6 +112,18 @@ void main() { expect(withConfig({'average_window': 'a fortnight'}).chartSettings.averageWindow, 7); }); + test('a line the user turned off has no period and no window', () { + expect(withConfig({'trend': 'none'}).chartSettings.trend.emaPeriod, isNull); + expect(withConfig({'average_window': 'none'}).chartSettings.averageWindow, isNull); + }); + + test('turning one line off leaves the other alone', () { + final settings = withConfig({'trend': 'none', 'average_window': 14}).chartSettings; + + expect(settings.trend, TrendCharacter.none); + expect(settings.averageWindow, 14); + }); + test('a setting is changed without dropping the keys of another client', () { final category = withConfig({'goal_line': 75}).withChartSetting('trend', 'reactive'); @@ -119,8 +131,8 @@ void main() { }); test('the trend character maps to the EMA period the chart uses', () { - expect(TrendCharacter.reactive.emaPeriod, lessThan(TrendCharacter.balanced.emaPeriod)); - expect(TrendCharacter.sluggish.emaPeriod, greaterThan(TrendCharacter.balanced.emaPeriod)); + expect(TrendCharacter.reactive.emaPeriod, lessThan(TrendCharacter.balanced.emaPeriod!)); + expect(TrendCharacter.sluggish.emaPeriod, greaterThan(TrendCharacter.balanced.emaPeriod!)); }); }); diff --git a/test/features/measurements/widgets/forms/category_test.dart b/test/features/measurements/widgets/forms/category_test.dart index 51f072b97..b60ba1517 100644 --- a/test/features/measurements/widgets/forms/category_test.dart +++ b/test/features/measurements/widgets/forms/category_test.dart @@ -158,7 +158,7 @@ void main() { await tester.pumpAndSettle(); expect(find.byType(DropdownButtonFormField), findsOneWidget); - expect(find.byType(DropdownButtonFormField), findsOneWidget); + expect(find.byType(DropdownButtonFormField), findsOneWidget); }); testWidgets('a summed type has no line to configure', (tester) async { @@ -171,7 +171,7 @@ void main() { await tester.pumpAndSettle(); expect(find.byType(DropdownButtonFormField), findsNothing); - expect(find.byType(DropdownButtonFormField), findsNothing); + expect(find.byType(DropdownButtonFormField), findsNothing); }); testWidgets('the line settings are disabled for a chart without a line', (tester) async { @@ -193,14 +193,40 @@ void main() { ); expect( tester - .widget>( - find.byType(DropdownButtonFormField), + .widget>( + find.byType(DropdownButtonFormField), ) .onChanged, isNull, ); }); + testWidgets('both lines of the chart can be turned off', (tester) async { + final category = getMeasurementCategories()[1].copyWith(chartType: ChartType.auto); + stubMeasurementReads(mockRepo, [category]); + + await tester.pumpWidget(wrap(MeasurementCategoryForm(category))); + await tester.pumpAndSettle(); + + await tester.tap(find.byType(DropdownButtonFormField)); + await tester.pumpAndSettle(); + await tester.tap(find.text('Off').last); + await tester.pumpAndSettle(); + + await tester.tap(find.byType(DropdownButtonFormField)); + await tester.pumpAndSettle(); + await tester.tap(find.text('Off').last); + await tester.pumpAndSettle(); + + await tester.tap(find.byType(ElevatedButton)); + await tester.pumpAndSettle(); + + final saved = + verify(mockRepo.updateLocalDriftCategory(captureAny)).captured.single + as MeasurementCategory; + expect(saved.chartConfig, {'trend': 'none', 'average_window': 'none'}); + }); + testWidgets('the line settings are enabled while the chart is a line', (tester) async { final category = getMeasurementCategories()[1].copyWith(chartType: ChartType.auto); stubMeasurementReads(mockRepo, [category]);