mirror of
https://github.com/wger-project/flutter.git
synced 2026-02-18 23:42:00 +01:00
Refactor weight chart to be used with the measurement entries
This commit is contained in:
@@ -258,7 +258,9 @@ class _DashboardWeightWidgetState extends State<DashboardWeightWidget> {
|
|||||||
? Container(
|
? Container(
|
||||||
padding: EdgeInsets.all(15),
|
padding: EdgeInsets.all(15),
|
||||||
height: 180,
|
height: 180,
|
||||||
child: WeightChartWidget(weightEntriesData.items),
|
child: WeightChartWidget(weightEntriesData.items
|
||||||
|
.map((e) => MeasurementChartEntry(e.weight, e.date))
|
||||||
|
.toList()),
|
||||||
)
|
)
|
||||||
: NothingFound(
|
: NothingFound(
|
||||||
AppLocalizations.of(context).noWeightEntries,
|
AppLocalizations.of(context).noWeightEntries,
|
||||||
|
|||||||
@@ -18,14 +18,20 @@
|
|||||||
|
|
||||||
import 'package:charts_flutter/flutter.dart' as charts;
|
import 'package:charts_flutter/flutter.dart' as charts;
|
||||||
import 'package:flutter/widgets.dart';
|
import 'package:flutter/widgets.dart';
|
||||||
import 'package:wger/models/body_weight/weight_entry.dart';
|
|
||||||
import 'package:wger/theme/theme.dart';
|
import 'package:wger/theme/theme.dart';
|
||||||
|
|
||||||
|
class MeasurementChartEntry {
|
||||||
|
num value;
|
||||||
|
DateTime date;
|
||||||
|
|
||||||
|
MeasurementChartEntry(this.value, this.date);
|
||||||
|
}
|
||||||
|
|
||||||
/// Weight chart widget
|
/// Weight chart widget
|
||||||
class WeightChartWidget extends StatelessWidget {
|
class WeightChartWidget extends StatelessWidget {
|
||||||
final List<WeightEntry> _entries;
|
final List<MeasurementChartEntry> _entries;
|
||||||
|
|
||||||
/// [_entries] is a list of [WeightEntry] as returned e.g. by the
|
/// [_entries] is a list of [MeasurementChartEntry] as returned e.g. by the
|
||||||
/// [BodyWeight] provider.
|
/// [BodyWeight] provider.
|
||||||
WeightChartWidget(this._entries);
|
WeightChartWidget(this._entries);
|
||||||
|
|
||||||
@@ -33,11 +39,11 @@ class WeightChartWidget extends StatelessWidget {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return charts.TimeSeriesChart(
|
return charts.TimeSeriesChart(
|
||||||
[
|
[
|
||||||
charts.Series<WeightEntry, DateTime>(
|
charts.Series<MeasurementChartEntry, DateTime>(
|
||||||
id: 'Weight',
|
id: 'Weight',
|
||||||
colorFn: (_, __) => wgerChartSecondaryColor,
|
colorFn: (_, __) => wgerChartSecondaryColor,
|
||||||
domainFn: (WeightEntry weightEntry, _) => weightEntry.date,
|
domainFn: (MeasurementChartEntry entry, _) => entry.date,
|
||||||
measureFn: (WeightEntry weightEntry, _) => weightEntry.weight,
|
measureFn: (MeasurementChartEntry entry, _) => entry.value,
|
||||||
data: _entries,
|
data: _entries,
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -35,7 +35,8 @@ class WeightEntriesList extends StatelessWidget {
|
|||||||
Container(
|
Container(
|
||||||
padding: EdgeInsets.all(15),
|
padding: EdgeInsets.all(15),
|
||||||
height: 220,
|
height: 220,
|
||||||
child: WeightChartWidget(_weightProvider.items),
|
child: WeightChartWidget(
|
||||||
|
_weightProvider.items.map((e) => MeasurementChartEntry(e.weight, e.date)).toList()),
|
||||||
),
|
),
|
||||||
Divider(),
|
Divider(),
|
||||||
Expanded(
|
Expanded(
|
||||||
|
|||||||
Reference in New Issue
Block a user