Commit 8f0440ac authored by Administrator's avatar Administrator

downloaded first activity summary, persistet and displayed

parent 76cdabf1
......@@ -35,8 +35,7 @@ class Activity extends Model {
name: name,
movingTime: movingTime.inSeconds,
type: type,
startDateTime: startDateTime.toIso8601String(),
distance: distance
distance: distance,
);
await dbActivity.save();
}
......@@ -55,9 +54,9 @@ class Activity extends Model {
final now = DateTime
.now()
.microsecondsSinceEpoch ~/ 1000;
.millisecondsSinceEpoch ~/ 1000;
final startDate = now - 7 * 86400;
final startDate = now - 2 * 86400;
List<SummaryActivity> summaryActivities = await strava
.getLoggedInAthleteActivities(now, startDate);
......
import 'package:encrateia/models/activity.dart';
import 'package:flutter/material.dart';
import 'package:encrateia/model/model.dart';
import 'package:encrateia/utils/db.dart';
class ListActivitiesScreen extends StatefulWidget {
final DbAthlete athlete;
......@@ -11,21 +12,61 @@ class ListActivitiesScreen extends StatefulWidget {
}
class _ListActivitiesScreenState extends State<ListActivitiesScreen> {
Future<List<DbActivity>> activities;
@override
void initState() {
Db.create().connect();
activities = DbActivity().select().toList();
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Activities'),
),
body: ListView(
padding: EdgeInsets.all(20),
children: <Widget>[
ListTile(
leading: Icon(Icons.cloud_download),
title: Text("Download Activities from Strava"),
onTap: () {Activity.queryStrava(); },
)
],
body: FutureBuilder<List<DbActivity>>(
future: activities,
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done &&
snapshot.data.length > 0) {
return ListView(
padding: EdgeInsets.all(20),
children: <Widget>[
ListTile(
leading: Icon(Icons.cloud_download),
title: Text("Download Activities from Strava"),
onTap: () {
Activity.queryStrava();
},
),
for (DbActivity activity in snapshot.data)
ListTile(
leading: Icon(Icons.person),
title: Text("${activity.type} "
"${activity.stravaId}"),
subtitle: Text(activity.name),
trailing: Text(activity.state),
)
],
);
} else {
return ListView(
padding: EdgeInsets.all(20),
children: <Widget>[
ListTile(
leading: Icon(Icons.cloud_download),
title: Text("Download Activities from Strava"),
onTap: () {
Activity.queryStrava();
},
),
],
);
}
},
),
);
}
......
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