284 lines
12 KiB
Dart
284 lines
12 KiB
Dart
import 'dart:collection';
|
|
|
|
import 'package:aitrainer_app/bloc/exercise_control/exercise_control_bloc.dart';
|
|
import 'package:aitrainer_app/localization/app_language.dart';
|
|
import 'package:aitrainer_app/model/cache.dart';
|
|
import 'package:aitrainer_app/repository/exercise_repository.dart';
|
|
import 'package:aitrainer_app/util/trans.dart';
|
|
import 'package:aitrainer_app/widgets/app_bar.dart';
|
|
import 'package:aitrainer_app/widgets/bottom_nav.dart';
|
|
import 'package:aitrainer_app/widgets/number_picker.dart';
|
|
import 'package:aitrainer_app/widgets/splash.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';
|
|
import 'package:google_fonts/google_fonts.dart';
|
|
|
|
class ExerciseControlPage extends StatefulWidget {
|
|
_ExerciseControlPage createState() => _ExerciseControlPage();
|
|
}
|
|
|
|
class _ExerciseControlPage extends State<ExerciseControlPage> with Trans {
|
|
@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'];
|
|
setContext(context);
|
|
|
|
return BlocProvider(
|
|
create: (context) => ExerciseControlBloc(exerciseRepository: exerciseRepository, percentToCalculate: percent, readonly: readonly)
|
|
..add(ExerciseControlLoad()),
|
|
child: BlocConsumer<ExerciseControlBloc, ExerciseControlState>(listener: (context, state) {
|
|
if (state is ExerciseControlError) {
|
|
Scaffold.of(context).showSnackBar(
|
|
SnackBar(backgroundColor: Colors.orange, content: Text(state.message, style: TextStyle(color: Colors.white))));
|
|
} else if (state is ExerciseControlLoading) {
|
|
return LoadingDialog();
|
|
}
|
|
}, builder: (context, state) {
|
|
final exerciseBloc = BlocProvider.of<ExerciseControlBloc>(context);
|
|
if (state is ExerciseControlLoading) {
|
|
return LoadingDialog();
|
|
} else if (state is ExerciseControlReady) {
|
|
return getControlForm(exerciseBloc);
|
|
} else {
|
|
return getControlForm(exerciseBloc);
|
|
}
|
|
}));
|
|
}
|
|
|
|
Form getControlForm(ExerciseControlBloc exerciseBloc) {
|
|
String exerciseName = AppLanguage().appLocal == Locale("en")
|
|
? exerciseBloc.exerciseRepository.exerciseType.name
|
|
: exerciseBloc.exerciseRepository.exerciseType.nameTranslation;
|
|
return Form(
|
|
child: Scaffold(
|
|
resizeToAvoidBottomInset: true,
|
|
appBar: AppBarNav(depth: 1),
|
|
body: Container(
|
|
height: double.infinity,
|
|
width: double.infinity,
|
|
alignment: Alignment.center,
|
|
decoration: BoxDecoration(
|
|
image: DecorationImage(
|
|
image: Cache().userLoggedIn.sex == "m"
|
|
? AssetImage("asset/image/WT_Results_for_men.png")
|
|
: AssetImage("asset/image/WT_Results_for_female.png"),
|
|
fit: BoxFit.cover,
|
|
alignment: Alignment.topCenter,
|
|
),
|
|
),
|
|
child: Container(
|
|
padding: const EdgeInsets.only(top: 10, left: 25, right: 25),
|
|
child: SingleChildScrollView(
|
|
scrollDirection: Axis.vertical,
|
|
controller: ScrollController(
|
|
initialScrollOffset: exerciseBloc.scrollOffset,
|
|
),
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: <Widget>[
|
|
Text(
|
|
exerciseName,
|
|
style: GoogleFonts.archivoBlack(
|
|
fontWeight: FontWeight.bold,
|
|
fontSize: 20,
|
|
color: Colors.white,
|
|
shadows: <Shadow>[
|
|
Shadow(
|
|
offset: Offset(2.0, 2.0),
|
|
blurRadius: 6.0,
|
|
color: Colors.black54,
|
|
),
|
|
Shadow(
|
|
offset: Offset(-3.0, 3.0),
|
|
blurRadius: 12.0,
|
|
color: Colors.black54,
|
|
),
|
|
],
|
|
),
|
|
overflow: TextOverflow.fade,
|
|
textAlign: TextAlign.center,
|
|
maxLines: 2,
|
|
softWrap: true,
|
|
),
|
|
Divider(
|
|
color: Colors.transparent,
|
|
),
|
|
Divider(
|
|
color: Colors.transparent,
|
|
),
|
|
Divider(
|
|
color: Colors.transparent,
|
|
),
|
|
/* FlatButton(
|
|
child: Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
|
|
Icon(
|
|
Icons.info,
|
|
color: Colors.yellow[50],
|
|
),
|
|
Flexible(
|
|
child: Text(t("Why do you need Exercise Control?"),
|
|
style: TextStyle(color: Colors.yellow[50], fontWeight: FontWeight.normal, fontSize: 14)),
|
|
),
|
|
Icon(
|
|
Icons.arrow_forward_ios,
|
|
color: Colors.yellow[50],
|
|
),
|
|
]),
|
|
textColor: Colors.blueAccent,
|
|
color: Colors.transparent,
|
|
onPressed: () => {
|
|
//Navigator.of(context).pushNamed('exerciseTypeDescription', arguments: exerciseBloc.exerciseRepository),
|
|
},
|
|
), */
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
children: [
|
|
Text(t("Your 1RM:"),
|
|
style: GoogleFonts.inter(
|
|
color: Colors.yellow[300],
|
|
fontSize: 18,
|
|
)),
|
|
Text(
|
|
" " +
|
|
exerciseBloc.initialRM.toStringAsFixed(0) +
|
|
" " +
|
|
exerciseBloc.exerciseRepository.exerciseType.unitQuantityUnit,
|
|
style: GoogleFonts.inter(color: Colors.yellow[300], fontSize: 18, fontWeight: FontWeight.bold),
|
|
),
|
|
],
|
|
),
|
|
Divider(),
|
|
numberPickForm(exerciseBloc, 1),
|
|
Divider(),
|
|
numberPickForm(exerciseBloc, 2),
|
|
Divider(),
|
|
numberPickForm(exerciseBloc, 3),
|
|
]),
|
|
))),
|
|
bottomNavigationBar: BottomNavigator(bottomNavIndex: 1),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget numberPickForm(ExerciseControlBloc exerciseBloc, int step) {
|
|
String strTimes = step == 2 ? exerciseBloc.origQuantity.toStringAsFixed(0) : "max.";
|
|
String textInstruction = "";
|
|
textInstruction = t("Please repeat with ") +
|
|
exerciseBloc.unitQuantity.toStringAsFixed(0) +
|
|
" " +
|
|
exerciseBloc.exerciseRepository.exerciseType.unitQuantityUnit +
|
|
t("hu_with") +
|
|
" " +
|
|
strTimes +
|
|
" " +
|
|
t(
|
|
"times!",
|
|
);
|
|
|
|
String title = step.toString() + ". " + t("Control Exercise:");
|
|
LinkedHashMap args = LinkedHashMap();
|
|
|
|
List<Widget> listWidgets = [
|
|
Text(
|
|
title,
|
|
style: GoogleFonts.inter(color: Colors.yellow[300], fontSize: 18, fontWeight: FontWeight.bold),
|
|
),
|
|
Text(
|
|
textInstruction,
|
|
style: GoogleFonts.inter(color: Colors.yellow[300], fontSize: 16),
|
|
),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
NumberPickerWidget(
|
|
minValue: 0,
|
|
maxValue: 200,
|
|
initalValue: exerciseBloc.quantity.toInt(),
|
|
unit: t("reps"),
|
|
color: Colors.yellow[50],
|
|
onChange: (value) => {exerciseBloc.add(ExerciseControlQuantityChange(quantity: value.toDouble(), step: step))}),
|
|
FlatButton(
|
|
padding: EdgeInsets.all(0),
|
|
textColor: Colors.white,
|
|
focusColor: Colors.blueAccent,
|
|
onPressed: () => {
|
|
exerciseBloc.add(ExerciseControlSubmit(step: step)),
|
|
if (step == 3)
|
|
{
|
|
//confirmationDialog(exerciseBloc)
|
|
Navigator.of(context).pop(),
|
|
args['exerciseRepository'] = exerciseBloc.exerciseRepository,
|
|
Navigator.of(context).pushNamed('evaluationPage', arguments: args)
|
|
}
|
|
},
|
|
child: step == exerciseBloc.step
|
|
? Stack(
|
|
alignment: Alignment.center,
|
|
children: [
|
|
Image.asset('asset/icon/gomb_orange_c.png', width: 140, height: 60),
|
|
Text(
|
|
t("Save"),
|
|
style: TextStyle(fontSize: 16, color: Colors.white),
|
|
),
|
|
],
|
|
)
|
|
: Container()),
|
|
],
|
|
),
|
|
];
|
|
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: listWidgets,
|
|
);
|
|
}
|
|
|
|
void confirmationDialog(ExerciseControlBloc bloc) {
|
|
String unit = t(bloc.exerciseRepository.exerciseType.unit);
|
|
LinkedHashMap args = LinkedHashMap();
|
|
|
|
showCupertinoDialog(
|
|
useRootNavigator: true,
|
|
context: context,
|
|
//barrierDismissible: false,
|
|
builder: (_) => CupertinoAlertDialog(
|
|
title: Text(t("Summary of your test")),
|
|
content: Column(children: [
|
|
Text(
|
|
t("Test") + ": " + bloc.repeats[1].toStringAsFixed(0) + "x" + bloc.repeats[0].toStringAsFixed(0) + " " + unit,
|
|
style: (TextStyle(color: Colors.blue)),
|
|
),
|
|
Divider(),
|
|
Text(
|
|
t("1st Control") + ": " + bloc.repeats[2].toStringAsFixed(0) + "x" + bloc.unitQuantity.toStringAsFixed(0) + " " + unit,
|
|
style: (TextStyle(color: Colors.blue)),
|
|
),
|
|
Text(
|
|
t("2nd Control") + ": " + bloc.repeats[3].toStringAsFixed(0) + "x" + bloc.unitQuantity.toStringAsFixed(0) + " " + unit,
|
|
style: (TextStyle(color: Colors.blue)),
|
|
),
|
|
Text(
|
|
t("3rd Control") + ": " + bloc.repeats[4].toStringAsFixed(0) + "x" + bloc.unitQuantity.toStringAsFixed(0) + " " + unit,
|
|
style: (TextStyle(color: Colors.blue)),
|
|
),
|
|
]),
|
|
actions: [
|
|
FlatButton(
|
|
child: Text(t("OK")),
|
|
onPressed: () => {
|
|
Navigator.of(context).pop(),
|
|
args['exerciseRepository'] = bloc.exerciseRepository,
|
|
Navigator.of(context).pushNamed('evaluationPage', arguments: args)
|
|
},
|
|
)
|
|
],
|
|
));
|
|
}
|
|
}
|