Commit ea388f44 authored by Administrator's avatar Administrator

use same attribute naming as strava

parent 7d1ada8a
......@@ -7,14 +7,14 @@ part 'athlete.jorm.dart';
class Athlete extends Model {
@PrimaryKey()
String id;
String name;
String firstName;
int stravaId;
Athlete();
Athlete.make(this.id, this.name, this.stravaId);
Athlete.make(this.id, this.firstName, this.stravaId);
static const String tableName = '_athlete';
String toString() => '$name ($id)';
String toString() => '$firstName ($id)';
}
@GenBean()
......
......@@ -8,18 +8,18 @@ part of 'athlete.dart';
abstract class _AthleteBean implements Bean<Athlete> {
final id = StrField('id');
final name = StrField('name');
final firstName = StrField('first_name');
final stravaId = IntField('strava_id');
Map<String, Field> _fields;
Map<String, Field> get fields => _fields ??= {
id.name: id,
name.name: name,
firstName.name: firstName,
stravaId.name: stravaId,
};
Athlete fromMap(Map map) {
Athlete model = Athlete();
model.id = adapter.parseValue(map['id']);
model.name = adapter.parseValue(map['name']);
model.firstName = adapter.parseValue(map['first_name']);
model.stravaId = adapter.parseValue(map['strava_id']);
return model;
......@@ -31,18 +31,19 @@ abstract class _AthleteBean implements Bean<Athlete> {
if (only == null && !onlyNonNull) {
ret.add(id.set(model.id));
ret.add(name.set(model.name));
ret.add(firstName.set(model.firstName));
ret.add(stravaId.set(model.stravaId));
} else if (only != null) {
if (only.contains(id.name)) ret.add(id.set(model.id));
if (only.contains(name.name)) ret.add(name.set(model.name));
if (only.contains(firstName.name))
ret.add(firstName.set(model.firstName));
if (only.contains(stravaId.name)) ret.add(stravaId.set(model.stravaId));
} else /* if (onlyNonNull) */ {
if (model.id != null) {
ret.add(id.set(model.id));
}
if (model.name != null) {
ret.add(name.set(model.name));
if (model.firstName != null) {
ret.add(firstName.set(model.firstName));
}
if (model.stravaId != null) {
ret.add(stravaId.set(model.stravaId));
......@@ -55,7 +56,7 @@ abstract class _AthleteBean implements Bean<Athlete> {
Future<void> createTable({bool ifNotExists = false}) async {
final st = Sql.create(tableName, ifNotExists: ifNotExists);
st.addStr(id.name, primary: true, isNullable: false);
st.addStr(name.name, isNullable: false);
st.addStr(firstName.name, isNullable: false);
st.addInt(stravaId.name, isNullable: false);
return adapter.createTable(st);
}
......
......@@ -21,8 +21,8 @@ class EditAthleteScreen extends StatelessWidget {
new ListView(padding: EdgeInsets.all(20), children: <
Widget>[
TextField(
onChanged: (value) => athlete.name = value,
decoration: InputDecoration(labelText: 'Name')),
onChanged: (value) => athlete.firstName = value,
decoration: InputDecoration(labelText: 'First Name')),
// Strava Connection
Card(
......
......@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:encrateia/secrets/secrets.dart';
import 'package:strava_flutter/strava.dart';
import 'package:strava_flutter/Models/detailedAthlete.dart';
import 'package:strava_flutter/Models/activity.dart';
class StravaLogin extends StatefulWidget {
final String title = "Strava Login";
......@@ -15,7 +16,8 @@ class StravaLogin extends StatefulWidget {
class _StravaLoginState extends State<StravaLogin> {
bool isAuthOk = false;
Strava strava;
DetailedAthlete stravaAthlete;
DetailedAthlete athlete;
List<SummaryActivity> activities;
@override
void initState() {
......@@ -34,13 +36,14 @@ class _StravaLoginState extends State<StravaLogin> {
appBar: AppBar(title: Text('Create Athlete')),
body: Container(child:
Text("isAuthOk ${isAuthOk} \n"
"stravaAthlete ${stravaAthlete?.firstname}"))
"stravaAthlete ${athlete?.firstname} \n"
"activities ${activities?.length}"))
)
);
}
loginToStrava() async {
strava = Strava(false, secret);
strava = Strava(true, secret);
final prompt = 'auto';
final auth = await strava.oauth(
......@@ -49,11 +52,17 @@ class _StravaLoginState extends State<StravaLogin> {
secret,
prompt);
print(auth);
final athlete = await strava.getLoggedInAthlete();
final stravaAthlete = await strava.getLoggedInAthlete();
// final now = DateTime.now().microsecondsSinceEpoch ~/ 1000 ;
// final yesterday = now - 1550;
// final stravaActivities = await strava.getLoggedInAthleteActivities(
// now,
// yesterday
// );
setState(() {
isAuthOk = auth;
stravaAthlete = athlete;
athlete = stravaAthlete;
});
}
}
\ No newline at end of file
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