WT 1.1.19 App Upgrade

This commit is contained in:
bossanyit
2021-06-10 00:18:15 +02:00
parent e5f5f305dd
commit a595ffb358
14 changed files with 172 additions and 818 deletions
@@ -1,300 +0,0 @@
import 'dart:collection';
import 'package:aitrainer_app/bloc/exercise_plan/exercise_plan_bloc.dart';
import 'package:aitrainer_app/bloc/exercise_plan_custom_add/exercise_plan_custom_add_bloc.dart';
import 'package:aitrainer_app/util/app_language.dart';
import 'package:aitrainer_app/model/workout_menu_tree.dart';
import 'package:aitrainer_app/repository/exercise_plan_repository.dart';
import 'package:aitrainer_app/util/trans.dart';
import 'package:aitrainer_app/widgets/app_bar.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:keyboard_actions/keyboard_actions.dart';
import 'package:keyboard_actions/keyboard_actions_config.dart';
import 'package:keyboard_actions/keyboard_actions_item.dart';
import 'package:modal_progress_hud_nsn/modal_progress_hud_nsn.dart';
class ExercisePlanDetailAddPage extends StatefulWidget {
@override
_ExercisePlanDetailAddPage createState() => _ExercisePlanDetailAddPage();
}
class _ExercisePlanDetailAddPage extends State<ExercisePlanDetailAddPage> with Trans {
final FocusNode _nodeText1 = FocusNode();
final FocusNode _nodeText2 = FocusNode();
final FocusNode _nodeText3 = FocusNode();
KeyboardActionsConfig _buildConfig(BuildContext context) {
return KeyboardActionsConfig(
keyboardActionsPlatform: KeyboardActionsPlatform.ALL,
keyboardBarColor: Colors.grey[200],
nextFocus: true,
actions: [
KeyboardActionsItem(focusNode: _nodeText2, toolbarButtons: [
(node) {
return GestureDetector(
onTap: () => node.unfocus(),
child: Container(
padding: EdgeInsets.all(8.0),
color: Colors.orange[500],
child: Text(
t("Done"),
style: TextStyle(color: Colors.white),
),
),
);
}
]),
KeyboardActionsItem(
focusNode: _nodeText1,
toolbarButtons: [
//button 2
(node) {
return GestureDetector(
onTap: () => node.unfocus(),
child: Container(
color: Colors.orange,
padding: EdgeInsets.all(8.0),
child: Text(
t("Done"),
style: TextStyle(color: Colors.white),
),
),
);
}
],
),
KeyboardActionsItem(
focusNode: _nodeText3,
toolbarButtons: [
//button 2
(node) {
return GestureDetector(
onTap: () => node.unfocus(),
child: Container(
color: Colors.orange,
padding: EdgeInsets.all(8.0),
child: Text(
t("Done"),
style: TextStyle(color: Colors.white),
),
),
);
}
],
),
],
);
}
@override
Widget build(BuildContext context) {
LinkedHashMap args = ModalRoute.of(context)!.settings.arguments as LinkedHashMap;
// ignore: close_sinks
final ExercisePlanBloc planBloc = args['bloc'];
final WorkoutMenuTree workoutMenuTree = args['workoutTreeItem'];
final ExercisePlanRepository exercisePlanRepository = planBloc.exercisePlanRepository;
setContext(context);
return BlocProvider(
create: (context) =>
ExercisePlanCustomAddBloc(exercisePlanRepository: exercisePlanRepository, planBloc: planBloc, workoutMenuTree: workoutMenuTree)
..add(ExercisePlanCustomAddLoad()),
child: BlocConsumer<ExercisePlanCustomAddBloc, ExercisePlanCustomAddState>(
listener: (context, state) {
if (state is ExercisePlanCustomAddError) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(backgroundColor: Colors.orange, content: Text(state.message, style: TextStyle(color: Colors.white))));
}
},
builder: (context, state) {
// ignore: close_sinks
final bloc = BlocProvider.of<ExercisePlanCustomAddBloc>(context);
return ModalProgressHUD(
child: getForm(bloc, workoutMenuTree),
inAsyncCall: state is ExercisePlanCustomAddLoading,
opacity: 0.5,
color: Colors.black54,
progressIndicator: CircularProgressIndicator(),
);
},
));
}
Widget getForm(ExercisePlanCustomAddBloc bloc, WorkoutMenuTree workoutMenuTree) {
String exerciseName = "";
if (bloc.exercisePlanRepository.getActualPlanDetail() == null || bloc.serie == null) {
return Offstage();
}
exerciseName = AppLanguage().appLocal == Locale("en")
? bloc.exercisePlanRepository.getActualPlanDetail()!.exerciseType!.name
: bloc.exercisePlanRepository.getActualPlanDetail()!.exerciseType!.nameTranslation;
final bool weightVisible = bloc.exercisePlanRepository.getActualPlanDetail()!.exerciseType!.unitQuantityUnit != null;
String summary = bloc.serie!.toStringAsFixed(0) + " x " + bloc.quantity.toStringAsFixed(0);
if (bloc.quantityUnit > 0) {
summary += " x " + bloc.quantityUnit.toStringAsFixed(1) + " kg";
}
final String unit = bloc.exercisePlanRepository.getActualPlanDetail()!.exerciseType!.unit;
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_black_background.jpg'),
fit: BoxFit.fill,
alignment: Alignment.center,
),
),
child: KeyboardActions(
config: _buildConfig(context),
child: Container(
child: SingleChildScrollView(
padding: const EdgeInsets.only(top: 25, left: 95, right: 95),
scrollDirection: Axis.vertical,
child: Column(mainAxisAlignment: MainAxisAlignment.spaceAround, children: <Widget>[
Text(t('Save The Exercise To The Exercise Plan'),
textAlign: TextAlign.center,
style: GoogleFonts.inter(
fontSize: 14,
color: Colors.white,
)),
Text(
exerciseName,
textAlign: TextAlign.center,
style: GoogleFonts.archivoBlack(fontSize: 18, color: Colors.yellow[200]),
overflow: TextOverflow.fade,
maxLines: 3,
softWrap: true,
),
Divider(
color: Colors.transparent,
height: 30,
),
TextFormField(
decoration: InputDecoration(
contentPadding: EdgeInsets.only(left: 25, top: 5, bottom: 5),
labelText: t('Serie'),
labelStyle: GoogleFonts.inter(fontSize: 20, color: Colors.yellow[50], decorationColor: Colors.black12),
fillColor: Colors.white24,
filled: true,
border: OutlineInputBorder(
gapPadding: 8.0,
borderRadius: BorderRadius.circular(12.0),
borderSide: BorderSide(color: Colors.black26, width: 0.4),
),
),
initialValue: bloc.serie!.toStringAsFixed(0),
focusNode: _nodeText1,
keyboardType: TextInputType.number,
style: GoogleFonts.archivoBlack(fontSize: 60, color: Colors.yellow[200]),
onChanged: (value) => {bloc.add(ExercisePlanCustomAddChangeSerie(quantity: double.parse(value)))}),
//] ),
Divider(),
TextFormField(
decoration: InputDecoration(
contentPadding: EdgeInsets.only(left: 25, top: 5, bottom: 5),
labelText: t(unit),
fillColor: Colors.white24,
labelStyle: GoogleFonts.inter(fontSize: 20, color: Colors.yellow[50]),
filled: true,
border: OutlineInputBorder(
gapPadding: 4.0,
borderRadius: BorderRadius.circular(12.0),
borderSide: BorderSide(color: Colors.green[50]!, width: 0.4),
),
),
focusNode: _nodeText2,
initialValue: bloc.quantity.toStringAsFixed(0),
keyboardType: TextInputType.number,
style: GoogleFonts.archivoBlack(fontSize: 60, color: Colors.yellow[200]),
onChanged: (value) => {bloc.add(ExercisePlanCustomAddChangeQuantity(quantity: double.parse(value)))}),
Divider(),
weightVisible
? TextFormField(
decoration: InputDecoration(
contentPadding: EdgeInsets.only(left: 25, top: 5, bottom: 5),
labelText: t('Weight'),
fillColor: Colors.white24,
labelStyle: GoogleFonts.inter(fontSize: 20, color: Colors.yellow[50]),
filled: true,
border: OutlineInputBorder(
gapPadding: 2.0,
borderRadius: BorderRadius.circular(12.0),
borderSide: BorderSide(color: Colors.green[50]!, width: 0.4),
),
),
focusNode: _nodeText3,
initialValue: bloc.quantityUnit.toStringAsFixed(1),
keyboardType: TextInputType.numberWithOptions(decimal: true),
style: GoogleFonts.archivoBlack(fontSize: 60, color: Colors.yellow[200]),
onChanged: (value) => {
if (value.isNotEmpty)
{
value = value.replaceFirst(",", "."),
value = value.replaceAll(RegExp(r'[^0-9.]'), ""),
bloc.add(ExercisePlanCustomAddChangeQuantityUnit(quantity: double.parse(value)))
}
})
: Offstage(),
Divider(),
Text(
summary,
style: TextStyle(fontSize: 24, fontWeight: FontWeight.normal, color: Colors.yellow[50]),
),
Divider(),
Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
TextButton(
onPressed: () => {
bloc.add(ExercisePlanCustomAddRemove()),
Navigator.of(context).pop(),
},
child: Stack(
alignment: Alignment.center,
children: [
Image.asset('asset/icon/gomb_pink_b.png', width: 140, height: 60),
Text(
t("Delete"),
style: TextStyle(fontSize: 16, color: Colors.white),
),
],
),
),
TextButton(
onPressed: () => {
bloc.add(ExercisePlanCustomAddSubmit()),
Navigator.of(context).pop(),
},
child: Stack(
alignment: Alignment.center,
children: [
Image.asset('asset/icon/gomb_zold_b-1.png', width: 140, height: 60),
Text(
t("Save"),
style: TextStyle(fontSize: 16, color: Colors.white),
),
],
)),
],
),
]),
)))),
));
}
}
-202
View File
@@ -1,202 +0,0 @@
import 'dart:collection';
import 'package:aitrainer_app/bloc/exercise_plan/exercise_plan_bloc.dart';
import 'package:aitrainer_app/model/cache.dart';
import 'package:aitrainer_app/model/workout_menu_tree.dart';
import 'package:aitrainer_app/library/tree_view.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/treeview_parent_widget.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:modal_progress_hud_nsn/modal_progress_hud_nsn.dart';
class ExercisePlanCustomPage extends StatefulWidget {
@override
_ExercisePlanCustomPage createState() => _ExercisePlanCustomPage();
}
class _ExercisePlanCustomPage extends State<ExercisePlanCustomPage> with Trans {
final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
// ignore: close_sinks
late ExercisePlanBloc bloc;
@override
void initState() {
super.initState();
/// We require the initializers to run after the loading screen is rendered
SchedulerBinding.instance!.addPostFrameCallback((_) {
BlocProvider.of<ExercisePlanBloc>(context).add(ExercisePlanLoad());
});
}
@override
Widget build(BuildContext context) {
LinkedHashMap arguments = ModalRoute.of(context)!.settings.arguments as LinkedHashMap;
final int customerId = arguments['customerId'];
bloc = BlocProvider.of<ExercisePlanBloc>(context);
bloc.customerId = customerId;
setContext(context);
return Scaffold(
key: _scaffoldKey,
appBar: AppBarNav(depth: 1),
body: Container(
padding: EdgeInsets.all(20),
decoration: BoxDecoration(
image: DecorationImage(
image: customerId == Cache().userLoggedIn!.customerId
? AssetImage('asset/image/WT_black_background.jpg')
: AssetImage('asset/image/WT_light_background.jpg'),
fit: BoxFit.cover,
alignment: Alignment.center,
),
),
child: BlocConsumer<ExercisePlanBloc, ExercisePlanState>(listener: (context, state) {
if (state is ExercisePlanError) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(
state.message,
),
backgroundColor: Colors.orange,
));
}
}, builder: (context, state) {
return ModalProgressHUD(
child: exerciseWidget(bloc),
inAsyncCall: state is ExercisePlanLoading,
opacity: 0.5,
color: Colors.black54,
progressIndicator: CircularProgressIndicator(),
);
})),
bottomNavigationBar: BottomNavigator(bottomNavIndex: 2),
);
}
Widget exerciseWidget(ExercisePlanBloc bloc) {
return TreeView(
startExpanded: false,
children: _getTreeChildren(bloc),
);
}
List<Widget> _getTreeChildren(ExercisePlanBloc bloc) {
List<Widget> exerciseTypes = [];
Card explanation = Card(
color: Colors.white60,
child: Container(
padding: EdgeInsets.only(left: 10, right: 5, top: 12, bottom: 8),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Row(
children: [
Icon(
Icons.info,
color: Colors.orangeAccent,
),
Text(" "),
Text(
t("Custom Exercise Plan"),
style: GoogleFonts.archivoBlack(fontSize: 20),
),
],
),
Divider(
color: Colors.transparent,
),
Text(
t("Select manually the exercises what you would like to have in your plan. At the end don't forget to save."),
style: GoogleFonts.inter(fontSize: 12, fontWeight: FontWeight.normal),
),
],
)));
exerciseTypes.add(explanation);
bloc.menuTreeRepository.sortedTree.forEach((name, list) {
exerciseTypes.add(Container(
margin: const EdgeInsets.only(left: 4.0),
child: TreeViewChild(
startExpanded: false,
parent: TreeviewParentWidget(text: name),
children: _getChildList(list, bloc),
)));
});
return exerciseTypes;
}
List<Widget> _getChildList(List<WorkoutMenuTree> listWorkoutTree, ExercisePlanBloc bloc) {
List<Widget> list = [];
listWorkoutTree.forEach((element) {
final String unitQuantityUnit =
element.exerciseType != null && element.exerciseType!.unitQuantityUnit != null ? element.exerciseType!.unitQuantityUnit! : "";
list.add(TreeViewChild(
startExpanded: false,
parent: Card(
margin: EdgeInsets.only(left: 10, top: 5),
color: Colors.white54,
child: Container(
padding: const EdgeInsets.only(left: 5, top: 0, right: 5, bottom: 0),
child: Row(mainAxisAlignment: MainAxisAlignment.start, children: [
IconButton(
icon: element.selected
? Icon(
Icons.check,
color: Colors.green[300],
)
: Icon(
Icons.add,
color: Colors.indigo,
),
onPressed: () => clickAddDetail(bloc, element),
),
SizedBox(width: 10),
Flexible(
fit: FlexFit.tight,
flex: 8,
child: InkWell(
child: Text(
element.name,
textAlign: TextAlign.start,
style: GoogleFonts.inter(fontSize: 16, color: Colors.black),
),
onTap: () => clickAddDetail(bloc, element),
),
),
InkWell(
child: !element.selected ||
bloc.exercisePlanRepository.exercisePlanDetails[element.exerciseTypeId] == null ||
bloc.exercisePlanRepository.exercisePlanDetails[element.exerciseTypeId]!.change == null
? Text("")
: Text(
bloc.exercisePlanRepository.exercisePlanDetails[element.exerciseTypeId]!.repeats.toString() +
" x " +
bloc.exercisePlanRepository.exercisePlanDetails[element.exerciseTypeId]!.weightEquation! +
unitQuantityUnit,
style: TextStyle(fontSize: 9, color: Colors.green),
),
onTap: () => clickAddDetail(bloc, element),
),
]),
)),
children: []));
});
return list;
}
void clickAddDetail(ExercisePlanBloc bloc, WorkoutMenuTree workoutMenuTree) {
final LinkedHashMap args = LinkedHashMap();
args['bloc'] = bloc;
args['workoutTreeItem'] = workoutMenuTree;
Navigator.of(context).pushNamed("exercisePlanDetailAdd", arguments: args);
}
}
-218
View File
@@ -1,218 +0,0 @@
import 'dart:collection';
import 'package:aitrainer_app/model/cache.dart';
import 'package:aitrainer_app/repository/exercise_repository.dart';
import 'package:aitrainer_app/service/logging.dart';
import 'package:aitrainer_app/util/enums.dart';
import 'package:aitrainer_app/util/track.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/dialog_premium.dart';
import 'package:aitrainer_app/widgets/image_button.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
class MyExercisePlanPage extends StatefulWidget {
@override
_MyExercisePlanPage createState() => _MyExercisePlanPage();
}
class _MyExercisePlanPage extends State<MyExercisePlanPage> with Trans, Logging {
@override
Widget build(BuildContext context) {
final ExerciseRepository exerciseRepository = ExerciseRepository();
final LinkedHashMap args = LinkedHashMap();
setContext(context);
double mediaWidth = MediaQuery.of(context).size.width;
double imageWidth = (mediaWidth - 45) / 2;
return Scaffold(
appBar: AppBarNav(depth: 0),
body: Container(
padding: EdgeInsets.all(10),
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('asset/image/WT_menu_dark.jpg'),
fit: BoxFit.cover,
alignment: Alignment.center,
),
),
child: CustomScrollView(scrollDirection: Axis.vertical, slivers: [
SliverGrid(
delegate: SliverChildListDelegate([
ImageButton(
width: imageWidth,
textAlignment: Alignment.topLeft,
text: t("Edit My Custom Plan"),
style: GoogleFonts.robotoMono(
textStyle: TextStyle(
fontSize: 14,
color: Colors.white,
fontWeight: FontWeight.bold,
backgroundColor: Colors.black54.withOpacity(0.4))),
image: "asset/image/exercise_plan_custom.jpg",
left: 5,
onTap: () => {
if (Cache().userLoggedIn != null)
{
args['exerciseRepository'] = exerciseRepository,
args['customerId'] = Cache().userLoggedIn!.customerId,
Navigator.of(context).pushNamed('exercisePlanCustomPage', arguments: args)
}
},
isLocked: false,
),
ImageButton(
width: imageWidth,
textAlignment: Alignment.topLeft,
text: t("Execute My Selected Training Plan"),
style: GoogleFonts.robotoMono(
textStyle: TextStyle(
fontSize: 14,
color: Colors.white,
fontWeight: FontWeight.bold,
backgroundColor: Colors.black54.withOpacity(0.4))),
image: "asset/image/exercise_plan_execute.jpg",
top: 130,
left: 5,
onTap: () => {
if (Cache().userLoggedIn != null)
{
args['customerId'] = Cache().userLoggedIn!.customerId,
Navigator.of(context).pushNamed('exerciseExecutePlanPage', arguments: args)
}
},
isLocked: false,
),
ImageButton(
width: imageWidth,
textAlignment: Alignment.topLeft,
text: t("Suggested Training Plan"),
style: GoogleFonts.robotoMono(
textStyle: TextStyle(
fontSize: 14,
color: Colors.white,
fontWeight: FontWeight.bold,
backgroundColor: Colors.black54.withOpacity(0.4))),
image: "asset/image/exercise_plan_suggested.jpg",
left: 2,
onTap: () => {
if (Cache().userLoggedIn != null)
{
Track().track(TrackingEvent.my_suggested_plan),
showDialog(
context: context,
builder: (BuildContext context) {
return DialogPremium(
unlocked: Cache().hasPurchased,
unlockRound: 2,
function: "Suggested Training Plan",
unlockedText: null,
onTap: () => {Navigator.of(context).pop()},
onCancel: () => {Navigator.of(context).pop()},
);
})
}
},
isLocked: true,
),
ImageButton(
width: imageWidth,
textAlignment: Alignment.topLeft,
text: t("Training Programs"),
style: GoogleFonts.robotoMono(
textStyle: TextStyle(
fontSize: 14,
color: Colors.white,
fontWeight: FontWeight.bold,
backgroundColor: Colors.black54.withOpacity(0.4))),
image: "asset/image/exercise_plan_stars.jpg",
left: 5,
onTap: () => {
if (Cache().userLoggedIn != null)
{
Track().track(TrackingEvent.my_special_plan),
showDialog(
context: context,
builder: (BuildContext context) {
return DialogPremium(
unlocked: Cache().hasPurchased,
unlockRound: 1,
function: "Training Programs",
unlockedText: null,
onTap: () => {Navigator.of(context).pop()},
onCancel: () => {Navigator.of(context).pop()},
);
})
}
},
isLocked: true,
),
hiddenPlanWidget(exerciseRepository),
hiddenTrainingWidget(),
]),
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
mainAxisSpacing: 15.0,
crossAxisSpacing: 15.0,
childAspectRatio: 1.0,
),
)
])),
bottomNavigationBar: BottomNavigator(bottomNavIndex: 2));
}
Widget hiddenPlanWidget(ExerciseRepository exerciseRepository) {
final LinkedHashMap args = LinkedHashMap();
if (Cache().getTrainee() != null) {
return TextButton(
style: TextButton.styleFrom(
padding: EdgeInsets.all(20),
primary: Colors.white,
onSurface: Colors.black12,
),
onPressed: () => {
if (Cache().getTrainee() != null)
{
args['exerciseRepository'] = exerciseRepository,
args['customerId'] = Cache().getTrainee()!.customerId,
Navigator.of(context).pushNamed('exercisePlanCustomPage', arguments: args)
}
},
child: Text(
t("My Trainee's Plan"),
style: TextStyle(fontSize: 18),
));
} else {
return Container();
}
}
Widget hiddenTrainingWidget() {
final LinkedHashMap args = LinkedHashMap();
if (Cache().getTrainee() != null) {
log("!!Trainee: " + Cache().getTrainee()!.firstname! + " " + Cache().getTrainee()!.name!);
return TextButton(
style: TextButton.styleFrom(
padding: EdgeInsets.all(20),
primary: Colors.white,
onSurface: Colors.black12,
),
onPressed: () => {
if (Cache().getTrainee() != null)
{
args['customerId'] = Cache().getTrainee()!.customerId,
Navigator.of(context).pushNamed('exerciseExecutePlanPage', arguments: args)
}
},
child: Text(
t("Execute My Trainee's Training Plan"),
style: TextStyle(fontSize: 18),
));
} else {
return Container();
}
}
}
+3 -1
View File
@@ -35,7 +35,9 @@ class TrainingPlanActivatePage extends StatelessWidget with Trans {
parentName = args['parentName'];
return Scaffold(
appBar: AppBarNav(depth: 1),
appBar: AppBarNav(
depth: 0,
),
body: Container(
padding: EdgeInsets.all(20),
decoration: BoxDecoration(