Commit bf394319 authored by Stefan Haslinger's avatar Stefan Haslinger

enforce heartRate zone schema input in wizard

parent 12e9c7fd
import 'package:encrateia/models/heart_rate_zone_schema.dart';
import 'package:encrateia/screens/onboarding_screens/onboarding_body_weight_screen.dart';
import 'package:encrateia/utils/my_button.dart';
import 'package:encrateia/utils/my_color.dart';
......@@ -20,6 +21,14 @@ class OnBoardingHeartRateZoneSchemaScreen extends StatefulWidget {
class _OnBoardingHeartRateZoneSchemaScreenState
extends State<OnBoardingHeartRateZoneSchemaScreen> {
bool heartRateZoneSchemaHasBeenEntered = false;
@override
void initState() {
getData();
super.initState();
}
@override
Widget build(BuildContext context) {
return WillPopScope(
......@@ -33,7 +42,10 @@ class _OnBoardingHeartRateZoneSchemaScreenState
body: SafeArea(
child: Column(
children: <Widget>[
AthleteHeartRateZoneSchemaWidget(athlete: widget.athlete),
AthleteHeartRateZoneSchemaWidget(
athlete: widget.athlete,
callBackFunction: getData,
),
const Padding(
padding: EdgeInsets.only(left: 20, right: 20),
child:
......@@ -43,17 +55,8 @@ class _OnBoardingHeartRateZoneSchemaScreenState
Row(mainAxisAlignment: MainAxisAlignment.end, children: <Widget>[
MyButton.save(
child: const Text('Next step'),
onPressed: () async {
await widget.athlete.save();
Navigator.pushReplacement(
context,
MaterialPageRoute<BuildContext>(
builder: (BuildContext _) => OnBoardingBodyWeightScreen(
athlete: widget.athlete,
),
),
);
},
onPressed:
heartRateZoneSchemaHasBeenEntered ? nextButton : null,
),
const SizedBox(width: 20),
]),
......@@ -64,4 +67,23 @@ class _OnBoardingHeartRateZoneSchemaScreenState
),
);
}
Future<void> getData() async {
final List<HeartRateZoneSchema> heartRateZoneSchemas =
await widget.athlete.heartRateZoneSchemas;
setState(() =>
heartRateZoneSchemaHasBeenEntered = heartRateZoneSchemas.isNotEmpty);
}
Future<void> nextButton() async {
await widget.athlete.save();
Navigator.pushReplacement(
context,
MaterialPageRoute<BuildContext>(
builder: (BuildContext _) => OnBoardingBodyWeightScreen(
athlete: widget.athlete,
),
),
);
}
}
......@@ -7,9 +7,13 @@ import 'package:encrateia/utils/icon_utils.dart';
import 'package:intl/intl.dart';
class AthleteHeartRateZoneSchemaWidget extends StatefulWidget {
const AthleteHeartRateZoneSchemaWidget({this.athlete});
const AthleteHeartRateZoneSchemaWidget({
this.athlete,
this.callBackFunction,
});
final Athlete athlete;
final Function callBackFunction;
@override
_AthleteHeartRateZoneSchemaWidgetState createState() =>
......@@ -72,7 +76,8 @@ class _AthleteHeartRateZoneSchemaWidgetState
await Navigator.push(
context,
MaterialPageRoute<BuildContext>(
builder: (BuildContext context) => AddHeartRateZoneSchemaScreen(
builder: (BuildContext context) =>
AddHeartRateZoneSchemaScreen(
heartRateZoneSchema: heartRateZoneSchema,
),
),
......@@ -94,7 +99,8 @@ class _AthleteHeartRateZoneSchemaWidgetState
await Navigator.push(
context,
MaterialPageRoute<BuildContext>(
builder: (BuildContext context) => AddHeartRateZoneSchemaScreen(
builder: (BuildContext context) =>
AddHeartRateZoneSchemaScreen(
heartRateZoneSchema:
HeartRateZoneSchema(athlete: widget.athlete),
),
......@@ -149,7 +155,8 @@ You could also create a schema from scratch.
await Navigator.push(
context,
MaterialPageRoute<BuildContext>(
builder: (BuildContext context) => AddHeartRateZoneSchemaScreen(
builder: (BuildContext context) =>
AddHeartRateZoneSchemaScreen(
heartRateZoneSchema:
HeartRateZoneSchema(athlete: widget.athlete),
),
......@@ -171,12 +178,15 @@ You could also create a schema from scratch.
Future<void> getData() async {
final Athlete athlete = widget.athlete;
heartRateZoneSchemas = await athlete.heartRateZoneSchemas;
if (widget.callBackFunction != null)
await widget.callBackFunction();
setState(() {});
}
Future<void> likeGarmin() async {
final Athlete athlete = widget.athlete;
final HeartRateZoneSchema heartRateZoneSchema = HeartRateZoneSchema.likeGarmin(athlete: athlete);
final HeartRateZoneSchema heartRateZoneSchema =
HeartRateZoneSchema.likeGarmin(athlete: athlete);
await heartRateZoneSchema.save();
await heartRateZoneSchema.addGarminZones();
await getData();
......
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