269 lines
10 KiB
Dart
269 lines
10 KiB
Dart
import 'dart:collection';
|
|
|
|
import 'package:aitrainer_app/bloc/exercise_execute_plan/exercise_execute_plan_bloc.dart';
|
|
import 'package:aitrainer_app/bloc/exercise_execute_plan_add/exercise_execute_plan_add_bloc.dart';
|
|
import 'package:aitrainer_app/localization/app_language.dart';
|
|
import 'package:aitrainer_app/model/workout_menu_tree.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/splash.dart';
|
|
import 'package:aitrainer_app/library/numberpicker.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 ExerciseExecutePlanAddPage extends StatefulWidget{
|
|
_ExerciseExecuteAddPage createState() => _ExerciseExecuteAddPage();
|
|
}
|
|
|
|
class _ExerciseExecuteAddPage extends State<ExerciseExecutePlanAddPage> with Trans {
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
LinkedHashMap arguments = ModalRoute.of(context).settings.arguments;
|
|
// ignore: close_sinks
|
|
final ExerciseExecutePlanBloc planBloc = arguments['blocExerciseByPlan'];
|
|
final int customerId = arguments['customerId'];
|
|
final WorkoutMenuTree workoutTree = arguments['workoutTree'];
|
|
final ExerciseRepository exerciseRepository = ExerciseRepository();
|
|
setContext(context);
|
|
|
|
return BlocProvider(
|
|
create: (context) =>
|
|
ExerciseExecutePlanAddBloc(
|
|
exerciseRepository: exerciseRepository,
|
|
exercisePlanRepository: planBloc.exercisePlanRepository,
|
|
customerId: customerId,
|
|
workoutTree: workoutTree,
|
|
planBloc: planBloc),
|
|
child: BlocConsumer<ExerciseExecutePlanAddBloc, ExerciseExecutePlanAddState>(
|
|
listener: (context, state) {
|
|
if (state is ExerciseExecutePlanAddError) {
|
|
Scaffold.of(context).showSnackBar(SnackBar(
|
|
backgroundColor: Colors.orange,
|
|
content:
|
|
Text(state.message, style: TextStyle(color: Colors.white))));
|
|
} else if (state is ExerciseExecutePlanAddLoading) {
|
|
return LoadingDialog();
|
|
}
|
|
},
|
|
builder: (context, state) {
|
|
// ignore: close_sinks
|
|
final exerciseBloc = BlocProvider.of<ExerciseExecutePlanAddBloc>(context);
|
|
if ( state is ExerciseExecutePlanAddLoading ) {
|
|
return LoadingDialog();
|
|
} else if ( state is ExerciseExecutePlanAddReady) {
|
|
return getControlForm(exerciseBloc);
|
|
} else {
|
|
return getControlForm(exerciseBloc);
|
|
}
|
|
}
|
|
));
|
|
}
|
|
|
|
Form getControlForm( ExerciseExecutePlanAddBloc exerciseBloc) {
|
|
String exerciseName = AppLanguage().appLocal == Locale("en") ?
|
|
exerciseBloc.exerciseRepository.exerciseType.name :
|
|
exerciseBloc.exerciseRepository.exerciseType.nameTranslation;
|
|
|
|
return Form(
|
|
autovalidate: true,
|
|
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,
|
|
controller: ScrollController(
|
|
initialScrollOffset: exerciseBloc.scrollOffset,
|
|
),
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
children: <Widget>[
|
|
Text(t("Save Exercise")),
|
|
Text(exerciseName,
|
|
style: TextStyle(fontWeight: FontWeight.bold,
|
|
fontSize: 18,
|
|
color: Colors.deepOrange),
|
|
overflow: TextOverflow.fade,
|
|
maxLines: 1,
|
|
softWrap: true,
|
|
),
|
|
Divider(color: Colors.transparent,),
|
|
|
|
Divider(),
|
|
Column(
|
|
children: repeatExercises(exerciseBloc),
|
|
|
|
),
|
|
Divider(),
|
|
|
|
|
|
|
|
]),
|
|
)
|
|
)
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
List<Column> repeatExercises(ExerciseExecutePlanAddBloc exerciseBloc) {
|
|
List<Column> listColumns = List<Column>();
|
|
for ( int i = 0; i < exerciseBloc.countSteps; i++) {
|
|
Column col = Column(
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Divider(color: Colors.transparent,),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
crossAxisAlignment: CrossAxisAlignment.baseline,
|
|
children: [
|
|
Text(t("Execute the") + " ",style: TextStyle(fontWeight: FontWeight.bold),),
|
|
Text((i+1).toString() + ". ",style: TextStyle(fontSize:24, fontWeight: FontWeight.bold),),
|
|
Text(t("set!"),style: TextStyle(fontWeight: FontWeight.bold),),
|
|
],
|
|
),
|
|
|
|
|
|
Divider(color: Colors.transparent,),
|
|
Text(t("Please repeat with") + " "+ exerciseBloc.unitQuantity.toStringAsFixed(0) + " " +
|
|
exerciseBloc.exerciseRepository.exerciseType.unitQuantityUnit + " " +
|
|
exerciseBloc.exercisePlanRepository.getActualPlanDetail().repeats.toString() + " " + t("times!")),
|
|
Row(
|
|
children: [
|
|
NumberPicker.horizontal(
|
|
highlightSelectedValue: (i + 1) == exerciseBloc.step,
|
|
initialValue: exerciseBloc.unitQuantity.toInt(),
|
|
minValue: 0,
|
|
maxValue: 650,
|
|
step: 1,
|
|
textStyle: TextStyle(fontWeight: FontWeight.bold),
|
|
textStyleHighlighted: TextStyle(fontSize: 24, color: Colors.indigo, fontWeight: FontWeight.bold),
|
|
onChanged: (value) => {
|
|
exerciseBloc.add(ExerciseExecutePlanAddChangeUnitQuantity(quantity: value.toDouble()))
|
|
},
|
|
listViewHeight: 80,
|
|
//decoration: _decoration,
|
|
),
|
|
Text(exerciseBloc.exerciseRepository.exerciseType.unitQuantityUnit),
|
|
]
|
|
),
|
|
|
|
Row(
|
|
children: [
|
|
NumberPicker.horizontal(
|
|
highlightSelectedValue: (i+1) == exerciseBloc.step,
|
|
initialValue: exerciseBloc.quantity.toInt(),
|
|
minValue: 0,
|
|
maxValue: 200,
|
|
step: 1,
|
|
textStyle: TextStyle(fontWeight: FontWeight.bold),
|
|
textStyleHighlighted: TextStyle(fontSize: 24, color: Colors.deepOrange, fontWeight: FontWeight.bold),
|
|
onChanged: (value) => {
|
|
exerciseBloc.add(ExerciseExecutePlanAddChangeQuantity(quantity: value.toDouble()))
|
|
},
|
|
listViewHeight: 80,
|
|
//decoration: _decoration,
|
|
),
|
|
Text(t("repeat")),
|
|
]
|
|
),
|
|
|
|
|
|
|
|
|
|
/*TextFieldBlocBuilder(
|
|
readOnly: exerciseBloc.step != i+1,
|
|
textFieldBloc: exerciseBloc.unitQuantity1Field,
|
|
textAlign: TextAlign.center,
|
|
style: TextStyle(
|
|
fontSize: 18,
|
|
color: Colors.black54,
|
|
fontWeight: FontWeight.bold),
|
|
inputFormatters: [
|
|
FilteringTextInputFormatter.allow(RegExp(r"[\d.]"))
|
|
],
|
|
|
|
decoration: InputDecoration(
|
|
fillColor: Colors.white,
|
|
filled: false,
|
|
hintStyle: TextStyle(
|
|
fontSize: 14, color: Colors.black54, fontWeight: FontWeight.w100),
|
|
labelStyle: TextStyle(fontSize: 14, color: Colors.deepOrange, fontWeight: FontWeight.normal),
|
|
labelText: exerciseBloc.exerciseRepository.exerciseType.unitQuantityUnit,
|
|
),
|
|
),*/
|
|
/*TextFieldBlocBuilder(
|
|
readOnly: exerciseBloc.step != i+1,
|
|
textFieldBloc: exerciseBloc.quantity1Field,
|
|
textAlign: TextAlign.center,
|
|
style: TextStyle(
|
|
fontSize: 18,
|
|
color: Colors.deepOrange,
|
|
fontWeight: FontWeight.bold),
|
|
inputFormatters: [
|
|
FilteringTextInputFormatter.allow(RegExp(r"[\d.]"))
|
|
],
|
|
|
|
decoration: InputDecoration(
|
|
fillColor: Colors.white,
|
|
filled: false,
|
|
hintStyle: TextStyle(
|
|
fontSize: 14, color: Colors.black54, fontWeight: FontWeight.w100),
|
|
hintText: t("The number of the exercise"),
|
|
labelStyle: TextStyle(fontSize: 14, color: Colors.deepOrange, fontWeight: FontWeight.normal),
|
|
labelText: t("Please repeat with") + " "+ exerciseBloc.unitQuantity1Field.value + " " +
|
|
exerciseBloc.exerciseRepository.exerciseType.unitQuantityUnit + " " +
|
|
exerciseBloc.exercisePlanRepository.getActualPlanDetail().repeats.toString() + " " + t("times!"),
|
|
),
|
|
),*/
|
|
RaisedButton(
|
|
|
|
padding: EdgeInsets.all(0),
|
|
textColor: Colors.white,
|
|
color: exerciseBloc.step == i+1 ? Colors.blue : Colors.black26,
|
|
focusColor: Colors.blueAccent,
|
|
onPressed: () =>
|
|
{
|
|
print ("Submit step " + exerciseBloc.step.toString() + " (i) " + i.toString()),
|
|
if ( exerciseBloc.step == i+1 ) {
|
|
exerciseBloc.add(ExerciseExecutePlanAddSubmit())
|
|
},
|
|
if ( i+1 == exerciseBloc.countSteps) {
|
|
Navigator.of(context).pop()
|
|
}
|
|
},
|
|
child: Text(
|
|
t("Save"),
|
|
style: TextStyle(fontSize: 12),)
|
|
),
|
|
Divider(),
|
|
],
|
|
);
|
|
listColumns.add(col);
|
|
}
|
|
return listColumns;
|
|
}
|
|
}
|