Commit 83ea88e7 authored by Administrator's avatar Administrator

alitude on lap level

parent acc9a9db
......@@ -7,6 +7,7 @@ import 'package:encrateia/widgets/lap_widgets/lap_overview_widget.dart';
import 'package:encrateia/widgets/lap_widgets/lap_heart_rate_widget.dart';
import 'package:encrateia/widgets/lap_widgets/lap_pace_widget.dart';
import 'package:encrateia/widgets/lap_widgets/lap_power_widget.dart';
import 'package:encrateia/widgets/lap_widgets/lap_altitude_widget.dart';
import 'package:encrateia/widgets/lap_widgets/lap_power_duration_widget.dart';
import 'package:encrateia/widgets/lap_widgets/lap_ground_time_widget.dart';
import 'package:encrateia/widgets/lap_widgets/lap_leg_spring_stiffness_widget.dart';
......@@ -113,6 +114,13 @@ class ShowLapScreen extends StatelessWidget {
context: context,
nextWidget: ({Lap lap}) => LapVerticalOscillationWidget(lap: lap),
),
navigationButton(
title: 'Altitude',
color: MyColor.navigate,
icon: MyIcon.altitude,
context: context,
nextWidget: ({Lap lap}) => LapAltitudeWidget(lap: lap),
),
navigationButton(
title: 'Metadata',
color: MyColor.settings,
......
import 'package:charts_flutter/flutter.dart';
import 'package:encrateia/models/record_list.dart';
import 'package:flutter/material.dart';
import 'package:encrateia/models/event.dart';
import 'package:encrateia/utils/graph_utils.dart';
class LapAltitudeChart extends StatelessWidget {
const LapAltitudeChart({
@required this.records,
@required this.minimum,
@required this.maximum,
});
final RecordList<Event> records;
final double minimum;
final double maximum;
@override
Widget build(BuildContext context) {
final int offset = records.first.distance.round();
final List<Series<Event, int>> data = <Series<Event, int>>[
Series<Event, int>(
id: 'Altitude',
colorFn: (_, __) => Color.black,
domainFn: (Event record, _) => record.distance.round() - offset,
measureFn: (Event record, _) => record.altitude,
data: records,
)
];
return Container(
height: 300,
child: LineChart(
data,
defaultRenderer: LineRendererConfig<num>(
includeArea: true,
),
primaryMeasureAxis: NumericAxisSpec(
tickProviderSpec: const BasicNumericTickProviderSpec(
zeroBound: false,
dataIsInWholeNumbers: false,
desiredTickCount: 5,
),
viewport: NumericExtents(minimum, maximum),
),
behaviors: GraphUtils.axis(
measureTitle: 'Altitude (m)',
),
),
);
}
}
import 'dart:math';
import 'package:encrateia/models/record_list.dart';
import 'package:flutter/material.dart';
import 'package:encrateia/models/lap.dart';
import 'package:encrateia/widgets/charts/lap_charts/lap_altitude_chart.dart';
import 'package:encrateia/utils/icon_utils.dart';
import 'package:encrateia/models/event.dart';
class LapAltitudeWidget extends StatefulWidget {
const LapAltitudeWidget({this.lap});
final Lap lap;
@override
_LapAltitudeWidgetState createState() => _LapAltitudeWidgetState();
}
class _LapAltitudeWidgetState extends State<LapAltitudeWidget> {
RecordList<Event> records = RecordList<Event>(<Event>[]);
@override
void initState() {
getData();
super.initState();
}
@override
void didUpdateWidget(LapAltitudeWidget oldWidget) {
getData();
super.didUpdateWidget(oldWidget);
}
@override
Widget build(BuildContext context) {
if (records.isNotEmpty) {
final List<Event> altitudeRecords =
records.where((Event value) => value.altitude != null).toList();
if (altitudeRecords.isNotEmpty) {
return ListTileTheme(
iconColor: Colors.lightGreen,
child: ListView(
padding: const EdgeInsets.only(left: 25),
children: <Widget>[
LapAltitudeChart(
records: RecordList<Event>(altitudeRecords),
minimum: altitudeRecords
.map((Event record) => record.altitude)
.reduce(min)
.toDouble(),
maximum: altitudeRecords
.map((Event record) => record.altitude)
.reduce(max)
.toDouble(),
),
const Text(
'Only records where altitude measurement is present are shown.'),
const Text('Swipe left/write to compare with other laps.'),
const Divider(),
ListTile(
leading: MyIcon.amount,
title: Text(altitudeRecords.length.toString()),
subtitle: const Text('number of measurements'),
),
],
),
);
} else {
return const Center(
child: Text('No altitude data available.'),
);
}
} else {
return const Center(
child: Text('Loading'),
);
}
}
Future<void> getData() async {
final Lap lap = widget.lap;
records = RecordList<Event>(await lap.records);
setState(() {});
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment