287 lines
14 KiB
Dart
287 lines
14 KiB
Dart
import 'dart:collection';
|
|
|
|
import 'package:aitrainer_app/bloc/exercise_control_form_bloc.dart';
|
|
import 'package:aitrainer_app/localization/app_language.dart';
|
|
import 'package:aitrainer_app/localization/app_localization.dart';
|
|
import 'package:aitrainer_app/repository/exercise_repository.dart';
|
|
import 'package:aitrainer_app/widgets/splash.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_form_bloc/flutter_form_bloc.dart';
|
|
|
|
class ExerciseControlPage extends StatefulWidget {
|
|
_ExerciseControlPage createState() => _ExerciseControlPage();
|
|
}
|
|
|
|
class _ExerciseControlPage extends State<ExerciseControlPage> {
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
LinkedHashMap arguments = ModalRoute.of(context).settings.arguments;
|
|
final ExerciseRepository exerciseRepository = arguments['exerciseRepository'];
|
|
final double percent = arguments['percent'];
|
|
final bool readonly = arguments['readonly'];
|
|
|
|
return BlocProvider(
|
|
create: (context) => ExerciseControlFormBloc(
|
|
exerciseRepository: exerciseRepository, percentToCalculate: percent, readonly: readonly),
|
|
child: BlocBuilder<ExerciseControlFormBloc, FormBlocState>(builder: (context, state) {
|
|
// ignore: close_sinks
|
|
final exerciseBloc = BlocProvider.of<ExerciseControlFormBloc>(context);
|
|
if (state is FormBlocLoading) {
|
|
return LoadingDialog();
|
|
} else if (state is FormBlocSuccess) {
|
|
return getControlForm(exerciseBloc);
|
|
} else {
|
|
return getControlForm(exerciseBloc);
|
|
}
|
|
}));
|
|
}
|
|
|
|
Form getControlForm(ExerciseControlFormBloc exerciseBloc) {
|
|
String exerciseName = AppLanguage().appLocal == Locale("en")
|
|
? exerciseBloc.exerciseRepository.exerciseType.name
|
|
: exerciseBloc.exerciseRepository.exerciseType.nameTranslation;
|
|
|
|
return Form(
|
|
autovalidate: true,
|
|
child: Scaffold(
|
|
resizeToAvoidBottomInset: true,
|
|
appBar: AppBar(
|
|
backgroundColor: Colors.transparent,
|
|
title: Row(
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
children: <Widget>[
|
|
Text("1RM Control"),
|
|
Image.asset(
|
|
'asset/image/WT_long_logo.png',
|
|
fit: BoxFit.cover,
|
|
height: 65.0,
|
|
),
|
|
],
|
|
),
|
|
leading: IconButton(
|
|
icon: Icon(Icons.arrow_back, color: Colors.white),
|
|
onPressed: () => Navigator.of(context).pop(),
|
|
),
|
|
),
|
|
body: Container(
|
|
width: MediaQuery.of(context).size.width,
|
|
height: MediaQuery.of(context).size.height,
|
|
decoration: BoxDecoration(
|
|
image: DecorationImage(
|
|
image: AssetImage('asset/image/WT_light_background.png'),
|
|
fit: BoxFit.fill,
|
|
alignment: Alignment.center,
|
|
),
|
|
),
|
|
child: Container(
|
|
padding: const EdgeInsets.only(top: 25, left: 25, right: 25),
|
|
child: SingleChildScrollView(
|
|
scrollDirection: Axis.vertical,
|
|
child: Column(mainAxisAlignment: MainAxisAlignment.spaceAround, children: <Widget>[
|
|
Text(
|
|
exerciseName,
|
|
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18, color: Colors.deepOrange),
|
|
overflow: TextOverflow.fade,
|
|
maxLines: 1,
|
|
softWrap: true,
|
|
),
|
|
FlatButton(
|
|
child: Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
|
|
Icon(Icons.question_answer),
|
|
Text(AppLocalizations.of(context).translate("Why do you need Exercise Control?"),
|
|
style: TextStyle(color: Colors.blueAccent, fontWeight: FontWeight.normal, fontSize: 14)),
|
|
Icon(Icons.arrow_forward_ios),
|
|
]),
|
|
textColor: Colors.blueAccent,
|
|
color: Colors.transparent,
|
|
onPressed: () => {
|
|
//Navigator.of(context).pushNamed('exerciseTypeDescription', arguments: exerciseBloc.exerciseRepository),
|
|
},
|
|
),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
AppLocalizations.of(context).translate("Your 1RM:"),
|
|
),
|
|
Text(
|
|
" " +
|
|
exerciseBloc.initialRMField.value +
|
|
" " +
|
|
exerciseBloc.exerciseRepository.exerciseType.unitQuantityUnit,
|
|
style: TextStyle(fontWeight: FontWeight.bold),
|
|
),
|
|
],
|
|
),
|
|
Divider(),
|
|
Column(
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
AppLocalizations.of(context).translate("1st Control Exercise:"),
|
|
style: TextStyle(),
|
|
),
|
|
TextFieldBlocBuilder(
|
|
readOnly: exerciseBloc.step != 1,
|
|
textFieldBloc: exerciseBloc.quantity1Field,
|
|
textAlign: TextAlign.center,
|
|
style: TextStyle(fontSize: 14, color: Colors.deepOrange, fontWeight: FontWeight.bold),
|
|
inputFormatters: [WhitelistingTextInputFormatter(RegExp(r"[\d.]"))],
|
|
decoration: InputDecoration(
|
|
fillColor: Colors.white,
|
|
filled: false,
|
|
hintStyle: TextStyle(fontSize: 12, color: Colors.black54, fontWeight: FontWeight.w100),
|
|
hintText: AppLocalizations.of(context).translate("The number of the exercise"),
|
|
labelStyle:
|
|
TextStyle(fontSize: 12, color: Colors.deepOrange, fontWeight: FontWeight.normal),
|
|
labelText: "Please repeat with " +
|
|
exerciseBloc.unitQuantity1Field.value +
|
|
" " +
|
|
exerciseBloc.exerciseRepository.exerciseType.unitQuantityUnit +
|
|
" " +
|
|
exerciseBloc.times +
|
|
" times!",
|
|
),
|
|
),
|
|
RaisedButton(
|
|
padding: EdgeInsets.all(0),
|
|
textColor: Colors.white,
|
|
color: exerciseBloc.step == 1 ? Colors.blue : Colors.black26,
|
|
focusColor: Colors.blueAccent,
|
|
onPressed: () => {exerciseBloc.submit()},
|
|
child: Text(
|
|
AppLocalizations.of(context).translate("Check"),
|
|
style: TextStyle(fontSize: 12),
|
|
)),
|
|
],
|
|
),
|
|
Divider(),
|
|
Column(
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
AppLocalizations.of(context).translate("2nd Control Exercise:"),
|
|
style: TextStyle(),
|
|
),
|
|
TextFieldBlocBuilder(
|
|
readOnly: exerciseBloc.step != 2,
|
|
textFieldBloc: exerciseBloc.quantity2Field,
|
|
textAlign: TextAlign.center,
|
|
style: TextStyle(fontSize: 14, color: Colors.deepOrange, fontWeight: FontWeight.bold),
|
|
inputFormatters: [WhitelistingTextInputFormatter(RegExp(r"[\d.]"))],
|
|
onChanged: (input) => {
|
|
print("Quantity 2 value $input"),
|
|
//exerciseBloc.exerciseRepository.setQuantity(double.parse(input)),
|
|
//exerciseBloc.exerciseRepository
|
|
// .setUnit(exerciseBloc.exerciseRepository.exerciseType.unit)
|
|
},
|
|
decoration: InputDecoration(
|
|
fillColor: Colors.white,
|
|
filled: false,
|
|
hintStyle: TextStyle(fontSize: 12, color: Colors.black54, fontWeight: FontWeight.w100),
|
|
hintText: AppLocalizations.of(context).translate("The number of the exercise"),
|
|
labelStyle:
|
|
TextStyle(fontSize: 12, color: Colors.deepOrange, fontWeight: FontWeight.normal),
|
|
labelText: "Please repeat with " +
|
|
exerciseBloc.unitQuantity2Field.value +
|
|
" " +
|
|
exerciseBloc.exerciseRepository.exerciseType.unitQuantityUnit +
|
|
" 12 times!",
|
|
),
|
|
),
|
|
RaisedButton(
|
|
padding: EdgeInsets.all(0),
|
|
textColor: Colors.white,
|
|
color: exerciseBloc.step == 2 ? Colors.blue : Colors.black26,
|
|
focusColor: Colors.blueAccent,
|
|
onPressed: () => {exerciseBloc.submit()},
|
|
child: Text(
|
|
AppLocalizations.of(context).translate("Check"),
|
|
style: TextStyle(fontSize: 12),
|
|
)),
|
|
],
|
|
),
|
|
Divider(),
|
|
Column(
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
AppLocalizations.of(context).translate("3rd Control Exercise:"),
|
|
style: TextStyle(),
|
|
),
|
|
TextFieldBlocBuilder(
|
|
readOnly: exerciseBloc.step != 3,
|
|
textFieldBloc: exerciseBloc.quantity3Field,
|
|
textAlign: TextAlign.center,
|
|
style: TextStyle(fontSize: 14, color: Colors.deepOrange, fontWeight: FontWeight.bold),
|
|
inputFormatters: [WhitelistingTextInputFormatter(RegExp(r"[\d.]"))],
|
|
onChanged: (input) => {
|
|
print("Quantity 3 value $input"),
|
|
//exerciseBloc.exerciseRepository.setQuantity(double.parse(input)),
|
|
//exerciseBloc.exerciseRepository
|
|
// .setUnit(exerciseBloc.exerciseRepository.exerciseType.unit)
|
|
},
|
|
decoration: InputDecoration(
|
|
fillColor: Colors.white,
|
|
filled: false,
|
|
hintStyle: TextStyle(fontSize: 12, color: Colors.black54, fontWeight: FontWeight.w100),
|
|
hintText: AppLocalizations.of(context).translate("The number of the exercise"),
|
|
labelStyle:
|
|
TextStyle(fontSize: 12, color: Colors.deepOrange, fontWeight: FontWeight.normal),
|
|
labelText: "Please repeat with " +
|
|
exerciseBloc.unitQuantity3Field.value +
|
|
" " +
|
|
exerciseBloc.exerciseRepository.exerciseType.unitQuantityUnit +
|
|
" 12 times!",
|
|
),
|
|
),
|
|
RaisedButton(
|
|
padding: EdgeInsets.all(0),
|
|
textColor: Colors.white,
|
|
color: exerciseBloc.step == 3 ? Colors.blue : Colors.black26,
|
|
focusColor: Colors.blueAccent,
|
|
onPressed: () => {exerciseBloc.submit()},
|
|
child: Text(
|
|
AppLocalizations.of(context).translate("Check"),
|
|
style: TextStyle(fontSize: 12),
|
|
)),
|
|
],
|
|
),
|
|
]),
|
|
))),
|
|
),
|
|
);
|
|
}
|
|
|
|
String validateNumberInput(input) {
|
|
String error = AppLocalizations.of(context).translate("Please type the right quantity 0-10000");
|
|
dynamic rc = (input != null && input.length > 0);
|
|
if (!rc) {
|
|
return null;
|
|
}
|
|
|
|
Pattern pattern = r'^\d+(?:\.\d+)?$';
|
|
RegExp regex = new RegExp(pattern);
|
|
if (!regex.hasMatch(input)) {
|
|
return error;
|
|
}
|
|
|
|
rc = double.tryParse(input);
|
|
if (rc == null) {
|
|
return error;
|
|
}
|
|
|
|
if (!(double.parse(input) < 10000 && double.parse(input) > 0)) {
|
|
return error;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|