Move milliseconds factor to a constant

This makes it less likely to run into weird bugs if we need to tweak
the value in the future.
This commit is contained in:
Roland Geider
2025-05-22 14:33:23 +02:00
parent 611f552963
commit f18af2ed65
4 changed files with 21 additions and 8 deletions

View File

@@ -1,5 +1,9 @@
import 'consts.dart';
double chartGetInterval(DateTime first, DateTime last, {divider = 3}) {
final dayDiff = last.difference(first);
return dayDiff.inMilliseconds == 0 ? 1000000 : dayDiff.inMilliseconds.abs() / divider;
return dayDiff.inMilliseconds == 0
? CHART_MILLISECOND_FACTOR
: dayDiff.inMilliseconds.abs() / divider;
}

View File

@@ -112,3 +112,9 @@ const COLOR_SECONDARY_MUSCLES = Colors.orange;
// Min account age to contribute exercises. Needs to be kept in sync with
// the value on the backend
const MIN_ACCOUNT_AGE = 14;
/// Factor to multiply / divide in the charts when converting dates to milliseconds
/// from epoch since fl_charts does not support real time series charts and using
/// the milliseconds themselves can cause the application to crash since it runs
/// out of memory...
const double CHART_MILLISECOND_FACTOR = 100000.0;

View File

@@ -20,6 +20,7 @@ import 'package:fl_chart/fl_chart.dart';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:wger/helpers/charts.dart';
import 'package:wger/helpers/consts.dart';
import 'package:wger/l10n/generated/app_localizations.dart';
class MeasurementOverallChangeWidget extends StatelessWidget {
@@ -142,7 +143,7 @@ class _MeasurementChartWidgetFlState extends State<MeasurementChartWidgetFl> {
widget._entries.last.date,
widget._entries.first.date,
)
: 1000000,
: CHART_MILLISECOND_FACTOR,
),
),
leftTitles: AxisTitles(

View File

@@ -78,13 +78,15 @@ List<Widget> getOverviewWidgetsSeries(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Indicator(
color: Theme.of(context).colorScheme.primary,
text: AppLocalizations.of(context).indicatorRaw,
isSquare: true),
color: Theme.of(context).colorScheme.primary,
text: AppLocalizations.of(context).indicatorRaw,
isSquare: true,
),
Indicator(
color: Theme.of(context).colorScheme.tertiary,
text: AppLocalizations.of(context).indicatorAvg,
isSquare: true),
color: Theme.of(context).colorScheme.tertiary,
text: AppLocalizations.of(context).indicatorAvg,
isSquare: true,
),
],
),
];