Commit 6c345c4b authored by Administrator's avatar Administrator

load athletes on startup

parent 43b99cb7
......@@ -11,7 +11,7 @@ class MyApp extends StatelessWidget {
theme: ThemeData(
primarySwatch: Colors.orange, // #ff9800
),
home: Dashboard(title: 'Encrateia Dashboard'),
home: Dashboard(),
);
}
}
......
......@@ -44,6 +44,7 @@ class Athlete extends Model {
persist() async {
await Db.create().connect();
var dbAthlete = DbAthlete(
firstName: firstName,
lastName: lastName,
......@@ -51,7 +52,6 @@ class Athlete extends Model {
stravaUsername: stravaUsername,
photoPath: photoPath);
int id = await dbAthlete.save();
print(id);
}
static Athlete of(BuildContext context) => ScopedModel.of<Athlete>(context);
......
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'edit_athlete.dart';
import 'package:scoped_model/scoped_model.dart';
import 'package:encrateia/models/athlete.dart';
import 'package:encrateia/model/model.dart';
import 'package:encrateia/utils/db.dart';
class Dashboard extends StatelessWidget {
final String title;
class Dashboard extends StatefulWidget {
Dashboard();
Dashboard({this.title});
@override
_DashboardState createState() => _DashboardState();
}
class _DashboardState extends State<Dashboard> {
Future<List<DbAthlete>> athletes;
@override
void initState() {
Db.create().connect();
athletes = DbAthlete().select().toList();
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text(title)),
body: ListView(
padding: EdgeInsets.all(20),
children: <Widget>[
Card(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
ListTile(
leading: Icon(Icons.help),
title: Text('Welcome to Encrateia!'),
subtitle: Text('Maybe you want to learn more about Encrateia.'
'We have provided some introductory help for you.'),
),
ButtonTheme.bar(
child: ButtonBar(
children: <Widget>[
FlatButton(
child: const Text('HELP'),
onPressed: () {},
)
],
),
)
],
),
),
Card(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
ListTile(
leading: Icon(Icons.face),
title: Text('Who are you?'),
subtitle: Text('This app stores date associated to one athlete '
'(you) or many athletes (if you act as a trainer).'
'\n Please create your first athlete!'),
),
ButtonTheme.bar(
child: ButtonBar(
children: <Widget>[
FlatButton(
child: const Text('CREATE NEW ATHLETE'),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ScopedModel<Athlete>(
model: Athlete(),
child: EditAthleteScreen(),
),
appBar: AppBar(title: Text("Encrateia Dashboard")),
body: FutureBuilder<List<DbAthlete>>(
future: athletes,
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
if (snapshot.data.length == 0) {
return ListView(
padding: EdgeInsets.all(20),
children: <Widget>[
Card(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
ListTile(
leading: Icon(Icons.help),
title: Text('Welcome to Encrateia!'),
subtitle: Text(
'Maybe you want to learn more about Encrateia.'
'We have provided some introductory help for you.'),
),
ButtonTheme.bar(
child: ButtonBar(
children: <Widget>[
FlatButton(
child: const Text('HELP'),
onPressed: () {},
)
],
),
)
],
),
),
Card(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
ListTile(
leading: Icon(Icons.face),
title: Text('Who are you?'),
subtitle: Text(
'This app stores date associated to one athlete '
'(you) or many athletes (if you act as a trainer).'
'\n Please create your first athlete!'),
),
);
},
)
],
))
],
))
],
),
ButtonTheme.bar(
child: ButtonBar(
children: <Widget>[
FlatButton(
child: const Text('CREATE NEW ATHLETE'),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ScopedModel<Athlete>(
model: Athlete(),
child: EditAthleteScreen(),
),
),
);
},
)
],
))
],
))
],
);
} else {
return ListView(
padding: EdgeInsets.all(40),
children: <Widget>[
Text(
"Select the athlete to analyze:",
style: Theme.of(context).textTheme.title,
),
for (DbAthlete athlete in snapshot.data)
ListTile(
leading: Image.network(athlete.photoPath),
title:
Text("${athlete.firstName} ${athlete.lastName}"),
subtitle: Text("${athlete.stravaId}"))
],
);
}
;
} else {
return CircularProgressIndicator();
}
}),
);
}
}
......@@ -7,7 +7,7 @@ packages:
name: analyzer
url: "https://pub.dartlang.org"
source: hosted
version: "0.35.4"
version: "0.36.4"
archive:
dependency: transitive
description:
......@@ -98,7 +98,7 @@ packages:
name: built_value
url: "https://pub.dartlang.org"
source: hosted
version: "6.7.0"
version: "6.7.1"
charcode:
dependency: transitive
description:
......@@ -112,7 +112,7 @@ packages:
name: checked_yaml
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.1"
version: "1.0.2"
code_builder:
dependency: transitive
description:
......@@ -140,7 +140,14 @@ packages:
name: crypto
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.1+1"
version: "2.1.3"
csslib:
dependency: transitive
description:
name: csslib
url: "https://pub.dartlang.org"
source: hosted
version: "0.16.1"
cupertino_icons:
dependency: "direct main"
description:
......@@ -154,7 +161,7 @@ packages:
name: dart_style
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.3"
version: "1.2.9"
fixnum:
dependency: transitive
description:
......@@ -173,7 +180,7 @@ packages:
name: flutter_launcher_icons
url: "https://pub.dartlang.org"
source: hosted
version: "0.7.2+1"
version: "0.7.3"
flutter_test:
dependency: "direct dev"
description: flutter
......@@ -185,7 +192,7 @@ packages:
name: front_end
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.14"
version: "0.1.19"
glob:
dependency: transitive
description:
......@@ -200,6 +207,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.0"
html:
dependency: transitive
description:
name: html
url: "https://pub.dartlang.org"
source: hosted
version: "0.14.0+2"
http:
dependency: transitive
description:
......@@ -248,7 +262,7 @@ packages:
name: json_annotation
url: "https://pub.dartlang.org"
source: hosted
version: "2.4.0"
version: "3.0.0"
json_rpc_2:
dependency: transitive
description:
......@@ -262,7 +276,7 @@ packages:
name: kernel
url: "https://pub.dartlang.org"
source: hosted
version: "0.3.14"
version: "0.3.19"
logging:
dependency: transitive
description:
......@@ -311,7 +325,7 @@ packages:
name: package_config
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.5"
version: "1.1.0"
package_resolver:
dependency: transitive
description:
......@@ -332,7 +346,7 @@ packages:
name: path_provider
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
version: "1.3.0"
pedantic:
dependency: transitive
description:
......@@ -346,6 +360,13 @@ packages:
name: petitparser
url: "https://pub.dartlang.org"
source: hosted
version: "2.4.0"
platform:
dependency: transitive
description:
name: platform
url: "https://pub.dartlang.org"
source: hosted
version: "2.2.1"
pool:
dependency: transitive
......@@ -568,7 +589,7 @@ packages:
name: url_launcher
url: "https://pub.dartlang.org"
source: hosted
version: "5.1.2"
version: "5.1.3"
vector_math:
dependency: transitive
description:
......@@ -603,14 +624,14 @@ packages:
name: xml
url: "https://pub.dartlang.org"
source: hosted
version: "3.4.1"
version: "3.5.0"
yaml:
dependency: transitive
description:
name: yaml
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.16"
version: "2.2.0"
sdks:
dart: ">=2.3.0 <3.0.0"
dart: ">=2.4.0 <3.0.0"
flutter: ">=1.5.0 <2.0.0"
......@@ -4,7 +4,7 @@ description: Activity tracker data analysis for Android and iOS
version: 0.0.1
environment:
sdk: ">=2.1.0 <3.0.0"
sdk: ">=2.2.2 <3.0.0"
dependencies:
flutter:
......
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