Commit 4f89544c authored by Stefan Haslinger's avatar Stefan Haslinger

refactor edit athlete sceens to use EditStravaAthleteWidget and EditStandaloneAthleteWidget part 2

parent f68c1ba9
import 'package:encrateia/utils/my_button.dart';
import 'package:encrateia/utils/my_color.dart';
import 'package:flushbar/flushbar.dart';
import 'package:encrateia/widgets/athlete_widgets/edit_standalone_athlete_widget.dart';
import 'package:flutter/material.dart';
import 'package:encrateia/models/athlete.dart';
import 'onboarding_power_zone_schema_screen.dart';
class OnBoardingStandaloneCredentialsScreen extends StatefulWidget {
class OnBoardingStandaloneCredentialsScreen extends StatelessWidget {
const OnBoardingStandaloneCredentialsScreen({
Key key,
this.athlete,
......@@ -13,15 +11,6 @@ class OnBoardingStandaloneCredentialsScreen extends StatefulWidget {
final Athlete athlete;
@override
_OnBoardingStandaloneCredentialsScreenState createState() =>
_OnBoardingStandaloneCredentialsScreenState();
}
class _OnBoardingStandaloneCredentialsScreenState
extends State<OnBoardingStandaloneCredentialsScreen> {
Flushbar<Object> flushbar = Flushbar<Object>();
@override
Widget build(BuildContext context) {
return Scaffold(
......@@ -29,45 +18,7 @@ class _OnBoardingStandaloneCredentialsScreenState
backgroundColor: MyColor.athlete,
title: const Text('Enter the Athlete\'s Name'),
),
body: ListView(
padding: const EdgeInsets.all(20),
children: <Widget>[
TextFormField(
decoration: const InputDecoration(labelText: 'First name'),
initialValue: widget.athlete.firstName,
onChanged: (String value) => widget.athlete.firstName = value,
),
TextFormField(
decoration: const InputDecoration(labelText: 'Last name'),
initialValue: widget.athlete.lastName,
onChanged: (String value) => widget.athlete.lastName = value,
),
// Cancel and Save Card
Padding(
padding: const EdgeInsets.all(15),
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
MyButton.save(
onPressed: () async {
await widget.athlete.save();
Navigator.pushReplacement(
context,
MaterialPageRoute<BuildContext>(
builder: (BuildContext _) =>
OnBoardingPowerZoneSchemaScreen(
athlete: widget.athlete,
),
),
);
},
),
],
),
),
],
),
body: EditStandaloneAthleteWidget(athlete: athlete),
);
}
}
import 'package:encrateia/screens/onboarding_screens/onboarding_power_zone_schema_screen.dart';
import 'package:encrateia/utils/my_button.dart';
import 'package:flushbar/flushbar.dart';
import 'package:flutter/material.dart';
import 'package:encrateia/models/athlete.dart';
import 'package:encrateia/models/power_zone_schema.dart';
import 'package:encrateia/utils/icon_utils.dart';
class EditStandaloneAthleteWidget extends StatefulWidget {
......@@ -13,52 +15,54 @@ class EditStandaloneAthleteWidget extends StatefulWidget {
final Athlete athlete;
@override
_EditStandaloneAthleteWidgetState createState() => _EditStandaloneAthleteWidgetState();
_EditStandaloneAthleteWidgetState createState() =>
_EditStandaloneAthleteWidgetState();
}
class _EditStandaloneAthleteWidgetState extends State<EditStandaloneAthleteWidget> {
class _EditStandaloneAthleteWidgetState
extends State<EditStandaloneAthleteWidget> {
Flushbar<Object> flushbar = Flushbar<Object>();
@override
Widget build(BuildContext context) {
return ListView(
padding: const EdgeInsets.all(20),
children: <Widget>[
Card(
child: ListTile(
leading: MyIcon.running,
title: const Text('Enter Your Name'),
),
),
TextFormField(
decoration: const InputDecoration(labelText: 'First name'),
initialValue: widget.athlete.firstName,
onChanged: (String value) => widget.athlete.firstName = value,
),
TextFormField(
decoration: const InputDecoration(labelText: 'Last name'),
initialValue: widget.athlete.lastName,
onChanged: (String value) => widget.athlete.lastName = value,
padding: const EdgeInsets.all(20),
children: <Widget>[
Card(
child: ListTile(
leading: MyIcon.running,
title: const Text('Enter Your Name'),
),
),
TextFormField(
decoration: const InputDecoration(labelText: 'First name'),
initialValue: widget.athlete.firstName,
onChanged: (String value) => widget.athlete.firstName = value,
),
TextFormField(
decoration: const InputDecoration(labelText: 'Last name'),
initialValue: widget.athlete.lastName,
onChanged: (String value) => widget.athlete.lastName = value,
),
// Cancel and Save Card
Padding(
padding: const EdgeInsets.all(15),
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
MyButton.cancel(
onPressed: () => Navigator.of(context).pop(),
),
Container(width: 20.0),
MyButton.save(
onPressed: () => saveStandaloneUser(context),
),
],
),
// Cancel and Save Card
Padding(
padding: const EdgeInsets.all(15),
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
MyButton.cancel(
onPressed: () => Navigator.of(context).pop(),
),
Container(width: 20.0),
MyButton.save(
onPressed: () => saveStandaloneUser(context),
),
],
),
],
);
),
],
);
}
Future<void> saveStandaloneUser(BuildContext context) async {
......@@ -67,6 +71,18 @@ class _EditStandaloneAthleteWidgetState extends State<EditStandaloneAthleteWidge
widget.athlete.lastName =
widget.athlete.lastName ?? widget.athlete.lastName;
await widget.athlete.save();
Navigator.of(context).pop();
final List<PowerZoneSchema> powerZoneSchemas =
await widget.athlete.powerZoneSchemas;
if (powerZoneSchemas.isEmpty)
Navigator.pushReplacement(
context,
MaterialPageRoute<BuildContext>(
builder: (BuildContext _) =>
OnBoardingPowerZoneSchemaScreen(athlete: widget.athlete),
),
);
else
Navigator.of(context).pop();
}
}
import 'package:encrateia/models/strava_fit_download.dart';
import 'package:encrateia/screens/onboarding_screens/onboarding_power_zone_schema_screen.dart';
import 'package:encrateia/utils/my_button.dart';
import 'package:flushbar/flushbar.dart';
import 'package:flutter/material.dart';
import 'package:encrateia/models/athlete.dart';
import 'package:encrateia/models/power_zone_schema.dart';
import 'package:encrateia/utils/icon_utils.dart';
class EditStravaAthleteWidget extends StatefulWidget {
......@@ -14,7 +16,8 @@ class EditStravaAthleteWidget extends StatefulWidget {
final Athlete athlete;
@override
_EditStravaAthleteWidgetState createState() => _EditStravaAthleteWidgetState();
_EditStravaAthleteWidgetState createState() =>
_EditStravaAthleteWidgetState();
}
class _EditStravaAthleteWidgetState extends State<EditStravaAthleteWidget> {
......@@ -23,61 +26,61 @@ class _EditStravaAthleteWidgetState extends State<EditStravaAthleteWidget> {
@override
Widget build(BuildContext context) {
return ListView(
padding: const EdgeInsets.all(20),
children: <Widget>[
Card(
child: ListTile(
leading: MyIcon.website,
title: const Text(
'Credentials for .fit-Download from Strava Web Site'),
),
),
ListTile(
leading: const Text('First Name'),
title: Text(widget.athlete.firstName ?? 't.b.d.'),
),
ListTile(
leading: const Text('Last Name'),
title: Text(widget.athlete.lastName ?? 't.b.d.'),
),
ListTile(
leading: const Text('Strava ID'),
title: Text(widget.athlete.stravaId?.toString() ?? 't.b.d.'),
),
ListTile(
leading: const Text('Strava Username'),
title: Text(widget.athlete.stravaUsername ?? 't.b.d.'),
),
TextFormField(
decoration: const InputDecoration(labelText: 'Email'),
initialValue: widget.athlete.email,
onChanged: (String value) => widget.athlete.email = value,
),
TextFormField(
decoration: const InputDecoration(labelText: 'Password'),
onChanged: (String value) => widget.athlete.password = value,
initialValue: widget.athlete.password,
obscureText: true,
padding: const EdgeInsets.all(20),
children: <Widget>[
Card(
child: ListTile(
leading: MyIcon.website,
title: const Text(
'Credentials for .fit-Download from Strava Web Site'),
),
),
ListTile(
leading: const Text('First Name'),
title: Text(widget.athlete.firstName ?? 't.b.d.'),
),
ListTile(
leading: const Text('Last Name'),
title: Text(widget.athlete.lastName ?? 't.b.d.'),
),
ListTile(
leading: const Text('Strava ID'),
title: Text(widget.athlete.stravaId?.toString() ?? 't.b.d.'),
),
ListTile(
leading: const Text('Strava Username'),
title: Text(widget.athlete.stravaUsername ?? 't.b.d.'),
),
TextFormField(
decoration: const InputDecoration(labelText: 'Email'),
initialValue: widget.athlete.email,
onChanged: (String value) => widget.athlete.email = value,
),
TextFormField(
decoration: const InputDecoration(labelText: 'Password'),
onChanged: (String value) => widget.athlete.password = value,
initialValue: widget.athlete.password,
obscureText: true,
),
// Cancel and Save Card
Padding(
padding: const EdgeInsets.all(15),
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
MyButton.cancel(
onPressed: () => Navigator.of(context).pop(),
),
Container(width: 20.0),
MyButton.save(
onPressed: () => saveStravaUser(context),
),
],
),
// Cancel and Save Card
Padding(
padding: const EdgeInsets.all(15),
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
MyButton.cancel(
onPressed: () => Navigator.of(context).pop(),
),
Container(width: 20.0),
MyButton.save(
onPressed: () => saveStravaUser(context),
),
],
),
],
);
),
],
);
}
Future<void> saveStravaUser(BuildContext context) async {
......@@ -89,13 +92,24 @@ class _EditStravaAthleteWidgetState extends State<EditStravaAthleteWidget> {
duration: const Duration(seconds: 10),
)..show(context);
if (await StravaFitDownload.credentialsAreValid(athlete: widget.athlete)) {
await flushbar.dismiss();
Navigator.of(context).pop();
final List<PowerZoneSchema> powerZoneSchemas =
await widget.athlete.powerZoneSchemas;
if (powerZoneSchemas.isEmpty)
Navigator.pushReplacement(
context,
MaterialPageRoute<BuildContext>(
builder: (BuildContext _) =>
OnBoardingPowerZoneSchemaScreen(athlete: widget.athlete),
),
);
else
Navigator.of(context).pop();
} else
flushbar = Flushbar<Object>(
icon: MyIcon.error,
message: 'The credentials provided are invalid!',
duration: const Duration(seconds: 10),
)..show(context);
await flushbar.dismiss();
flushbar = Flushbar<Object>(
icon: MyIcon.error,
message: 'The credentials provided are invalid!',
duration: const Duration(seconds: 10),
)..show(context);
}
}
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