Commit 0027fad5 authored by Administrator's avatar Administrator

swiping between laps for lap detail views

parent 8a99595d
import 'package:encrateia/models/lap.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
class ShowLapDetailScreen extends StatelessWidget {
class ShowLapDetailScreen extends StatefulWidget {
final Lap lap;
final Widget widget;
final List<Lap> laps;
final Function({Lap lap}) nextWidget;
final String title;
const ShowLapDetailScreen({
Key key,
@required this.lap,
this.widget,
this.title,
@required this.laps,
@required this.nextWidget,
@required this.title,
}) : super(key: key);
@override
_ShowLapDetailScreenState createState() => _ShowLapDetailScreenState();
}
class _ShowLapDetailScreenState extends State<ShowLapDetailScreen> {
Lap currentLap;
double dragAmount = 0;
@override
void initState() {
currentLap = widget.lap;
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
'Lap ${lap.index.toString()}: $title',
'Lap ${currentLap.index.toString()}: ${widget.title}',
overflow: TextOverflow.ellipsis,
),
),
body: widget,
body: GestureDetector(
child: widget.nextWidget(lap: currentLap),
onHorizontalDragUpdate: (details) {
dragAmount = dragAmount + details.primaryDelta;
},
onHorizontalDragEnd: (details) {
if (dragAmount < -50) {
dragAmount = 0;
if (currentLap.index < widget.laps.length) {
setState(() => currentLap = widget.laps[currentLap.index - 1 + 1]);
}
} else if (dragAmount > 50) {
dragAmount = 0;
if (currentLap.index > 1) {
setState(
() => currentLap = widget.laps[currentLap.index - 1 - 1]);
}
}
},
),
);
}
}
......@@ -16,10 +16,12 @@ import 'package:encrateia/utils/icon_utils.dart';
class ShowLapScreen extends StatelessWidget {
final Lap lap;
final List<Lap> laps;
const ShowLapScreen({
Key key,
this.lap,
@required this.lap,
@required this.laps,
}) : super(key: key);
@override
......@@ -45,70 +47,70 @@ class ShowLapScreen extends StatelessWidget {
color: MyColor.navigate,
icon: MyIcon.metaData,
context: context,
nextWidget: LapOverviewWidget(lap: lap),
nextWidget: ({lap}) => LapOverviewWidget(lap: lap),
),
navigationButton(
title: "Heart Rate",
color: MyColor.navigate,
icon: MyIcon.heartRate,
context: context,
nextWidget: LapHeartRateWidget(lap: lap),
nextWidget: ({lap}) => LapHeartRateWidget(lap: lap),
),
navigationButton(
title: "Power",
color: MyColor.navigate,
icon: MyIcon.power,
context: context,
nextWidget: LapPowerWidget(lap: lap),
nextWidget: ({lap}) => LapPowerWidget(lap: lap),
),
navigationButton(
title: "Power Duration",
color: MyColor.navigate,
icon: MyIcon.powerDuration,
context: context,
nextWidget: LapPowerDurationWidget(lap: lap),
nextWidget: ({lap}) => LapPowerDurationWidget(lap: lap),
),
navigationButton(
title: "Ground Time",
color: MyColor.navigate,
icon: MyIcon.groundTime,
context: context,
nextWidget: LapGroundTimeWidget(lap: lap),
nextWidget: ({lap}) => LapGroundTimeWidget(lap: lap),
),
navigationButton(
title: "Leg Spring Stiffness",
color: MyColor.navigate,
icon: MyIcon.legSpringStiffness,
context: context,
nextWidget: LapLegSpringStiffnessWidget(lap: lap),
nextWidget: ({lap}) => LapLegSpringStiffnessWidget(lap: lap),
),
navigationButton(
title: "Form Power",
color: MyColor.navigate,
icon: MyIcon.formPower,
context: context,
nextWidget: LapFormPowerWidget(lap: lap),
nextWidget: ({lap}) => LapFormPowerWidget(lap: lap),
),
navigationButton(
title: "Cadence",
color: MyColor.navigate,
icon: MyIcon.cadence,
context: context,
nextWidget: LapStrydCadenceWidget(lap: lap),
nextWidget: ({lap}) => LapStrydCadenceWidget(lap: lap),
),
navigationButton(
title: "Vertical Oscillation",
color: MyColor.navigate,
icon: MyIcon.verticalOscillation,
context: context,
nextWidget: LapVerticalOscillationWidget(lap: lap),
nextWidget: ({lap}) => LapVerticalOscillationWidget(lap: lap),
),
navigationButton(
title: "Metadata",
color: MyColor.navigate,
icon: MyIcon.metaData,
context: context,
nextWidget: LapMetadataWidget(lap: lap),
nextWidget: ({lap}) => LapMetadataWidget(lap: lap),
),
],
);
......@@ -118,7 +120,7 @@ class ShowLapScreen extends StatelessWidget {
navigationButton({
@required BuildContext context,
@required Widget nextWidget,
@required Function({Lap lap}) nextWidget,
@required Widget icon,
@required String title,
@required Color color,
......@@ -134,7 +136,8 @@ class ShowLapScreen extends StatelessWidget {
MaterialPageRoute(
builder: (context) => ShowLapDetailScreen(
lap: lap,
widget: nextWidget,
laps: laps,
nextWidget: nextWidget,
title: title,
),
),
......
......@@ -25,6 +25,12 @@ class _LapFormPowerWidgetState extends State<LapFormPowerWidget> {
super.initState();
}
@override
void didUpdateWidget(oldWidget) {
getData();
super.didUpdateWidget(oldWidget);
}
@override
Widget build(context) {
if (records.length > 0) {
......
......@@ -25,6 +25,12 @@ class _LapGroundTimeWidgetState extends State<LapGroundTimeWidget> {
super.initState();
}
@override
void didUpdateWidget(oldWidget) {
getData();
super.didUpdateWidget(oldWidget);
}
@override
Widget build(context) {
if (records.length > 0) {
......
......@@ -28,6 +28,12 @@ class _LapHeartRateWidgetState extends State<LapHeartRateWidget> {
super.initState();
}
@override
void didUpdateWidget(oldWidget) {
getData();
super.didUpdateWidget(oldWidget);
}
@override
Widget build(context) {
if (records.length > 0) {
......
......@@ -27,6 +27,12 @@ class _LapLegSpringStiffnessWidgetState
super.initState();
}
@override
void didUpdateWidget(oldWidget) {
getData();
super.didUpdateWidget(oldWidget);
}
@override
Widget build(context) {
if (records.length > 0) {
......
import 'package:flutter/material.dart';
import 'package:encrateia/models/lap.dart';
import 'package:encrateia/models/event.dart';
import '../charts/power_duration_chart.dart';
import 'package:encrateia/widgets/charts/power_duration_chart.dart';
class LapPowerDurationWidget extends StatelessWidget {
class LapPowerDurationWidget extends StatefulWidget {
final Lap lap;
LapPowerDurationWidget({this.lap});
LapPowerDurationWidget({@required this.lap});
@override
_LapPowerDurationWidgetState createState() => _LapPowerDurationWidgetState();
}
class _LapPowerDurationWidgetState extends State<LapPowerDurationWidget> {
List<Event> records = [];
@override
void initState() {
getData();
super.initState();
}
@override
void didUpdateWidget(oldWidget) {
getData();
super.didUpdateWidget(oldWidget);
}
@override
Widget build(context) {
return FutureBuilder<List<Event>>(
future: lap.records,
builder: (BuildContext context, AsyncSnapshot<List<Event>> snapshot) {
if (snapshot.hasData) {
var powerRecords = snapshot.data
.where((value) => value.db.power != null && value.db.power > 100)
.toList();
if (powerRecords.length > 0) {
return SingleChildScrollView(
child: PowerDurationChart(records: powerRecords),
);
} else {
return Center(
child: Text("No power data available."),
);
}
} else {
return Center(
child: Text("Loading"),
);
}
},
);
if (records.length > 0) {
var powerRecords = records
.where((value) => value.db.power != null && value.db.power > 100)
.toList();
if (powerRecords.length > 0) {
return SingleChildScrollView(
child: PowerDurationChart(records: powerRecords),
);
} else {
return Center(
child: Text("No power data available."),
);
}
} else {
return Center(
child: Text("Loading"),
);
}
}
getData() async {
records = await widget.lap.records;
setState(() {});
}
}
......@@ -31,6 +31,12 @@ class _LapPowerWidgetState extends State<LapPowerWidget> {
super.initState();
}
@override
void didUpdateWidget(oldWidget) {
getData();
super.didUpdateWidget(oldWidget);
}
@override
Widget build(context) {
if (records.length > 0) {
......
......@@ -25,6 +25,12 @@ class _LapStrydCadenceWidgetState extends State<LapStrydCadenceWidget> {
super.initState();
}
@override
void didUpdateWidget(oldWidget) {
getData();
super.didUpdateWidget(oldWidget);
}
@override
Widget build(context) {
if (records.length > 0) {
......
......@@ -27,6 +27,12 @@ class _LapVerticalOscillationWidgetState
super.initState();
}
@override
void didUpdateWidget(oldWidget) {
getData();
super.didUpdateWidget(oldWidget);
}
@override
Widget build(context) {
if (records.length > 0) {
......
......@@ -16,6 +16,7 @@ class LapsListWidget extends StatelessWidget {
future: Lap.by(activity: activity),
builder: (BuildContext context, AsyncSnapshot<List<Lap>> snapshot) {
if (snapshot.hasData) {
List<Lap> laps = snapshot.data;
return SingleChildScrollView(
child: DataTable(
dataRowHeight: kMinInteractiveDimension * 0.60,
......@@ -48,7 +49,7 @@ class LapsListWidget extends StatelessWidget {
numeric: true,
),
],
rows: snapshot.data.map((Lap lap) {
rows: laps.map((Lap lap) {
return DataRow(
key: Key(lap.db.id.toString()),
onSelectChanged: (bool selected) {
......@@ -56,7 +57,10 @@ class LapsListWidget extends StatelessWidget {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ShowLapScreen(lap: lap),
builder: (context) => ShowLapScreen(
lap: lap,
laps: laps,
),
),
);
}
......
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