Commit d955cf80 authored by Administrator's avatar Administrator

allow users without strava connection

parent 8a67c340
......@@ -7,6 +7,8 @@ import 'package:flutter_secure_storage/flutter_secure_storage.dart';
class Athlete extends ChangeNotifier {
String email;
String password;
String firstName;
String lastName;
DbAthlete db = DbAthlete();
Athlete();
......@@ -27,6 +29,15 @@ class Athlete extends ChangeNotifier {
notifyListeners();
}
setupStandaloneAthlete() async {
db
..state = "standalone"
..firstName = "Jane"
..lastName = "Doe";
await db.save();
notifyListeners();
}
String get stateText {
switch (db.state) {
case "new":
......
......@@ -101,9 +101,9 @@ class _DashboardState extends State<Dashboard> {
children: <Widget>[
for (Athlete athlete in athletes)
ListTile(
leading: Image.network(athlete.db.photoPath),
title: Text("${athlete.db.firstName} ${athlete.db.lastName} "
"- ${athlete.db.stravaId}"),
leading: photoOrImage(athlete: athlete),
title: Text(
"${athlete.db.firstName} ${athlete.db.lastName} ${stravaIdString(athlete: athlete)}"),
subtitle: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
......@@ -123,6 +123,20 @@ class _DashboardState extends State<Dashboard> {
}
}
stravaIdString({Athlete athlete}) {
if (athlete.db.stravaId != null)
return "- ${athlete.db.stravaId}";
else
return "";
}
photoOrImage({Athlete athlete}) {
if (athlete.db.photoPath != null)
return Image.network(athlete.db.photoPath);
else
return MyIcon.runningBig;
}
addUserCard() {
return Card(
child: Column(
......
......@@ -29,43 +29,123 @@ class EditAthleteScreen extends StatelessWidget {
}
Widget editAthleteForm(Athlete athlete, BuildContext context) {
if (athlete.db == null || athlete.db.stravaId == null) {
if (athlete.db == null ||
(athlete.db.stravaId == null && athlete.db.state != "standalone")) {
// Strava Connection Card
return Card(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
ListTile(
leading: MyIcon.brokenConnection,
title: Text('Step 1 of 2: Strava Connection'),
subtitle: Text('This athlete is not connected to a '
'Strava User yet'),
return ListView(
padding: EdgeInsets.all(20),
children: <Widget>[
Card(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
ListTile(
leading: MyIcon.download,
title: Text('Option 1: Strava Connection'),
subtitle:
Text('Choose this option, if you want to download most'
'of the activities from Strava'),
),
ButtonBar(
children: <Widget>[
FlatButton(
child: const Text('Connect to Strava'),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
StravaGetUser(athlete: athlete),
),
);
},
)
],
),
],
),
ButtonBar(
),
Card(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
FlatButton(
child: const Text('CONNECT TO STRAVA'),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => StravaGetUser(athlete: athlete),
),
);
},
)
Card(
child: ListTile(
leading: MyIcon.upload,
title: Text('Option 2: Standalone User'),
subtitle:
Text('Choose this option, if you want to upload all'
' .fit-files manually'),
),
),
ButtonBar(
children: <Widget>[
FlatButton(
child: const Text('Create standalone User'),
onPressed: () => athlete.setupStandaloneAthlete(),
)
],
),
],
),
],
),
),
],
);
} else if (athlete.db.state == "standalone") {
return ListView(
padding: EdgeInsets.all(20),
children: <Widget>[
Card(
child: ListTile(
leading: MyIcon.running,
title: Text('Step 2 of 2: Enter Your Name'),
),
),
TextFormField(
decoration: InputDecoration(labelText: "First name"),
initialValue: athlete.db.firstName,
onChanged: (value) => athlete.firstName = value,
),
TextFormField(
decoration: InputDecoration(labelText: "Last name"),
initialValue: athlete.db.lastName,
onChanged: (value) => athlete.lastName = value,
),
// Cancel and Save Card
Padding(
padding: EdgeInsets.all(15),
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
RaisedButton(
color: Theme.of(context).primaryColorDark,
textColor: Theme.of(context).primaryColorLight,
child: Text('Cancel', textScaleFactor: 1.5),
onPressed: () => Navigator.of(context).pop(),
),
Container(width: 20.0),
RaisedButton(
color: Theme.of(context).primaryColorDark,
textColor: Theme.of(context).primaryColorLight,
child: Text('Save', textScaleFactor: 1.5),
onPressed: () => saveStandaloneUser(context),
),
],
),
),
],
);
} else {
return ListView(
padding: EdgeInsets.all(20),
children: <Widget>[
ListTile(
leading: MyIcon.website,
title: Text('Step 2 of 2: Credentials for Strava Web Site scraping'),
Card(
child: ListTile(
leading: MyIcon.website,
title:
Text('Step 2 of 2: Credentials for Strava Web Site scraping'),
),
),
ListTile(
leading: Text("First Name"),
......@@ -112,7 +192,7 @@ class EditAthleteScreen extends StatelessWidget {
color: Theme.of(context).primaryColorDark,
textColor: Theme.of(context).primaryColorLight,
child: Text('Save', textScaleFactor: 1.5),
onPressed: () => save(context),
onPressed: () => saveStravaUser(context),
),
],
),
......@@ -122,9 +202,16 @@ class EditAthleteScreen extends StatelessWidget {
}
}
save (BuildContext context) async {
saveStravaUser(BuildContext context) async {
await athlete.db.save();
await athlete.storeCredentials();
Navigator.of(context).pop();
}
saveStandaloneUser(BuildContext context) async {
athlete.db.firstName = athlete.firstName;
athlete.db.lastName = athlete.lastName;
await athlete.db.save();
Navigator.of(context).pop();
}
}
......@@ -65,6 +65,7 @@ class MyIcon {
// R
static final repeats = Icon(Icons.loop);
static final running = Icon(Icons.directions_run);
static final runningBig = Icon(Icons.directions_run, size: 50);
// S
static final settings = Icon(Icons.settings);
static final show = Icon(Icons.remove_red_eye);
......@@ -83,6 +84,8 @@ class MyIcon {
static final timeStamp = Icon(Icons.access_time);
static final title = Icon(Icons.title);
static final trainingEffect = Icon(Icons.fitness_center);
//
static final upload = Icon(Icons.file_upload);
// V
static final verticalOscillation = Icon(Icons.unfold_more);
// W
......
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