Commit 6d92e127 authored by Administrator's avatar Administrator

implemented dataTable for Laps

parent c667c3a9
......@@ -6,6 +6,7 @@ import 'activity.dart';
class Lap {
DbLap db;
Activity activity;
int index;
Lap({DataMessage dataMessage, this.activity, int eventId}) {
db = DbLap()
......@@ -47,4 +48,21 @@ class Lap {
..totalFractionalCycles = dataMessage.get('total_fractional_cycles')
..save();
}
Lap.fromDb(this.db);
static Future<List<Lap>> by({Activity activity}) async {
int counter = 1;
List<DbLap> dbLapList = await activity.db.getDbLaps().toList();
var lapList = dbLapList.map((dbLap) => Lap.fromDb(dbLap)).toList();
await Future.forEach(lapList, (lap) async {
var dbActivity = await lap.db.getDbActivity();
lap.activity = Activity.fromDb(dbActivity);
lap.index = counter;
counter = counter +1;
});
return lapList;
}
}
import 'package:flutter/material.dart';
import 'package:encrateia/models/activity.dart';
import 'package:encrateia/models/lap.dart';
class LapsListWidget extends StatelessWidget {
final Activity activity;
......@@ -8,6 +9,58 @@ class LapsListWidget extends StatelessWidget {
@override
Widget build(context) {
return new Text("Second Tab");
return FutureBuilder<List<Lap>>(
future: Lap.by(activity: activity),
builder: (BuildContext context, AsyncSnapshot<List<Lap>> snapshot) {
Widget widget;
if (snapshot.hasData) {
widget = DataTable(
columns: <DataColumn>[
const DataColumn(label: Icon(Icons.loop), tooltip: 'Lap'),
const DataColumn(label: Text("bpm"), tooltip: 'heartrate'),
const DataColumn(label: Text("km/h"), tooltip: 'speed'),
const DataColumn(
label: Icon(Icons.trending_up), tooltip: 'ascent'),
],
rows: snapshot.data.map((Lap lap) {
return DataRow(key: Key(lap.db.id.toString()), cells: [
DataCell(
Text(lap.index.toString()),
),
DataCell(
Text(lap.db.avgHeartRate.toString()),
),
DataCell(
Text((lap.db.avgSpeed * 3.6).toStringAsFixed(2)),
),
DataCell(
Text((lap.db.totalAscent - lap.db.totalDescent).toString()),
),
]);
}).toList(),
);
} else {
widget = Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SizedBox(
child: CircularProgressIndicator(),
width: 60,
height: 60,
),
const Padding(
padding: EdgeInsets.only(top: 16),
child: Text('Loading...'),
)
],
),
);
}
return widget;
},
);
}
}
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