mirror of
https://github.com/wger-project/flutter.git
synced 2026-12-05 23:44:02 +01:00
Optimization code lines
This commit is contained in:
@@ -43,8 +43,7 @@ import 'package:wger/widgets/workouts/forms.dart';
|
||||
|
||||
class DashboardNutritionWidget extends StatefulWidget {
|
||||
@override
|
||||
_DashboardNutritionWidgetState createState() =>
|
||||
_DashboardNutritionWidgetState();
|
||||
_DashboardNutritionWidgetState createState() => _DashboardNutritionWidgetState();
|
||||
}
|
||||
|
||||
class _DashboardNutritionWidgetState extends State<DashboardNutritionWidget> {
|
||||
@@ -55,8 +54,7 @@ class _DashboardNutritionWidgetState extends State<DashboardNutritionWidget> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_plan =
|
||||
Provider.of<NutritionPlansProvider>(context, listen: false).currentPlan;
|
||||
_plan = Provider.of<NutritionPlansProvider>(context, listen: false).currentPlan;
|
||||
_hasContent = _plan != null;
|
||||
}
|
||||
|
||||
@@ -99,8 +97,7 @@ class _DashboardNutritionWidgetState extends State<DashboardNutritionWidget> {
|
||||
icon: Icon(Icons.history_edu),
|
||||
color: wgerPrimaryButtonColor,
|
||||
onPressed: () {
|
||||
Provider.of<NutritionPlansProvider>(context, listen: false)
|
||||
.logMealToDiary(meal);
|
||||
Provider.of<NutritionPlansProvider>(context, listen: false).logMealToDiary(meal);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
@@ -131,8 +128,7 @@ class _DashboardNutritionWidgetState extends State<DashboardNutritionWidget> {
|
||||
),
|
||||
),
|
||||
SizedBox(width: 5),
|
||||
Text(
|
||||
'${item.amount.toStringAsFixed(0)} ${AppLocalizations.of(context).g}'),
|
||||
Text('${item.amount.toStringAsFixed(0)} ${AppLocalizations.of(context).g}'),
|
||||
],
|
||||
),
|
||||
],
|
||||
@@ -162,9 +158,7 @@ class _DashboardNutritionWidgetState extends State<DashboardNutritionWidget> {
|
||||
children: [
|
||||
ListTile(
|
||||
title: Text(
|
||||
_hasContent
|
||||
? _plan!.description
|
||||
: AppLocalizations.of(context).nutritionalPlan,
|
||||
_hasContent ? _plan!.description : AppLocalizations.of(context).nutritionalPlan,
|
||||
style: Theme.of(context).textTheme.headline4,
|
||||
),
|
||||
subtitle: Text(
|
||||
@@ -193,8 +187,7 @@ class _DashboardNutritionWidgetState extends State<DashboardNutritionWidget> {
|
||||
Container(
|
||||
padding: EdgeInsets.all(15),
|
||||
height: 180,
|
||||
child:
|
||||
NutritionalPlanPieChartWidget(_plan!.nutritionalValues),
|
||||
child: NutritionalPlanPieChartWidget(_plan!.nutritionalValues),
|
||||
)
|
||||
],
|
||||
),
|
||||
@@ -212,9 +205,8 @@ class _DashboardNutritionWidgetState extends State<DashboardNutritionWidget> {
|
||||
TextButton(
|
||||
child: Text(AppLocalizations.of(context).goToDetailPage),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pushNamed(
|
||||
NutritionalPlanScreen.routeName,
|
||||
arguments: _plan);
|
||||
Navigator.of(context)
|
||||
.pushNamed(NutritionalPlanScreen.routeName, arguments: _plan);
|
||||
}),
|
||||
],
|
||||
),
|
||||
@@ -279,11 +271,9 @@ class _DashboardWeightWidgetState extends State<DashboardWeightWidget> {
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: <Widget>[
|
||||
TextButton(
|
||||
child: Text(
|
||||
AppLocalizations.of(context).goToDetailPage),
|
||||
child: Text(AppLocalizations.of(context).goToDetailPage),
|
||||
onPressed: () {
|
||||
Navigator.of(context)
|
||||
.pushNamed(WeightScreen.routeName);
|
||||
Navigator.of(context).pushNamed(WeightScreen.routeName);
|
||||
}),
|
||||
],
|
||||
),
|
||||
@@ -356,8 +346,7 @@ class _DashboardWorkoutWidgetState extends State<DashboardWorkoutWidget> {
|
||||
icon: Icon(Icons.play_arrow),
|
||||
color: wgerPrimaryButtonColor,
|
||||
onPressed: () {
|
||||
Navigator.of(context)
|
||||
.pushNamed(GymModeScreen.routeName, arguments: day);
|
||||
Navigator.of(context).pushNamed(GymModeScreen.routeName, arguments: day);
|
||||
},
|
||||
),
|
||||
],
|
||||
@@ -379,8 +368,7 @@ class _DashboardWorkoutWidgetState extends State<DashboardWorkoutWidget> {
|
||||
children: [
|
||||
Text(s.exerciseObj.name),
|
||||
SizedBox(width: 10),
|
||||
MutedText(
|
||||
set.getSmartRepr(s.exerciseObj).join('\n')),
|
||||
MutedText(set.getSmartRepr(s.exerciseObj).join('\n')),
|
||||
],
|
||||
),
|
||||
SizedBox(height: 10),
|
||||
@@ -405,9 +393,7 @@ class _DashboardWorkoutWidgetState extends State<DashboardWorkoutWidget> {
|
||||
children: [
|
||||
ListTile(
|
||||
title: Text(
|
||||
_hasContent
|
||||
? _workoutPlan!.name
|
||||
: AppLocalizations.of(context).labelWorkoutPlan,
|
||||
_hasContent ? _workoutPlan!.name : AppLocalizations.of(context).labelWorkoutPlan,
|
||||
style: Theme.of(context).textTheme.headline4,
|
||||
),
|
||||
subtitle: Text(
|
||||
@@ -449,8 +435,8 @@ class _DashboardWorkoutWidgetState extends State<DashboardWorkoutWidget> {
|
||||
TextButton(
|
||||
child: Text(AppLocalizations.of(context).goToDetailPage),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pushNamed(WorkoutPlanScreen.routeName,
|
||||
arguments: _workoutPlan);
|
||||
Navigator.of(context)
|
||||
.pushNamed(WorkoutPlanScreen.routeName, arguments: _workoutPlan);
|
||||
},
|
||||
),
|
||||
],
|
||||
|
||||
@@ -21,8 +21,7 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
import 'package:wger/models/nutrition/nutritrional_values.dart';
|
||||
import 'package:wger/widgets/core/core.dart';
|
||||
|
||||
List<Widget> getMutedNutritionalValues(
|
||||
NutritionalValues values, BuildContext context) {
|
||||
List<Widget> getMutedNutritionalValues(NutritionalValues values, BuildContext context) {
|
||||
final List<Widget> out = [
|
||||
MutedText(
|
||||
'${AppLocalizations.of(context).energy}: '
|
||||
|
||||
@@ -39,10 +39,8 @@ class NutritionalPlanDetailWidget extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final nutritionalValues = _nutritionalPlan.nutritionalValues;
|
||||
final valuesPercentage =
|
||||
_nutritionalPlan.energyPercentage(nutritionalValues);
|
||||
final lastWeightEntry =
|
||||
Provider.of<BodyWeightProvider>(context, listen: false).getLastEntry();
|
||||
final valuesPercentage = _nutritionalPlan.energyPercentage(nutritionalValues);
|
||||
final lastWeightEntry = Provider.of<BodyWeightProvider>(context, listen: false).getLastEntry();
|
||||
final valuesGperKg = lastWeightEntry != null
|
||||
? _nutritionalPlan.gPerBodyKg(lastWeightEntry.weight, nutritionalValues)
|
||||
: null;
|
||||
@@ -85,8 +83,7 @@ class NutritionalPlanDetailWidget extends StatelessWidget {
|
||||
TableRow(
|
||||
children: [
|
||||
Padding(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(vertical: tablePadding),
|
||||
padding: const EdgeInsets.symmetric(vertical: tablePadding),
|
||||
child: Text(
|
||||
AppLocalizations.of(context).macronutrients,
|
||||
style: TextStyle(fontWeight: FontWeight.bold),
|
||||
@@ -109,8 +106,7 @@ class NutritionalPlanDetailWidget extends StatelessWidget {
|
||||
TableRow(
|
||||
children: [
|
||||
Padding(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(vertical: tablePadding),
|
||||
padding: const EdgeInsets.symmetric(vertical: tablePadding),
|
||||
child: Text(AppLocalizations.of(context).energy),
|
||||
),
|
||||
Text(
|
||||
@@ -124,42 +120,34 @@ class NutritionalPlanDetailWidget extends StatelessWidget {
|
||||
TableRow(
|
||||
children: [
|
||||
Padding(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(vertical: tablePadding),
|
||||
padding: const EdgeInsets.symmetric(vertical: tablePadding),
|
||||
child: Text(AppLocalizations.of(context).protein),
|
||||
),
|
||||
Text(nutritionalValues.protein.toStringAsFixed(0) +
|
||||
AppLocalizations.of(context).g),
|
||||
Text(valuesPercentage.protein.toStringAsFixed(1)),
|
||||
Text(valuesGperKg != null
|
||||
? valuesGperKg.protein.toStringAsFixed(1)
|
||||
: ''),
|
||||
Text(valuesGperKg != null ? valuesGperKg.protein.toStringAsFixed(1) : ''),
|
||||
],
|
||||
),
|
||||
TableRow(
|
||||
children: [
|
||||
Padding(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(vertical: tablePadding),
|
||||
padding: const EdgeInsets.symmetric(vertical: tablePadding),
|
||||
child: Text(AppLocalizations.of(context).carbohydrates),
|
||||
),
|
||||
Text(nutritionalValues.carbohydrates.toStringAsFixed(0) +
|
||||
AppLocalizations.of(context).g),
|
||||
Text(valuesPercentage.carbohydrates.toStringAsFixed(1)),
|
||||
Text(valuesGperKg != null
|
||||
? valuesGperKg.carbohydrates.toStringAsFixed(1)
|
||||
: ''),
|
||||
Text(valuesGperKg != null ? valuesGperKg.carbohydrates.toStringAsFixed(1) : ''),
|
||||
],
|
||||
),
|
||||
TableRow(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: tablePadding, horizontal: 12),
|
||||
padding: const EdgeInsets.symmetric(vertical: tablePadding, horizontal: 12),
|
||||
child: Text(AppLocalizations.of(context).sugars),
|
||||
),
|
||||
Text(nutritionalValues.carbohydratesSugar
|
||||
.toStringAsFixed(0) +
|
||||
Text(nutritionalValues.carbohydratesSugar.toStringAsFixed(0) +
|
||||
AppLocalizations.of(context).g),
|
||||
Text(''),
|
||||
Text(''),
|
||||
@@ -168,23 +156,18 @@ class NutritionalPlanDetailWidget extends StatelessWidget {
|
||||
TableRow(
|
||||
children: [
|
||||
Padding(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(vertical: tablePadding),
|
||||
padding: const EdgeInsets.symmetric(vertical: tablePadding),
|
||||
child: Text(AppLocalizations.of(context).fat),
|
||||
),
|
||||
Text(nutritionalValues.fat.toStringAsFixed(0) +
|
||||
AppLocalizations.of(context).g),
|
||||
Text(nutritionalValues.fat.toStringAsFixed(0) + AppLocalizations.of(context).g),
|
||||
Text(valuesPercentage.fat.toStringAsFixed(1)),
|
||||
Text(valuesGperKg != null
|
||||
? valuesGperKg.fat.toStringAsFixed(1)
|
||||
: ''),
|
||||
Text(valuesGperKg != null ? valuesGperKg.fat.toStringAsFixed(1) : ''),
|
||||
],
|
||||
),
|
||||
TableRow(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: tablePadding, horizontal: 12),
|
||||
padding: const EdgeInsets.symmetric(vertical: tablePadding, horizontal: 12),
|
||||
child: Text(AppLocalizations.of(context).saturatedFat),
|
||||
),
|
||||
Text(nutritionalValues.fatSaturated.toStringAsFixed(0) +
|
||||
@@ -196,8 +179,7 @@ class NutritionalPlanDetailWidget extends StatelessWidget {
|
||||
TableRow(
|
||||
children: [
|
||||
Padding(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(vertical: tablePadding),
|
||||
padding: const EdgeInsets.symmetric(vertical: tablePadding),
|
||||
child: Text(AppLocalizations.of(context).fibres),
|
||||
),
|
||||
Text(nutritionalValues.fibres.toStringAsFixed(0) +
|
||||
@@ -209,8 +191,7 @@ class NutritionalPlanDetailWidget extends StatelessWidget {
|
||||
TableRow(
|
||||
children: [
|
||||
Padding(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(vertical: tablePadding),
|
||||
padding: const EdgeInsets.symmetric(vertical: tablePadding),
|
||||
child: Text(AppLocalizations.of(context).sodium),
|
||||
),
|
||||
Text(nutritionalValues.sodium.toStringAsFixed(0) +
|
||||
@@ -231,8 +212,7 @@ class NutritionalPlanDetailWidget extends StatelessWidget {
|
||||
Container(
|
||||
padding: EdgeInsets.all(15),
|
||||
height: 220,
|
||||
child:
|
||||
NutritionalDiaryChartWidget(nutritionalPlan: _nutritionalPlan),
|
||||
child: NutritionalDiaryChartWidget(nutritionalPlan: _nutritionalPlan),
|
||||
),
|
||||
SizedBox(
|
||||
height: 200,
|
||||
@@ -246,8 +226,7 @@ class NutritionalPlanDetailWidget extends StatelessWidget {
|
||||
children: [
|
||||
TextButton(onPressed: () {}, child: const Text('')),
|
||||
Text(
|
||||
'${getFirstWord(AppLocalizations.of(context).energy)} (${AppLocalizations.of(context).kcal})',
|
||||
),
|
||||
'${getFirstWord(AppLocalizations.of(context).energy)} (${AppLocalizations.of(context).kcal})'),
|
||||
Text(
|
||||
'${getFirstWord(AppLocalizations.of(context).protein)} (${AppLocalizations.of(context).g})'),
|
||||
Text(
|
||||
@@ -258,8 +237,7 @@ class NutritionalPlanDetailWidget extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
..._nutritionalPlan.logEntriesValues.entries
|
||||
.map((entry) => NutritionDiaryEntry(
|
||||
entry.key, entry.value, _nutritionalPlan))
|
||||
.map((entry) => NutritionDiaryEntry(entry.key, entry.value, _nutritionalPlan))
|
||||
.toList()
|
||||
.reversed,
|
||||
],
|
||||
@@ -295,15 +273,12 @@ class NutritionDiaryEntry extends StatelessWidget {
|
||||
arguments: NutritionalDiaryArguments(plan, date),
|
||||
),
|
||||
child: Text(
|
||||
DateFormat.yMd(Localizations.localeOf(context).languageCode)
|
||||
.format(date),
|
||||
DateFormat.yMd(Localizations.localeOf(context).languageCode).format(date),
|
||||
)),
|
||||
Text(values.energy.toStringAsFixed(0)),
|
||||
Text(values.protein.toStringAsFixed(0)),
|
||||
Text(values.carbohydrates.toStringAsFixed(0)),
|
||||
//Text(values.carbohydratesSugar.toStringAsFixed(0)),
|
||||
Text(values.fat.toStringAsFixed(0)),
|
||||
//Text(values.fatSaturated.toStringAsFixed(0)),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user