WT 1.1.26+3 bloc migration

This commit is contained in:
Tibor Bossanyi (Freelancer)
2022-04-15 08:47:32 +02:00
parent 60df0bcf2d
commit 225172f950
47 changed files with 1527 additions and 1620 deletions
+1 -5
View File
@@ -41,11 +41,7 @@ class _ExerciseNewPageState extends State<ExerciseNewPage> with Trans, Logging {
return BlocProvider(
create: (context) => ExerciseNewBloc(
exerciseRepository: ExerciseRepository(),
menuBloc: menuBloc,
customerRepository: CustomerRepository(),
exerciseType: exerciseType)
..add(ExerciseNewLoad()),
exerciseRepository: ExerciseRepository(), menuBloc: menuBloc, customerRepository: CustomerRepository(), exerciseType: exerciseType),
child: BlocConsumer<ExerciseNewBloc, ExerciseNewState>(
listener: (context, state) {
if (state is ExerciseNewError) {
+168 -25
View File
@@ -1,5 +1,7 @@
import 'dart:async';
import 'dart:collection';
import 'package:aitrainer_app/bloc/development_diagram/development_diagram_bloc.dart';
import 'package:aitrainer_app/bloc/menu/menu_bloc.dart';
import 'package:aitrainer_app/library/radar_chart.dart';
import 'package:aitrainer_app/widgets/app_bar.dart';
import 'package:aitrainer_app/widgets/bottom_nav.dart';
@@ -11,6 +13,7 @@ import 'package:aitrainer_app/util/trans.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:aitrainer_app/bloc/body_development/body_development_bloc.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:modal_progress_hud_nsn/modal_progress_hud_nsn.dart';
class MyDevelopmentBodyPage extends StatefulWidget {
@@ -55,7 +58,7 @@ class _MyDevelopmentBodyPage extends State<MyDevelopmentBodyPage> with Trans, Co
@override
Widget build(BuildContext context) {
bloc = BlocProvider.of<BodyDevelopmentBloc>(context);
final MenuBloc menuBloc = BlocProvider.of<MenuBloc>(context);
LinkedHashMap arguments = ModalRoute.of(context)!.settings.arguments as LinkedHashMap;
final int customerId = arguments['customerId'];
setContext(context);
@@ -73,41 +76,181 @@ class _MyDevelopmentBodyPage extends State<MyDevelopmentBodyPage> with Trans, Co
alignment: Alignment.center,
),
),
child: BlocConsumer<BodyDevelopmentBloc, BodyDevelopmentState>(
listener: (context, state) {},
builder: (context, state) {
if (state is BodyDevelopmentInitial) {
return Container();
} else {
return ModalProgressHUD(
child: developmentWidget(customerId),
inAsyncCall: state is BodyDevelopmentLoading,
opacity: 0.5,
color: Colors.black54,
progressIndicator: CircularProgressIndicator(),
);
}
},
)),
child: BlocProvider(
create: (context) => BodyDevelopmentBloc(workoutTreeRepository: menuBloc.menuTreeRepository),
child: BlocConsumer<BodyDevelopmentBloc, BodyDevelopmentState>(
listener: (context, state) {
if (state is BodyDevelopmentError) {
ScaffoldMessenger.of(context)
.showSnackBar(SnackBar(backgroundColor: Colors.orange, content: Text(state.message, style: TextStyle(color: Colors.white))));
}
},
builder: (context, state) {
final bloc = BlocProvider.of<BodyDevelopmentBloc>(context);
return ModalProgressHUD(
child: developmentWidget(customerId, bloc),
inAsyncCall: state is BodyDevelopmentLoading,
opacity: 0.5,
color: Colors.black54,
progressIndicator: CircularProgressIndicator(),
);
},
))),
bottomNavigationBar: BottomNavigator(bottomNavIndex: 1),
);
}
Widget developmentWidget(int customerId) {
Widget getFilterData(BodyDevelopmentBloc bloc) {
return Container(
color: Colors.transparent,
// padding: EdgeInsets.all(5),
child: Wrap(
direction: Axis.horizontal,
spacing: 10,
runSpacing: 5,
children: [
ChoiceChip(
avatar: Icon(
Icons.bubble_chart,
),
label: Text(t('Sum Of Mass')),
labelStyle: TextStyle(fontSize: 9, color: Colors.black),
selectedColor: Colors.lightBlueAccent,
selected: bloc.group == DiagramGroup.sumMass,
onSelected: (value) => {bloc.add(BodyDevelopmentChangeGroup(group: DiagramGroup.sumMass))},
),
ChoiceChip(
avatar: Icon(Icons.accessibility_new),
label: Text(t('One Rep Max')),
labelStyle: TextStyle(fontSize: 9, color: Colors.black),
selectedColor: Colors.lightBlueAccent,
selected: bloc.group == DiagramGroup.oneRepMax,
onSelected: (value) => {bloc.add(BodyDevelopmentChangeGroup(group: DiagramGroup.oneRepMax))},
),
ChoiceChip(
avatar: Icon(Icons.perm_device_information),
label: Text(t('Percent')),
labelStyle: TextStyle(fontSize: 9, color: Colors.black),
selectedColor: Colors.lightBlueAccent,
selected: bloc.group == DiagramGroup.percent,
onSelected: (value) => {bloc.add(BodyDevelopmentChangeGroup(group: DiagramGroup.percent))},
),
],
),
);
}
Widget getGroupDate(BodyDevelopmentBloc bloc) {
return Container(
color: Colors.transparent,
//padding: EdgeInsets.all(5),
child: Wrap(
direction: Axis.horizontal,
spacing: 10,
runSpacing: 5,
children: [
ChoiceChip(
labelPadding: EdgeInsets.only(right: 5),
avatar: Icon(Icons.timer),
label: Text(t('L3M')),
labelStyle: TextStyle(fontSize: 9, color: Colors.black),
disabledColor: Colors.black26,
selectedColor: Colors.greenAccent,
selected: bloc.filter == DiagramDateFilterGroup.l3m,
onSelected: (value) => {bloc.add(BodyDevelopmentChangeDate(filter: DiagramDateFilterGroup.l3m))},
),
ChoiceChip(
labelPadding: EdgeInsets.only(right: 5),
avatar: Icon(Icons.timer),
label: Text(t('FM-LM')),
labelStyle: TextStyle(fontSize: 9, color: Colors.black),
selectedColor: Colors.greenAccent,
disabledColor: Colors.white12,
selected: bloc.filter == DiagramDateFilterGroup.fm_lm,
onSelected: (value) => {bloc.add(BodyDevelopmentChangeDate(filter: DiagramDateFilterGroup.fm_lm))},
),
ChoiceChip(
labelPadding: EdgeInsets.only(right: 5),
avatar: Icon(Icons.timer),
label: Text(t('L3T')),
labelStyle: TextStyle(fontSize: 9, color: Colors.black),
selectedColor: Colors.greenAccent,
disabledColor: Colors.black26,
selected: bloc.filter == DiagramDateFilterGroup.l3t,
onSelected: (value) => {bloc.add(BodyDevelopmentChangeDate(filter: DiagramDateFilterGroup.l3t))},
),
ChoiceChip(
labelPadding: EdgeInsets.only(right: 5),
avatar: Icon(Icons.timer),
label: Text(t('Yearly')),
labelStyle: TextStyle(fontSize: 9, color: Colors.black),
selectedColor: Colors.greenAccent,
disabledColor: Colors.white70,
selected: bloc.filter == DiagramDateFilterGroup.yearly,
onSelected: (value) => {bloc.add(BodyDevelopmentChangeDate(filter: DiagramDateFilterGroup.yearly))},
),
],
),
);
}
Widget getLegend(BodyDevelopmentBloc bloc) {
if (bloc.filter == DiagramDateFilterGroup.yearly) {
return Offstage();
}
return Wrap(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Container(
width: 100,
height: 6,
color: Colors.green,
),
Text("First Month", style: GoogleFonts.inter(fontSize: 14)),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Container(
width: 100,
height: 6,
color: Colors.blue,
),
Text("First Month", style: GoogleFonts.inter(fontSize: 14)),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Container(
width: 100,
height: 6,
color: Colors.red,
),
Text("First Month", style: GoogleFonts.inter(fontSize: 14)),
],
)
],
);
}
Widget developmentWidget(int customerId, BodyDevelopmentBloc bloc) {
return Column(children: [
explanationWidget(),
getFilterData(bloc),
getGroupDate(bloc),
getLegend(bloc),
Expanded(
child: exerciseWidget(customerId),
child: exerciseWidget(customerId, bloc),
),
]);
}
Widget exerciseWidget(int customerId) {
return RadarChart.light(
ticks: bloc.radarTicks,
features: bloc.radarFeatures,
data: bloc.radarData,
);
Widget exerciseWidget(int customerId, BodyDevelopmentBloc bloc) {
return RadarChart.light(ticks: bloc.radarTicks, features: bloc.radarFeatures, data: bloc.radarData);
}
Widget explanationWidget() {
+2 -6
View File
@@ -87,9 +87,7 @@ class _MyDevelopmentPage extends State<MyDevelopmentPage> with Trans {
builder: (BuildContext context) {
return DialogCommon(
title: t("Premium function"),
descriptions: Cache().canTrial()
? t("This is a premium function, you can reach it outside of the trial period only with a valid subscription")
: t("This is a premium function, you can reach it only with a valid subscription"),
descriptions: t("This is a premium function, you can reach it only with a valid subscription"),
onCancel: () => Navigator.of(context).pop(),
onTap: () => Navigator.of(context).pop(),
text: '',
@@ -151,9 +149,7 @@ class _MyDevelopmentPage extends State<MyDevelopmentPage> with Trans {
builder: (BuildContext context) {
return DialogCommon(
title: t("Premium function"),
descriptions: Cache().canTrial()
? t("This is a premium function, you can reach it outside of the trial period only with a valid subscription")
: t("This is a premium function, you can reach it only with a valid subscription"),
descriptions: t("This is a premium function, you can reach it only with a valid subscription"),
onCancel: () => Navigator.of(context).pop(),
onTap: () => Navigator.of(context).pop(),
text: '',
+5 -5
View File
@@ -160,7 +160,7 @@ class _SizeState extends State<SizesDevelopmentPage> with Trans {
HashMap<String, dynamic> args = HashMap();
args['customerRepository'] = bloc.customerRepository;
args['property'] = element;
args['title'] = t("Size development: ") + " " + propertyName;
args['title'] = t("Size development") + ": " + t(propertyName);
Navigator.of(context).pushNamed('developmentDiagramPage', arguments: args);
}
@@ -177,8 +177,8 @@ class _SizeState extends State<SizesDevelopmentPage> with Trans {
),
padding: EdgeInsets.only(left: 10, right: 5, top: 12, bottom: 8),
child: Column(children: [
Row(
mainAxisAlignment: MainAxisAlignment.start,
Wrap(
//mainAxisAlignment: MainAxisAlignment.start,
children: [
Icon(
Icons.info,
@@ -187,7 +187,7 @@ class _SizeState extends State<SizesDevelopmentPage> with Trans {
Text(" "),
Text(
t("Red icon means you have not saved this size."),
overflow: TextOverflow.clip,
//overflow: TextOverflow.clip,
style: GoogleFonts.inter(
fontSize: 14,
color: Colors.white,
@@ -197,7 +197,7 @@ class _SizeState extends State<SizesDevelopmentPage> with Trans {
),
Text(
t("Tap on the green icon to see your development in a diagram"),
overflow: TextOverflow.clip,
//overflow: TextOverflow.clip,
style: GoogleFonts.inter(
fontSize: 14,
color: Colors.white,
+4 -4
View File
@@ -185,7 +185,7 @@ class SettingsPage extends StatelessWidget with Trans {
leading: Icon(CustomIcon.user_cog),
title: TextButton(
child: Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
Text("Terms Of Use", style: TextStyle(color: Colors.black)),
Text(t("Terms Of Use"), style: TextStyle(color: Colors.black)),
Icon(
Icons.arrow_forward_ios,
color: Colors.indigo,
@@ -212,7 +212,7 @@ class SettingsPage extends StatelessWidget with Trans {
leading: Icon(Icons.enhanced_encryption),
title: TextButton(
child: Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
Text("Data Privacy", style: TextStyle(color: Colors.black)),
Text(t("Data Privacy"), style: TextStyle(color: Colors.black)),
Icon(
Icons.arrow_forward_ios,
color: Colors.indigo,
@@ -239,7 +239,7 @@ class SettingsPage extends StatelessWidget with Trans {
leading: Icon(CustomIcon.question),
title: TextButton(
child: Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
Text("Frequently Asked Questions", style: TextStyle(color: Colors.indigo)),
Text(t("Frequently Asked Questions"), style: TextStyle(color: Colors.indigo)),
Icon(
Icons.arrow_forward_ios,
color: Colors.indigo,
@@ -282,7 +282,7 @@ class SettingsPage extends StatelessWidget with Trans {
leading: Icon(CustomIcon.mail_1),
title: TextButton(
child: Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
Text("Feedback email", style: TextStyle(color: Colors.indigo)),
Text(t("Feedback email"), style: TextStyle(color: Colors.indigo)),
Icon(
Icons.arrow_forward_ios,
color: Colors.indigo,
+5 -8
View File
@@ -51,12 +51,11 @@ class TrainingEvaluationPage extends StatelessWidget with Trans {
),
),
child: BlocProvider(
create: (context) =>
TrainingEvaluationBloc(trainingPlanBloc: trainingPlanBloc, day: dayName)..add(TrainingEvaluationLoad()),
create: (context) => TrainingEvaluationBloc(trainingPlanBloc: trainingPlanBloc, day: dayName),
child: BlocConsumer<TrainingEvaluationBloc, TrainingEvaluationState>(listener: (context, state) {
if (state is TrainingEvaluationError) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(backgroundColor: Colors.orange, content: Text(state.message, style: TextStyle(color: Colors.white))));
ScaffoldMessenger.of(context)
.showSnackBar(SnackBar(backgroundColor: Colors.orange, content: Text(state.message, style: TextStyle(color: Colors.white))));
} else if (state is TrainingEvaluationVictoryReady) {
showDialog(
context: context,
@@ -373,8 +372,7 @@ class ExerciseTile extends StatelessWidget with Trans {
hasWeight
? skipped
? extra
? TextSpan(
text: "-", style: GoogleFonts.inter(fontSize: 12, color: Colors.grey[400], fontWeight: FontWeight.bold))
? TextSpan(text: "-", style: GoogleFonts.inter(fontSize: 12, color: Colors.grey[400], fontWeight: FontWeight.bold))
: TextSpan(
text: t("skipped") + "!",
style: GoogleFonts.inter(fontSize: 12, color: Colors.grey[400], fontWeight: FontWeight.bold))
@@ -433,8 +431,7 @@ class ExerciseTile extends StatelessWidget with Trans {
skipped || extra
? TextSpan()
: TextSpan(
text: t("Trend") + ": ",
style: GoogleFonts.inter(fontSize: 12, color: Colors.yellow[400], fontWeight: FontWeight.bold)),
text: t("Trend") + ": ", style: GoogleFonts.inter(fontSize: 12, color: Colors.yellow[400], fontWeight: FontWeight.bold)),
skipped || extra
? TextSpan()
: TextSpan(
+2 -5
View File
@@ -204,9 +204,7 @@ class TrainingPlanActivatePage extends StatelessWidget with Trans {
builder: (BuildContext context) {
return DialogCommon(
title: t("Premium function"),
descriptions: Cache().canTrial()
? t("This is a premium function, you can reach it outside of the trial period only with a valid subscription")
: t("This is a premium function, you can reach it only with a valid subscription"),
descriptions: t("This is a premium function, you can reach it only with a valid subscription"),
onCancel: () => Navigator.of(context).pop(),
onTap: () => Navigator.of(context).pop(),
text: '',
@@ -478,8 +476,7 @@ class TrainingPlanActivatePage extends StatelessWidget with Trans {
return DialogCommon(
title: t("Dropset"),
descriptions: t("A drop set is an advanced resistance training technique "),
description2:
t(" in which you focus on completing a set until failure - or the inability to do another repetition."),
description2: t(" in which you focus on completing a set until failure - or the inability to do another repetition."),
text: "OK",
onTap: () => {
Navigator.of(context).pop(),
+10 -14
View File
@@ -333,8 +333,8 @@ class _ExerciseListState extends State<ExerciseList> with Trans {
String description2 = "";
if (next.exerciseTypeId != detail.exerciseTypeId) {
title = AppLocalizations.of(context)!.translate("Stop!");
description = AppLocalizations.of(context)!.translate("Please continue with the next exercise in the queue:") +
next.exerciseType!.nameTranslation;
description =
AppLocalizations.of(context)!.translate("Please continue with the next exercise in the queue:") + next.exerciseType!.nameTranslation;
} else {
final HashMap args = HashMap();
args['exerciseType'] = next.exerciseType;
@@ -388,8 +388,7 @@ class _ExerciseListState extends State<ExerciseList> with Trans {
bloc.getMyPlan()!.days[widget.dayName]!.forEach((element) {
if (prev == null || (prev != null && prev!.exerciseTypeId != element.exerciseTypeId)) {
tiles.add(GestureDetector(
onTap: () =>
bloc.getNext() != null ? executeExercise(bloc, bloc.getNext()!, context) : Navigator.of(context).pushNamed('home'),
onTap: () => bloc.getNext() != null ? executeExercise(bloc, bloc.getNext()!, context) : Navigator.of(context).pushNamed('home'),
child: ExerciseTile(
bloc: bloc,
detail: element,
@@ -544,8 +543,7 @@ class ExerciseTile extends StatelessWidget with Trans {
List<Widget> getExerciseTiles(CustomerTrainingPlanDetails detail) {
final List<Widget> list = [];
if (bloc.alternatives[detail.customerTrainingPlanDetailsId] != null &&
bloc.alternatives[detail.customerTrainingPlanDetailsId].length > 0) {
if (bloc.alternatives[detail.customerTrainingPlanDetailsId] != null && bloc.alternatives[detail.customerTrainingPlanDetailsId].length > 0) {
int index = 0;
for (CustomerTrainingPlanDetails alternative in bloc.alternatives[detail.customerTrainingPlanDetailsId]) {
final Widget widget = getTile(alternative, index);
@@ -565,8 +563,7 @@ class ExerciseTile extends StatelessWidget with Trans {
final int step = bloc.getStep(detail);
final int highlightStep = bloc.getHighlightStep(detail);
final bool hasLeftAlternative = detail.alternatives.length > 0 && index > 0;
final bool hasRightAlternative =
detail.alternatives.length > 0 && index + 1 < bloc.alternatives[detail.customerTrainingPlanDetailsId].length;
final bool hasRightAlternative = detail.alternatives.length > 0 && index + 1 < bloc.alternatives[detail.customerTrainingPlanDetailsId].length;
return Container(
child: Stack(alignment: Alignment.centerRight, children: [
@@ -601,8 +598,7 @@ class ExerciseTile extends StatelessWidget with Trans {
context: context,
builder: (BuildContext context) {
return DialogHTML(
title: detail.exerciseType!.nameTranslation,
htmlData: '<p>' + detail.exerciseType!.descriptionTranslation + '</p>');
title: detail.exerciseType!.nameTranslation, htmlData: '<p>' + detail.exerciseType!.descriptionTranslation + '</p>');
}),
icon: Icon(
Icons.info_outline,
@@ -676,13 +672,13 @@ class ExerciseTile extends StatelessWidget with Trans {
height: 1.1,
shadows: <Shadow>[
Shadow(
offset: Offset(16.0, 16.0),
blurRadius: 16.0,
offset: Offset(8.0, 8.0),
blurRadius: 8.0,
color: Colors.black54,
),
Shadow(
offset: Offset(16.0, 16.0),
blurRadius: 16.0,
offset: Offset(8.0, 8.0),
blurRadius: 8.0,
color: Colors.black54,
),
],