Commit fe55e2aa authored by Administrator's avatar Administrator

store data in scoped model

parents 48e4d8c2 87533844
......@@ -32,7 +32,6 @@ android {
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.informatom.encrateia"
minSdkVersion 16
targetSdkVersion 28
......
import 'package:flutter/material.dart';
import 'screens/edit_athlete.dart';
import 'screens/dashboard.dart';
void main() => runApp(MyApp());
......@@ -16,70 +16,3 @@ class MyApp extends StatelessWidget {
}
}
class Dashboard extends StatelessWidget {
final String title;
Widget widget;
Dashboard({this.title});
@override
Widget build(BuildContext context) {
if (true) {
widget = 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) => EditAthleteScreen()),
);
},
)
],
))
],
))
]);
}
return Scaffold(
appBar: AppBar(
title: Text(title),
),
body: widget);
}
}
......@@ -15,6 +15,11 @@ class Athlete extends Model {
static const String tableName = '_athlete';
String toString() => '$firstName ($id)';
void setData({firstName}) {
this.firstName = firstName;
notifyListeners();
}
}
@GenBean()
......
import 'package:flutter/material.dart';
import 'edit_athlete.dart';
import 'package:scoped_model/scoped_model.dart';
import 'package:encrateia/models/athlete.dart';
class Dashboard extends StatelessWidget {
final String title;
Dashboard({this.title});
@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())),
);
},
)
],
))
],
))
]));
}
}
import 'package:flutter/material.dart';
import 'package:encrateia/models/athlete.dart';
import 'package:scoped_model/scoped_model.dart';
import 'strava/strava_get_user.dart';
class EditAthleteScreen extends StatelessWidget {
......@@ -15,17 +14,14 @@ class EditAthleteScreen extends StatelessWidget {
appBar: AppBar(
title: Text('Create Athlete'),
),
body: ScopedModel<Athlete>(
model: athlete,
child: ScopedModelDescendant<Athlete>(
builder: (context, child, athlete) =>
body:
ListView(padding: EdgeInsets.all(20), children: <
Widget>[
TextField(
onChanged: (value) => athlete.firstName = value,
decoration: InputDecoration(labelText: 'First Name')),
// Strava Connection
// Strava Connection Card
Card(
child: Column(
mainAxisSize: MainAxisSize.min,
......@@ -45,7 +41,7 @@ class EditAthleteScreen extends StatelessWidget {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => StravaGetUser(athlete)),
builder: (context) => StravaGetUser(athlete: athlete)),
);
},
)
......@@ -54,7 +50,7 @@ class EditAthleteScreen extends StatelessWidget {
],
)),
// Cancel and Save
// Cancel and Save Card
Padding(
padding: EdgeInsets.only(top: 15.0, bottom: 15.0),
child: Row(
......@@ -85,6 +81,6 @@ class EditAthleteScreen extends StatelessWidget {
),
],
)),
])))));
])));
}
}
......@@ -4,42 +4,40 @@ import 'package:strava_flutter/strava.dart';
import 'package:scoped_model/scoped_model.dart';
import 'package:encrateia/models/athlete.dart';
class StravaGetUser extends StatefulWidget {
class StravaGetUser extends StatelessWidget {
final String title = "Strava Login";
Athlete athlete;
StravaGetUser(this.athlete) {}
@override
_StravaGetUserState createState() => _StravaGetUserState();
}
class _StravaGetUserState extends State<StravaGetUser> {
Strava strava;
@override
void initState() {
loginToStrava();
super.initState();
}
StravaGetUser({this.athlete});
@override
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: () {
Navigator.pop(context, true);
},
child: Scaffold(
appBar: AppBar(title: Text('Create Athlete')),
body: ScopedModelDescendant<Athlete>(
builder: (context, child, model) {
widget.athlete = model;
Container(child: Text("Athlete ${widget.athlete.firstName}"));
})));
return ScopedModel<Athlete>(
model: athlete,
child: WillPopScope(
onWillPop: () {
Navigator.pop(context, true);
},
child: Scaffold(
appBar: AppBar(title: Text('Create Athlete')),
body: ScopedModelDescendant<Athlete>(
builder: (context, child, athlete) {
if (strava == null) {
loginToStrava();
};
return Container(child:
Text("Athlete ${athlete.firstName}")
);
}
)
)
)
);
}
loginToStrava() async {
strava = Strava(true, secret);
this.strava = Strava(true, secret);
final prompt = 'auto';
final auth = await strava.oauth(
......@@ -50,8 +48,6 @@ class _StravaGetUserState extends State<StravaGetUser> {
print(auth);
final stravaAthlete = await strava.getLoggedInAthlete();
setState(() {
widget.athlete.firstName = stravaAthlete.firstname;
});
athlete.setData(firstName: stravaAthlete.firstname);
}
}
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
# See https://www.dartlang.org/tools/pub/glossary#lockfile
packages:
analyzer:
dependency: transitive
......@@ -28,7 +28,7 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.2.0"
version: "2.1.0"
boolean_selector:
dependency: transitive
description:
......@@ -105,7 +105,7 @@ packages:
name: checked_yaml
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.2"
version: "1.0.1"
code_builder:
dependency: transitive
description:
......@@ -353,14 +353,14 @@ packages:
name: pedantic
url: "https://pub.dartlang.org"
source: hosted
version: "1.7.0"
version: "1.5.0"
petitparser:
dependency: transitive
description:
name: petitparser
url: "https://pub.dartlang.org"
source: hosted
version: "2.4.0"
version: "2.2.1"
plugin:
dependency: transitive
description:
......@@ -395,7 +395,7 @@ packages:
name: quiver
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.3"
version: "2.0.2"
scoped_model:
dependency: "direct main"
description:
......@@ -505,7 +505,7 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.5"
version: "0.2.4"
timing:
dependency: transitive
description:
......@@ -554,7 +554,7 @@ packages:
name: xml
url: "https://pub.dartlang.org"
source: hosted
version: "3.5.0"
version: "3.4.1"
yaml:
dependency: transitive
description:
......@@ -563,5 +563,5 @@ packages:
source: hosted
version: "2.1.16"
sdks:
dart: ">=2.4.0 <3.0.0"
dart: ">=2.2.0 <3.0.0"
flutter: ">=1.5.0 <2.0.0"
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