Commit 8d222dd5 authored by Stefan Haslinger's avatar Stefan Haslinger

replace all Providers and all Models by Statefull Widgets

parent 68af2e76
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"flutter_secure_storage","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_secure_storage-3.3.3/","dependencies":[]},{"name":"path_provider","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.8/","dependencies":[]},{"name":"shared_preferences","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.5.7+2/","dependencies":[]},{"name":"sqflite","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.0+1/","dependencies":[]},{"name":"uni_links","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/uni_links-0.4.0/","dependencies":[]},{"name":"url_launcher","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher-5.4.7/","dependencies":[]}],"android":[{"name":"flutter_secure_storage","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_secure_storage-3.3.3/","dependencies":[]},{"name":"path_provider","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.8/","dependencies":[]},{"name":"shared_preferences","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.5.7+2/","dependencies":[]},{"name":"sqflite","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.0+1/","dependencies":[]},{"name":"uni_links","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/uni_links-0.4.0/","dependencies":[]},{"name":"url_launcher","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher-5.4.7/","dependencies":[]}],"macos":[{"name":"path_provider_macos","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_macos-0.0.4+2/","dependencies":[]},{"name":"shared_preferences_macos","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_macos-0.0.1+8/","dependencies":[]},{"name":"sqflite","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.0+1/","dependencies":[]},{"name":"url_launcher_macos","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_macos-0.0.1+5/","dependencies":[]}],"linux":[],"windows":[],"web":[{"name":"shared_preferences_web","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_web-0.1.2+5/","dependencies":[]},{"name":"url_launcher_web","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_web-0.1.1+5/","dependencies":[]}]},"dependencyGraph":[{"name":"flutter_secure_storage","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_macos"]},{"name":"path_provider_macos","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_macos","shared_preferences_web"]},{"name":"shared_preferences_macos","dependencies":[]},{"name":"shared_preferences_web","dependencies":[]},{"name":"sqflite","dependencies":[]},{"name":"uni_links","dependencies":[]},{"name":"url_launcher","dependencies":["url_launcher_web","url_launcher_macos"]},{"name":"url_launcher_macos","dependencies":[]},{"name":"url_launcher_web","dependencies":[]}],"date_created":"2020-06-07 18:10:44.190546","version":"1.17.0-4.0.pre.7"}
\ No newline at end of file
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"flutter_secure_storage","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_secure_storage-3.3.3/","dependencies":[]},{"name":"path_provider","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.8/","dependencies":[]},{"name":"shared_preferences","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.5.7+2/","dependencies":[]},{"name":"sqflite","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.0+1/","dependencies":[]},{"name":"uni_links","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/uni_links-0.4.0/","dependencies":[]},{"name":"url_launcher","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher-5.4.7/","dependencies":[]}],"android":[{"name":"flutter_secure_storage","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_secure_storage-3.3.3/","dependencies":[]},{"name":"path_provider","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.8/","dependencies":[]},{"name":"shared_preferences","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.5.7+2/","dependencies":[]},{"name":"sqflite","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.0+1/","dependencies":[]},{"name":"uni_links","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/uni_links-0.4.0/","dependencies":[]},{"name":"url_launcher","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher-5.4.7/","dependencies":[]}],"macos":[{"name":"path_provider_macos","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_macos-0.0.4+2/","dependencies":[]},{"name":"shared_preferences_macos","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_macos-0.0.1+8/","dependencies":[]},{"name":"sqflite","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.0+1/","dependencies":[]},{"name":"url_launcher_macos","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_macos-0.0.1+5/","dependencies":[]}],"linux":[],"windows":[],"web":[{"name":"shared_preferences_web","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_web-0.1.2+5/","dependencies":[]},{"name":"url_launcher_web","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_web-0.1.1+5/","dependencies":[]}]},"dependencyGraph":[{"name":"flutter_secure_storage","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_macos"]},{"name":"path_provider_macos","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_macos","shared_preferences_web"]},{"name":"shared_preferences_macos","dependencies":[]},{"name":"shared_preferences_web","dependencies":[]},{"name":"sqflite","dependencies":[]},{"name":"uni_links","dependencies":[]},{"name":"url_launcher","dependencies":["url_launcher_web","url_launcher_macos"]},{"name":"url_launcher_macos","dependencies":[]},{"name":"url_launcher_web","dependencies":[]}],"date_created":"2020-06-08 11:09:31.053989","version":"1.17.0-4.0.pre.7"}
\ No newline at end of file
......@@ -27,7 +27,7 @@ import 'bar_zone.dart';
import 'heart_rate_zone.dart';
import 'heart_rate_zone_schema.dart';
class Activity extends ChangeNotifier {
class Activity {
Activity();
Activity.fromDb(this.db);
......@@ -143,7 +143,6 @@ class Activity extends ChangeNotifier {
Future<void> setState(String state) async {
db.state = state;
await db.save();
notifyListeners();
}
String distanceString() {
......@@ -282,7 +281,6 @@ class Activity extends ChangeNotifier {
db.state = 'persisted';
await recalculateAverages();
await db.save();
notifyListeners();
print('Activity data for »${db.name}« stored in database.');
yield 100;
}
......
......@@ -4,7 +4,7 @@ import 'package:flutter/material.dart';
import 'package:encrateia/model/model.dart' show DbActivityTagging;
import 'package:sqfentity_gen/sqfentity_gen.dart';
class ActivityTagging extends ChangeNotifier {
class ActivityTagging {
ActivityTagging({
@required Activity activity,
@required Tag tag,
......
import 'dart:io';
import 'package:encrateia/models/power_zone_schema.dart';
import 'package:encrateia/models/tag_group.dart';
import 'package:flutter/material.dart';
import 'package:encrateia/model/model.dart' show DbAthlete;
import 'package:path_provider/path_provider.dart';
import 'package:strava_flutter/Models/detailedAthlete.dart';
......@@ -10,7 +9,7 @@ import 'package:encrateia/models/weight.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'heart_rate_zone_schema.dart';
class Athlete extends ChangeNotifier {
class Athlete {
Athlete();
Athlete.fromDb(this.db);
......@@ -19,7 +18,7 @@ class Athlete extends ChangeNotifier {
String firstName;
String lastName;
DbAthlete db = DbAthlete();
List<int> filters = <int> [];
List<int> filters = <int>[];
@override
String toString() =>
......@@ -36,7 +35,6 @@ class Athlete extends ChangeNotifier {
..state = 'fromStrava'
..downloadInterval = 21
..recordAggregationCount = 16;
notifyListeners();
}
Future<void> setupStandaloneAthlete() async {
......@@ -47,7 +45,6 @@ class Athlete extends ChangeNotifier {
..downloadInterval = 21
..recordAggregationCount = 16;
await db.save();
notifyListeners();
}
String get stateText {
......@@ -67,14 +64,12 @@ class Athlete extends ChangeNotifier {
const FlutterSecureStorage storage = FlutterSecureStorage();
await storage.write(key: 'email', value: email);
await storage.write(key: 'password', value: password);
notifyListeners();
}
Future<void> readCredentials() async {
const FlutterSecureStorage storage = FlutterSecureStorage();
email = await storage.read(key: 'email');
password = await storage.read(key: 'password');
notifyListeners();
}
static Future<List<Athlete>> all() async {
......@@ -105,13 +100,9 @@ class Athlete extends ChangeNotifier {
}
await db.getDbActivities().delete();
await db.delete();
notifyListeners();
}
Future<void> save() async {
await db.save();
notifyListeners();
}
Future<void> save() async => await db.save();
Future<bool> checkForSchemas() async =>
(await powerZoneSchemas).isNotEmpty &&
......
......@@ -3,7 +3,7 @@ import 'package:encrateia/model/model.dart' show DbHeartRateZone;
import 'package:encrateia/models/heart_rate_zone_schema.dart';
import 'package:sqfentity_gen/sqfentity_gen.dart';
class HeartRateZone extends ChangeNotifier {
class HeartRateZone {
HeartRateZone(
{@required HeartRateZoneSchema heartRateZoneSchema,
String name,
......
......@@ -4,7 +4,7 @@ import 'package:encrateia/model/model.dart' show DbHeartRateZoneSchema;
import 'package:encrateia/models/athlete.dart';
import 'package:sqfentity_gen/sqfentity_gen.dart';
class HeartRateZoneSchema extends ChangeNotifier {
class HeartRateZoneSchema {
HeartRateZoneSchema({@required Athlete athlete}) {
db = DbHeartRateZoneSchema()
..athletesId = athlete.db.id
......
......@@ -4,7 +4,7 @@ import 'package:flutter/material.dart';
import 'package:encrateia/model/model.dart' show DbLapTagging;
import 'package:sqfentity_gen/sqfentity_gen.dart';
class LapTagging extends ChangeNotifier {
class LapTagging {
LapTagging({
@required Lap lap,
@required Tag tag,
......
......@@ -3,7 +3,7 @@ import 'package:encrateia/model/model.dart' show DbPowerZone;
import 'package:encrateia/models/power_zone_schema.dart';
import 'package:sqfentity_gen/sqfentity_gen.dart';
class PowerZone extends ChangeNotifier {
class PowerZone {
PowerZone(
{@required PowerZoneSchema powerZoneSchema,
String name,
......
......@@ -4,7 +4,7 @@ import 'package:encrateia/model/model.dart' show DbPowerZoneSchema;
import 'package:encrateia/models/athlete.dart';
import 'package:sqfentity_gen/sqfentity_gen.dart';
class PowerZoneSchema extends ChangeNotifier {
class PowerZoneSchema {
PowerZoneSchema({@required Athlete athlete}) {
db = DbPowerZoneSchema()
..athletesId = athlete.db.id
......
......@@ -2,11 +2,10 @@ import 'package:flutter/material.dart';
import 'package:encrateia/model/model.dart' show DbTag, DbActivityTagging;
import 'package:encrateia/models/tag_group.dart';
import 'package:sqfentity_gen/sqfentity_gen.dart' show BoolResult;
import 'activity.dart';
import 'athlete.dart';
class Tag extends ChangeNotifier {
class Tag {
Tag({
@required TagGroup tagGroup,
String name,
......
......@@ -8,7 +8,7 @@ import 'package:encrateia/models/activity.dart';
import 'package:sqfentity_gen/sqfentity_gen.dart' show BoolResult;
import 'lap.dart';
class TagGroup extends ChangeNotifier {
class TagGroup {
TagGroup({@required Athlete athlete}) {
db = DbTagGroup()
..athletesId = athlete.db.id
......
......@@ -3,7 +3,7 @@ import 'package:encrateia/model/model.dart';
import 'package:encrateia/models/athlete.dart';
import 'package:sqfentity_gen/sqfentity_gen.dart';
class Weight extends ChangeNotifier {
class Weight {
Weight({@required Athlete athlete}) {
db = DbWeight()
..athletesId = athlete.db.id
......
......@@ -2,11 +2,10 @@ import 'package:encrateia/utils/my_button.dart';
import 'package:encrateia/utils/my_color.dart';
import 'package:flutter/material.dart';
import 'package:encrateia/models/athlete.dart';
import 'package:provider/provider.dart';
import 'package:encrateia/utils/icon_utils.dart';
import 'strava_get_user.dart';
class EditAthleteScreen extends StatelessWidget {
class EditAthleteScreen extends StatefulWidget {
const EditAthleteScreen({
Key key,
this.athlete,
......@@ -14,6 +13,11 @@ class EditAthleteScreen extends StatelessWidget {
final Athlete athlete;
@override
_EditAthleteScreenState createState() => _EditAthleteScreenState();
}
class _EditAthleteScreenState extends State<EditAthleteScreen> {
@override
Widget build(BuildContext context) {
return Scaffold(
......@@ -21,13 +25,7 @@ class EditAthleteScreen extends StatelessWidget {
backgroundColor: MyColor.athlete,
title: const Text('Create Athlete'),
),
body: ChangeNotifierProvider<Athlete>.value(
value: athlete,
child: Consumer<Athlete>(
builder: (BuildContext context, Athlete athlete, Widget _child) =>
editAthleteForm(athlete, context),
),
),
body: editAthleteForm(widget.athlete, context),
);
}
......@@ -45,23 +43,15 @@ class EditAthleteScreen extends StatelessWidget {
ListTile(
leading: MyIcon.download,
title: const Text('Option 1: Strava Connection'),
subtitle:
const Text('Choose this option, if you want to download most '
'of the activities from Strava'),
subtitle: const 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<BuildContext>(
builder: (BuildContext context) =>
StravaGetUser(athlete: athlete),
),
);
},
onPressed: () => stravaGetUser(context),
)
],
),
......@@ -75,8 +65,9 @@ class EditAthleteScreen extends StatelessWidget {
ListTile(
leading: MyIcon.upload,
title: const Text('Option 2: Standalone User'),
subtitle: const Text('Choose this option, if you want to upload all'
' .fit-files manually'),
subtitle:
const Text('Choose this option, if you want to upload all'
' .fit-files manually'),
),
ButtonBar(
children: <Widget>[
......@@ -137,8 +128,8 @@ class EditAthleteScreen extends StatelessWidget {
Card(
child: ListTile(
leading: MyIcon.website,
title:
const Text('Step 2 of 2: Credentials for Strava Web Site scraping'),
title: const Text(
'Step 2 of 2: Credentials for Strava Web Site scraping'),
),
),
ListTile(
......@@ -191,16 +182,28 @@ class EditAthleteScreen extends StatelessWidget {
}
Future<void> saveStravaUser(BuildContext context) async {
await athlete.db.save();
await athlete.storeCredentials();
await widget.athlete.db.save();
await widget.athlete.storeCredentials();
Navigator.of(context).pop();
}
Future<void> saveStandaloneUser(BuildContext context) async {
athlete.db.firstName = athlete.firstName ?? athlete.db.firstName;
athlete.db.lastName = athlete.lastName ?? athlete.db.lastName;
await athlete.save();
widget.athlete.db.firstName =
widget.athlete.firstName ?? widget.athlete.db.firstName;
widget.athlete.db.lastName =
widget.athlete.lastName ?? widget.athlete.db.lastName;
await widget.athlete.save();
Navigator.of(context).pop();
}
Future<void> stravaGetUser(BuildContext context) async {
await Navigator.push(
context,
MaterialPageRoute<BuildContext>(
builder: (BuildContext context) =>
StravaGetUser(athlete: widget.athlete),
),
);
setState(() {});
}
}
......@@ -2,38 +2,38 @@ import 'package:encrateia/utils/my_color.dart';
import 'package:flutter/material.dart';
import 'package:encrateia/secrets/secrets.dart';
import 'package:strava_flutter/strava.dart';
import 'package:provider/provider.dart';
import 'package:encrateia/models/athlete.dart';
import 'package:strava_flutter/Models/detailedAthlete.dart';
class StravaGetUser extends StatelessWidget {
class StravaGetUser extends StatefulWidget {
const StravaGetUser({this.athlete});
String get title => 'Strava Login';
final Athlete athlete;
@override
_StravaGetUserState createState() => _StravaGetUserState();
}
class _StravaGetUserState extends State<StravaGetUser> {
String get title => 'Strava Login';
@override
void initState() {
getData();
super.initState();
}
@override
Widget build(BuildContext context) {
return ChangeNotifierProvider<Athlete>.value(
value: athlete,
child: Scaffold(
appBar: AppBar(
title: const Text('Create Athlete'),
backgroundColor: MyColor.primary,
),
body: Consumer<Athlete>(
builder: (BuildContext context, Athlete athlete, Widget _child) {
if (athlete.db.firstName == null)
loginToStrava();
if (athlete.db.state == 'fromStrava')
Navigator.of(context).pop();
return Container(
child: Padding(
padding: const EdgeInsets.all(20),
child: Text(athlete.stateText),
),
);
},
return Scaffold(
appBar: AppBar(
title: const Text('Create Athlete'),
backgroundColor: MyColor.primary,
),
body: Container(
child: Padding(
padding: const EdgeInsets.all(20),
child: Text(widget.athlete.stateText),
),
),
);
......@@ -49,6 +49,15 @@ class StravaGetUser extends StatelessWidget {
secret,
prompt);
final DetailedAthlete stravaAthlete = await strava.getLoggedInAthlete();
athlete.updateFromStravaAthlete(stravaAthlete);
widget.athlete.updateFromStravaAthlete(stravaAthlete);
}
Future<void> getData() async {
if (widget.athlete.db.firstName == null) {
await loginToStrava();
setState((){});
}
if (widget.athlete.db.state == 'fromStrava')
Navigator.of(context).pop();
}
}
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