223 lines
9.0 KiB
Dart
223 lines
9.0 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/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/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:aitrainer_app/library/numberpicker.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 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(
|
|
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,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
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.info),
|
|
Flexible(
|
|
child: Text(t("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(
|
|
t("Your 1RM:"),
|
|
),
|
|
Text(
|
|
" " +
|
|
exerciseBloc.initialRM.toStringAsFixed(0) +
|
|
" " +
|
|
exerciseBloc.exerciseRepository.exerciseType.unitQuantityUnit,
|
|
style: TextStyle(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.toString() : "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:");
|
|
|
|
List<Widget> listWidgets = [
|
|
Text(
|
|
title,
|
|
style: TextStyle(fontWeight: FontWeight.bold),
|
|
),
|
|
Text(
|
|
textInstruction,
|
|
style: TextStyle(fontSize: 12),
|
|
),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
NumberPicker.horizontal(
|
|
highlightSelectedValue: step == exerciseBloc.step,
|
|
initialValue: exerciseBloc.quantity.toInt(),
|
|
minValue: 0,
|
|
maxValue: 200,
|
|
step: 1,
|
|
onChanged: (value) => {exerciseBloc.add(ExerciseControlQuantityChange(quantity: value.toDouble(), step: step))},
|
|
listViewHeight: 80,
|
|
//decoration: _decoration,
|
|
),
|
|
RaisedButton(
|
|
padding: EdgeInsets.all(0),
|
|
textColor: Colors.white,
|
|
color: step == exerciseBloc.step ? Colors.blue : Colors.black26,
|
|
focusColor: Colors.blueAccent,
|
|
onPressed: () => {
|
|
exerciseBloc.add(ExerciseControlSubmit(step: step)),
|
|
if (step == 3) {confirmationDialog(exerciseBloc)}
|
|
},
|
|
child: Text(
|
|
t("Save"),
|
|
style: TextStyle(fontSize: 12),
|
|
)),
|
|
],
|
|
),
|
|
];
|
|
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: listWidgets,
|
|
);
|
|
}
|
|
|
|
void confirmationDialog(ExerciseControlBloc bloc) {
|
|
String unit = t(bloc.exerciseRepository.exerciseType.unit);
|
|
|
|
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(), Navigator.of(context).pop()},
|
|
)
|
|
],
|
|
));
|
|
}
|
|
}
|