From 2ade2013dca09661fdfbe65f46edfb2f7fd80f73 Mon Sep 17 00:00:00 2001 From: burny0202 Date: Sun, 18 May 2025 10:36:24 +0100 Subject: [PATCH 1/3] Interval of 1000 hard crashes, and 1000000 does not. Changing to last date also stops it hitting the 0 difference. Removed unused currentDate #788 --- lib/helpers/charts.dart | 2 +- lib/widgets/measurements/charts.dart | 2 +- lib/widgets/routines/charts.dart | 5 ++--- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/helpers/charts.dart b/lib/helpers/charts.dart index 64a0b6e8..8358715b 100644 --- a/lib/helpers/charts.dart +++ b/lib/helpers/charts.dart @@ -1,5 +1,5 @@ double chartGetInterval(DateTime first, DateTime last, {divider = 3}) { final dayDiff = last.difference(first); - return dayDiff.inMilliseconds == 0 ? 1000 : dayDiff.inMilliseconds.abs() / divider; + return dayDiff.inMilliseconds == 0 ? 1000000 : dayDiff.inMilliseconds.abs() / divider; } diff --git a/lib/widgets/measurements/charts.dart b/lib/widgets/measurements/charts.dart index d2b7876b..9b19fa0f 100644 --- a/lib/widgets/measurements/charts.dart +++ b/lib/widgets/measurements/charts.dart @@ -142,7 +142,7 @@ class _MeasurementChartWidgetFlState extends State { widget._entries.last.date, widget._entries.first.date, ) - : 1000, + : 1000000, ), ), leftTitles: AxisTitles( diff --git a/lib/widgets/routines/charts.dart b/lib/widgets/routines/charts.dart index f0cf66cf..4c1fa362 100644 --- a/lib/widgets/routines/charts.dart +++ b/lib/widgets/routines/charts.dart @@ -27,9 +27,8 @@ import 'package:wger/models/workouts/log.dart'; class LogChartWidgetFl extends StatefulWidget { final Map> _data; - final DateTime _currentDate; - const LogChartWidgetFl(this._data, this._currentDate); + const LogChartWidgetFl(this._data); @override State createState() => _LogChartWidgetFlState(); @@ -112,7 +111,7 @@ class _LogChartWidgetFlState extends State { : DateTime.now(), widget._data.containsKey(widget._data.keys.last) && widget._data[widget._data.keys.last]!.isNotEmpty - ? widget._data[widget._data.keys.last]!.first.date + ? widget._data[widget._data.keys.last]!.last.date : DateTime.now(), // widget._data[widget._data.keys.first]!.first.date, // widget._data[widget._data.keys.last]!.first.date, From 611f552963260da1f62a4700e75322e008f1cd92 Mon Sep 17 00:00:00 2001 From: burny0202 Date: Sun, 18 May 2025 10:39:24 +0100 Subject: [PATCH 2/3] Interval of 1000 hard crashes, and 1000000 does not. Changing to last date also stops it hitting the 0 difference. #788 --- lib/widgets/routines/charts.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/widgets/routines/charts.dart b/lib/widgets/routines/charts.dart index 4c1fa362..7d5e3321 100644 --- a/lib/widgets/routines/charts.dart +++ b/lib/widgets/routines/charts.dart @@ -27,8 +27,9 @@ import 'package:wger/models/workouts/log.dart'; class LogChartWidgetFl extends StatefulWidget { final Map> _data; + final DateTime _currentDate; - const LogChartWidgetFl(this._data); + const LogChartWidgetFl(this._data, this._currentDate); @override State createState() => _LogChartWidgetFlState(); From f18af2ed65cf72801e92456d1fc165cb11405cb2 Mon Sep 17 00:00:00 2001 From: Roland Geider Date: Thu, 22 May 2025 14:33:23 +0200 Subject: [PATCH 3/3] 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. --- lib/helpers/charts.dart | 6 +++++- lib/helpers/consts.dart | 6 ++++++ lib/widgets/measurements/charts.dart | 3 ++- lib/widgets/measurements/helpers.dart | 14 ++++++++------ 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/lib/helpers/charts.dart b/lib/helpers/charts.dart index 8358715b..1a4b1574 100644 --- a/lib/helpers/charts.dart +++ b/lib/helpers/charts.dart @@ -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; } diff --git a/lib/helpers/consts.dart b/lib/helpers/consts.dart index ac39612a..8430184c 100644 --- a/lib/helpers/consts.dart +++ b/lib/helpers/consts.dart @@ -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; diff --git a/lib/widgets/measurements/charts.dart b/lib/widgets/measurements/charts.dart index 9b19fa0f..dc8ffff2 100644 --- a/lib/widgets/measurements/charts.dart +++ b/lib/widgets/measurements/charts.dart @@ -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 { widget._entries.last.date, widget._entries.first.date, ) - : 1000000, + : CHART_MILLISECOND_FACTOR, ), ), leftTitles: AxisTitles( diff --git a/lib/widgets/measurements/helpers.dart b/lib/widgets/measurements/helpers.dart index 111be02f..3881b3a7 100644 --- a/lib/widgets/measurements/helpers.dart +++ b/lib/widgets/measurements/helpers.dart @@ -78,13 +78,15 @@ List 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, + ), ], ), ];