From 5cc6413f0daa496893fab2903dd2a774a34b35b1 Mon Sep 17 00:00:00 2001 From: Bujdy Date: Wed, 5 Oct 2022 17:09:59 +0200 Subject: [PATCH 1/4] addded measurements to dashboard, categories card refactor --- lib/screens/dashboard.dart | 1 + lib/widgets/dashboard/widgets.dart | 155 ++++++++++++++++-- lib/widgets/measurements/categories.dart | 54 +----- lib/widgets/measurements/categories_card.dart | 70 ++++++++ pubspec.lock | 35 ++-- pubspec.yaml | 5 +- 6 files changed, 234 insertions(+), 86 deletions(-) create mode 100644 lib/widgets/measurements/categories_card.dart diff --git a/lib/screens/dashboard.dart b/lib/screens/dashboard.dart index c397c5b50..d4d12c052 100644 --- a/lib/screens/dashboard.dart +++ b/lib/screens/dashboard.dart @@ -41,6 +41,7 @@ class _DashboardScreenState extends State { DashboardWorkoutWidget(), DashboardNutritionWidget(), DashboardWeightWidget(), + DashboardMeasurementsWidget(), const DashboardCalendarWidget(), ], ), diff --git a/lib/widgets/dashboard/widgets.dart b/lib/widgets/dashboard/widgets.dart index 8979821e0..ba9a64156 100644 --- a/lib/widgets/dashboard/widgets.dart +++ b/lib/widgets/dashboard/widgets.dart @@ -16,6 +16,7 @@ * along with this program. If not, see . */ +import 'package:carousel_slider/carousel_slider.dart'; import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; @@ -35,14 +36,20 @@ import 'package:wger/screens/workout_plan_screen.dart'; import 'package:wger/theme/theme.dart'; import 'package:wger/widgets/core/charts.dart'; import 'package:wger/widgets/core/core.dart'; +import 'package:wger/widgets/measurements/categories_card.dart'; import 'package:wger/widgets/nutrition/charts.dart'; import 'package:wger/widgets/nutrition/forms.dart'; import 'package:wger/widgets/weight/forms.dart'; import 'package:wger/widgets/workouts/forms.dart'; +import '../../providers/measurement.dart'; +import '../../screens/measurement_entries_screen.dart'; +import '../measurements/forms.dart'; + class DashboardNutritionWidget extends StatefulWidget { @override - _DashboardNutritionWidgetState createState() => _DashboardNutritionWidgetState(); + _DashboardNutritionWidgetState createState() => + _DashboardNutritionWidgetState(); } class _DashboardNutritionWidgetState extends State { @@ -53,7 +60,8 @@ class _DashboardNutritionWidgetState extends State { @override void initState() { super.initState(); - _plan = Provider.of(context, listen: false).currentPlan; + _plan = + Provider.of(context, listen: false).currentPlan; _hasContent = _plan != null; } @@ -96,7 +104,8 @@ class _DashboardNutritionWidgetState extends State { icon: const Icon(Icons.history_edu), color: wgerPrimaryButtonColor, onPressed: () { - Provider.of(context, listen: false).logMealToDiary(meal); + Provider.of(context, listen: false) + .logMealToDiary(meal); ScaffoldMessenger.of(context).showSnackBar( SnackBar( content: Text( @@ -127,7 +136,8 @@ class _DashboardNutritionWidgetState extends State { ), ), const SizedBox(width: 5), - Text('${item.amount.toStringAsFixed(0)} ${AppLocalizations.of(context).g}'), + Text( + '${item.amount.toStringAsFixed(0)} ${AppLocalizations.of(context).g}'), ], ), ], @@ -147,7 +157,9 @@ class _DashboardNutritionWidgetState extends State { return const Text(''); } - return _showDetail ? const Icon(Icons.expand_less) : const Icon(Icons.expand_more); + return _showDetail + ? const Icon(Icons.expand_less) + : const Icon(Icons.expand_more); } @override @@ -157,7 +169,9 @@ class _DashboardNutritionWidgetState extends State { 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( @@ -186,7 +200,8 @@ class _DashboardNutritionWidgetState extends State { Container( padding: const EdgeInsets.all(15), height: 180, - child: NutritionalPlanPieChartWidget(_plan!.nutritionalValues), + child: + NutritionalPlanPieChartWidget(_plan!.nutritionalValues), ) ], ), @@ -218,8 +233,9 @@ class _DashboardNutritionWidgetState extends State { TextButton( child: Text(AppLocalizations.of(context).goToDetailPage), onPressed: () { - Navigator.of(context) - .pushNamed(NutritionalPlanScreen.routeName, arguments: _plan); + Navigator.of(context).pushNamed( + NutritionalPlanScreen.routeName, + arguments: _plan); }, ), ], @@ -253,7 +269,7 @@ class _DashboardWeightWidgetState extends State { style: Theme.of(context).textTheme.headline4, ), leading: const FaIcon( - FontAwesomeIcons.weightScale, + FontAwesomeIcons.weight, color: Colors.black, ), trailing: IconButton( @@ -286,9 +302,11 @@ class _DashboardWeightWidgetState extends State { mainAxisAlignment: MainAxisAlignment.end, children: [ 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); }), ], ), @@ -309,6 +327,101 @@ class _DashboardWeightWidgetState extends State { } } +class DashboardMeasurementsWidget extends StatefulWidget { + @override + _DashboardMeasurementsWidgetState createState() => + _DashboardMeasurementsWidgetState(); +} + +class _DashboardMeasurementsWidgetState + extends State { + int _current = 0; + final CarouselController _controller = CarouselController(); + + @override + Widget build(BuildContext context) { + final _provider = Provider.of(context, listen: false); + + var items = _provider.categories + .map( + (item) => CategoriesCard(item), + ) + .toList(); + return Consumer( + builder: (context, workoutProvider, child) => Card( + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + ListTile( + title: Text( + AppLocalizations.of(context).measurements, + style: Theme.of(context).textTheme.headline4, + ), + leading: const FaIcon( + FontAwesomeIcons.weight, + color: Colors.black, + ), + ), + Column( + children: [ + if (items.isNotEmpty) + Column(children: [ + CarouselSlider( + items: items, + carouselController: _controller, + options: CarouselOptions( + autoPlay: false, + enlargeCenterPage: false, + viewportFraction: 1, + enableInfiniteScroll: false, + aspectRatio: 1.1, + onPageChanged: (index, reason) { + setState(() { + _current = index; + }); + }), + ), + Padding( + padding: const EdgeInsets.only(bottom: 10), + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: items.asMap().entries.map((entry) { + return GestureDetector( + onTap: () => _controller.animateToPage(entry.key), + child: Container( + width: 12.0, + height: 12.0, + margin: EdgeInsets.symmetric( + vertical: 8.0, horizontal: 4.0), + decoration: BoxDecoration( + shape: BoxShape.circle, + color: (Theme.of(context).brightness == + Brightness.dark + ? Colors.white + : wgerPrimaryColor) + .withOpacity( + _current == entry.key ? 0.9 : 0.4)), + ), + ); + }).toList(), + ), + ), + ]) + else + NothingFound( + AppLocalizations.of(context).noWeightEntries, + AppLocalizations.of(context).newEntry, + WeightForm(), + ), + ], + ), + ], + ), + ), + ); + } +} + class DashboardWorkoutWidget extends StatefulWidget { @override _DashboardWorkoutWidgetState createState() => _DashboardWorkoutWidgetState(); @@ -332,7 +445,9 @@ class _DashboardWorkoutWidgetState extends State { return const Text(''); } - return _showDetail ? const Icon(Icons.expand_less) : const Icon(Icons.expand_more); + return _showDetail + ? const Icon(Icons.expand_less) + : const Icon(Icons.expand_more); } List getContent() { @@ -364,7 +479,8 @@ class _DashboardWorkoutWidgetState extends State { icon: const Icon(Icons.play_arrow), color: wgerPrimaryButtonColor, onPressed: () { - Navigator.of(context).pushNamed(GymModeScreen.routeName, arguments: day); + Navigator.of(context) + .pushNamed(GymModeScreen.routeName, arguments: day); }, ), ], @@ -386,7 +502,8 @@ class _DashboardWorkoutWidgetState extends State { children: [ Text(s.exerciseObj.name), const SizedBox(width: 10), - MutedText(set.getSmartRepr(s.exerciseObj).join('\n')), + MutedText( + set.getSmartRepr(s.exerciseObj).join('\n')), ], ), const SizedBox(height: 10), @@ -411,7 +528,9 @@ class _DashboardWorkoutWidgetState extends State { 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( @@ -453,8 +572,8 @@ class _DashboardWorkoutWidgetState extends State { TextButton( child: Text(AppLocalizations.of(context).goToDetailPage), onPressed: () { - Navigator.of(context) - .pushNamed(WorkoutPlanScreen.routeName, arguments: _workoutPlan); + Navigator.of(context).pushNamed(WorkoutPlanScreen.routeName, + arguments: _workoutPlan); }, ), ], diff --git a/lib/widgets/measurements/categories.dart b/lib/widgets/measurements/categories.dart index fd44426ad..49ba73e37 100644 --- a/lib/widgets/measurements/categories.dart +++ b/lib/widgets/measurements/categories.dart @@ -24,6 +24,7 @@ import 'package:wger/screens/form_screen.dart'; import 'package:wger/screens/measurement_entries_screen.dart'; import 'package:wger/widgets/core/charts.dart'; +import 'categories_card.dart'; import 'forms.dart'; class CategoriesList extends StatelessWidget { @@ -37,58 +38,7 @@ class CategoriesList extends StatelessWidget { itemBuilder: (context, index) { final currentCategory = _provider.categories[index]; - return Card( - child: Column( - children: [ - Padding( - padding: const EdgeInsets.only(top: 5), - child: Text( - currentCategory.name, - style: Theme.of(context).textTheme.headline6, - ), - ), - Container( - color: Colors.white, - padding: const EdgeInsets.all(10), - height: 220, - child: MeasurementChartWidget( - currentCategory.entries - .map((e) => MeasurementChartEntry(e.value, e.date)) - .toList(), - unit: currentCategory.unit, - ), - ), - const Divider(), - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - TextButton( - child: Text(AppLocalizations.of(context).goToDetailPage), - onPressed: () { - Navigator.pushNamed( - context, - MeasurementEntriesScreen.routeName, - arguments: currentCategory.id, - ); - }), - IconButton( - onPressed: () async { - await Navigator.pushNamed( - context, - FormScreen.routeName, - arguments: FormScreenArguments( - AppLocalizations.of(context).newEntry, - MeasurementEntryForm(currentCategory.id!), - ), - ); - }, - icon: const Icon(Icons.add), - ), - ], - ), - ], - ), - ); + return CategoriesCard(currentCategory); }, ); } diff --git a/lib/widgets/measurements/categories_card.dart b/lib/widgets/measurements/categories_card.dart new file mode 100644 index 000000000..b2605774f --- /dev/null +++ b/lib/widgets/measurements/categories_card.dart @@ -0,0 +1,70 @@ +import 'package:flutter/material.dart'; + +import '../../models/measurements/measurement_category.dart'; +import '../../screens/form_screen.dart'; +import '../../screens/measurement_entries_screen.dart'; +import '../core/charts.dart'; +import 'forms.dart'; +import 'package:flutter_gen/gen_l10n/app_localizations.dart'; + +class CategoriesCard extends StatelessWidget { + MeasurementCategory currentCategory; + + CategoriesCard(this.currentCategory); + + @override + Widget build(BuildContext context) { + return Card( + child: Column( + children: [ + Padding( + padding: const EdgeInsets.only(top: 5), + child: Text( + currentCategory.name, + style: Theme.of(context).textTheme.headline6, + ), + ), + Container( + color: Colors.white, + padding: const EdgeInsets.all(10), + height: 220, + child: MeasurementChartWidget( + currentCategory.entries + .map((e) => MeasurementChartEntry(e.value, e.date)) + .toList(), + unit: currentCategory.unit, + ), + ), + const Divider(), + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + TextButton( + child: Text(AppLocalizations.of(context).goToDetailPage), + onPressed: () { + Navigator.pushNamed( + context, + MeasurementEntriesScreen.routeName, + arguments: currentCategory.id, + ); + }), + IconButton( + onPressed: () async { + await Navigator.pushNamed( + context, + FormScreen.routeName, + arguments: FormScreenArguments( + AppLocalizations.of(context).newEntry, + MeasurementEntryForm(currentCategory.id!), + ), + ); + }, + icon: const Icon(Icons.add), + ), + ], + ), + ], + ), + ); + } +} diff --git a/pubspec.lock b/pubspec.lock index 07c1a0666..de8e7a934 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -42,7 +42,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.8.2" + version: "2.9.0" boolean_selector: dependency: transitive description: @@ -141,6 +141,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.3.0" + carousel_slider: + dependency: "direct main" + description: + name: carousel_slider + url: "https://pub.dartlang.org" + source: hosted + version: "4.1.1" change: dependency: transitive description: @@ -154,7 +161,7 @@ packages: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.2.1" charcode: dependency: transitive description: @@ -217,7 +224,7 @@ packages: name: clock url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.1.1" code_builder: dependency: transitive description: @@ -287,7 +294,7 @@ packages: name: fake_async url: "https://pub.dartlang.org" source: hosted - version: "1.3.0" + version: "1.3.1" ffi: dependency: transitive description: @@ -552,7 +559,7 @@ packages: name: json_serializable url: "https://pub.dartlang.org" source: hosted - version: "6.4.1" + version: "6.4.0" klizma: dependency: transitive description: @@ -594,21 +601,21 @@ packages: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.11" + version: "0.12.12" material_color_utilities: dependency: transitive description: name: material_color_utilities url: "https://pub.dartlang.org" source: hosted - version: "0.1.4" + version: "0.1.5" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.7.0" + version: "1.8.0" mime: dependency: transitive description: @@ -664,7 +671,7 @@ packages: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.8.1" + version: "1.8.2" path_drawing: dependency: transitive description: @@ -879,7 +886,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.2" + version: "1.9.0" stack_trace: dependency: transitive description: @@ -907,7 +914,7 @@ packages: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.1.1" table_calendar: dependency: "direct main" description: @@ -921,14 +928,14 @@ packages: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.2.1" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.4.9" + version: "0.4.12" timing: dependency: transitive description: @@ -956,7 +963,7 @@ packages: name: url_launcher url: "https://pub.dartlang.org" source: hosted - version: "6.1.6" + version: "6.1.5" url_launcher_android: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index b1ddc0cc7..5dc17fb75 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -51,9 +51,10 @@ dependencies: rive: ^0.9.1 shared_preferences: ^2.0.15 table_calendar: ^3.0.7 - url_launcher: ^6.1.6 + url_launcher: ^6.1.5 flutter_barcode_scanner: ^2.0.0 video_player: ^2.4.7 + carousel_slider: ^4.1.1 dev_dependencies: flutter_test: @@ -62,7 +63,7 @@ dev_dependencies: # sdk: flutter build_runner: ^2.2.1 flutter_launcher_icons: ^0.10.0 - json_serializable: ^6.4.1 + json_serializable: ^6.3.2 mockito: ^5.3.2 network_image_mock: ^2.1.1 flutter_lints: ^2.0.1 From a659fcc24ad8538d92e1559e5a7504e0b7f49f41 Mon Sep 17 00:00:00 2001 From: Bujdy Date: Wed, 5 Oct 2022 23:52:50 +0200 Subject: [PATCH 2/4] fixed typo, added translation, fixed empty list state, added elevation parameter to card --- lib/l10n/app_en.arb | 4 + lib/screens/dashboard.dart | 2 +- lib/widgets/dashboard/widgets.dart | 114 ++++++++---------- lib/widgets/measurements/categories_card.dart | 4 +- 4 files changed, 56 insertions(+), 68 deletions(-) diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index 0e569b541..20291659e 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -383,6 +383,10 @@ "@noWeightEntries": { "description": "Message shown when the user has no logged weight entries" }, + "noMeasurementEntries": "You have no measurement entries", + "@noMeasurementsntries": { + "description": "Message shown when the user has no logged measurement entries" + }, "edit": "Edit", "@edit": {}, "loadingText": "Loading...", diff --git a/lib/screens/dashboard.dart b/lib/screens/dashboard.dart index d4d12c052..9be302e97 100644 --- a/lib/screens/dashboard.dart +++ b/lib/screens/dashboard.dart @@ -41,7 +41,7 @@ class _DashboardScreenState extends State { DashboardWorkoutWidget(), DashboardNutritionWidget(), DashboardWeightWidget(), - DashboardMeasurementsWidget(), + DashboardMeasurementWidget(), const DashboardCalendarWidget(), ], ), diff --git a/lib/widgets/dashboard/widgets.dart b/lib/widgets/dashboard/widgets.dart index ba9a64156..5ad9bae88 100644 --- a/lib/widgets/dashboard/widgets.dart +++ b/lib/widgets/dashboard/widgets.dart @@ -26,6 +26,7 @@ import 'package:provider/provider.dart'; import 'package:wger/models/nutrition/nutritional_plan.dart'; import 'package:wger/models/workouts/workout_plan.dart'; import 'package:wger/providers/body_weight.dart'; +import 'package:wger/providers/measurement.dart'; import 'package:wger/providers/nutrition.dart'; import 'package:wger/providers/workout_plans.dart'; import 'package:wger/screens/form_screen.dart'; @@ -37,19 +38,15 @@ import 'package:wger/theme/theme.dart'; import 'package:wger/widgets/core/charts.dart'; import 'package:wger/widgets/core/core.dart'; import 'package:wger/widgets/measurements/categories_card.dart'; +import 'package:wger/widgets/measurements/forms.dart'; import 'package:wger/widgets/nutrition/charts.dart'; import 'package:wger/widgets/nutrition/forms.dart'; import 'package:wger/widgets/weight/forms.dart'; import 'package:wger/widgets/workouts/forms.dart'; -import '../../providers/measurement.dart'; -import '../../screens/measurement_entries_screen.dart'; -import '../measurements/forms.dart'; - class DashboardNutritionWidget extends StatefulWidget { @override - _DashboardNutritionWidgetState createState() => - _DashboardNutritionWidgetState(); + _DashboardNutritionWidgetState createState() => _DashboardNutritionWidgetState(); } class _DashboardNutritionWidgetState extends State { @@ -60,8 +57,7 @@ class _DashboardNutritionWidgetState extends State { @override void initState() { super.initState(); - _plan = - Provider.of(context, listen: false).currentPlan; + _plan = Provider.of(context, listen: false).currentPlan; _hasContent = _plan != null; } @@ -104,8 +100,7 @@ class _DashboardNutritionWidgetState extends State { icon: const Icon(Icons.history_edu), color: wgerPrimaryButtonColor, onPressed: () { - Provider.of(context, listen: false) - .logMealToDiary(meal); + Provider.of(context, listen: false).logMealToDiary(meal); ScaffoldMessenger.of(context).showSnackBar( SnackBar( content: Text( @@ -136,8 +131,7 @@ class _DashboardNutritionWidgetState extends State { ), ), const SizedBox(width: 5), - Text( - '${item.amount.toStringAsFixed(0)} ${AppLocalizations.of(context).g}'), + Text('${item.amount.toStringAsFixed(0)} ${AppLocalizations.of(context).g}'), ], ), ], @@ -157,9 +151,7 @@ class _DashboardNutritionWidgetState extends State { return const Text(''); } - return _showDetail - ? const Icon(Icons.expand_less) - : const Icon(Icons.expand_more); + return _showDetail ? const Icon(Icons.expand_less) : const Icon(Icons.expand_more); } @override @@ -169,9 +161,7 @@ class _DashboardNutritionWidgetState extends State { 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( @@ -200,8 +190,7 @@ class _DashboardNutritionWidgetState extends State { Container( padding: const EdgeInsets.all(15), height: 180, - child: - NutritionalPlanPieChartWidget(_plan!.nutritionalValues), + child: NutritionalPlanPieChartWidget(_plan!.nutritionalValues), ) ], ), @@ -233,9 +222,8 @@ class _DashboardNutritionWidgetState extends State { TextButton( child: Text(AppLocalizations.of(context).goToDetailPage), onPressed: () { - Navigator.of(context).pushNamed( - NutritionalPlanScreen.routeName, - arguments: _plan); + Navigator.of(context) + .pushNamed(NutritionalPlanScreen.routeName, arguments: _plan); }, ), ], @@ -302,11 +290,9 @@ class _DashboardWeightWidgetState extends State { mainAxisAlignment: MainAxisAlignment.end, children: [ 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); }), ], ), @@ -327,14 +313,12 @@ class _DashboardWeightWidgetState extends State { } } -class DashboardMeasurementsWidget extends StatefulWidget { +class DashboardMeasurementWidget extends StatefulWidget { @override - _DashboardMeasurementsWidgetState createState() => - _DashboardMeasurementsWidgetState(); + _DashboardMeasurementWidgetState createState() => _DashboardMeasurementWidgetState(); } -class _DashboardMeasurementsWidgetState - extends State { +class _DashboardMeasurementWidgetState extends State { int _current = 0; final CarouselController _controller = CarouselController(); @@ -344,10 +328,13 @@ class _DashboardMeasurementsWidgetState var items = _provider.categories .map( - (item) => CategoriesCard(item), + (item) => CategoriesCard( + item, + elevation: 0, + ), ) .toList(); - return Consumer( + return Consumer( builder: (context, workoutProvider, child) => Card( child: Column( mainAxisSize: MainAxisSize.min, @@ -391,16 +378,13 @@ class _DashboardMeasurementsWidgetState child: Container( width: 12.0, height: 12.0, - margin: EdgeInsets.symmetric( - vertical: 8.0, horizontal: 4.0), + margin: EdgeInsets.symmetric(vertical: 8.0, horizontal: 4.0), decoration: BoxDecoration( shape: BoxShape.circle, - color: (Theme.of(context).brightness == - Brightness.dark + color: (Theme.of(context).brightness == Brightness.dark ? Colors.white : wgerPrimaryColor) - .withOpacity( - _current == entry.key ? 0.9 : 0.4)), + .withOpacity(_current == entry.key ? 0.9 : 0.4)), ), ); }).toList(), @@ -409,9 +393,9 @@ class _DashboardMeasurementsWidgetState ]) else NothingFound( - AppLocalizations.of(context).noWeightEntries, + AppLocalizations.of(context).noMeasurementEntries, AppLocalizations.of(context).newEntry, - WeightForm(), + MeasurementCategoryForm(), ), ], ), @@ -445,9 +429,7 @@ class _DashboardWorkoutWidgetState extends State { return const Text(''); } - return _showDetail - ? const Icon(Icons.expand_less) - : const Icon(Icons.expand_more); + return _showDetail ? const Icon(Icons.expand_less) : const Icon(Icons.expand_more); } List getContent() { @@ -479,8 +461,7 @@ class _DashboardWorkoutWidgetState extends State { icon: const Icon(Icons.play_arrow), color: wgerPrimaryButtonColor, onPressed: () { - Navigator.of(context) - .pushNamed(GymModeScreen.routeName, arguments: day); + Navigator.of(context).pushNamed(GymModeScreen.routeName, arguments: day); }, ), ], @@ -502,8 +483,7 @@ class _DashboardWorkoutWidgetState extends State { children: [ Text(s.exerciseObj.name), const SizedBox(width: 10), - MutedText( - set.getSmartRepr(s.exerciseObj).join('\n')), + MutedText(set.getSmartRepr(s.exerciseObj).join('\n')), ], ), const SizedBox(height: 10), @@ -528,9 +508,7 @@ class _DashboardWorkoutWidgetState extends State { 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( @@ -572,8 +550,8 @@ class _DashboardWorkoutWidgetState extends State { TextButton( child: Text(AppLocalizations.of(context).goToDetailPage), onPressed: () { - Navigator.of(context).pushNamed(WorkoutPlanScreen.routeName, - arguments: _workoutPlan); + Navigator.of(context) + .pushNamed(WorkoutPlanScreen.routeName, arguments: _workoutPlan); }, ), ], @@ -587,9 +565,10 @@ class _DashboardWorkoutWidgetState extends State { class NothingFound extends StatelessWidget { final String _title; final String _titleForm; - final Widget _form; + final Widget? _form; + final VoidCallback? onPressed; - const NothingFound(this._title, this._titleForm, this._form); + const NothingFound(this._title, this._titleForm, this._form, {this.onPressed}); @override Widget build(BuildContext context) { @@ -605,16 +584,19 @@ class NothingFound extends StatelessWidget { Icons.add_box, color: wgerPrimaryButtonColor, ), - onPressed: () async { - Navigator.pushNamed( - context, - FormScreen.routeName, - arguments: FormScreenArguments( - _titleForm, - _form, - ), - ); - }, + onPressed: onPressed ?? + () async { + if (_form != null) { + Navigator.pushNamed( + context, + FormScreen.routeName, + arguments: FormScreenArguments( + _titleForm, + _form!, + ), + ); + } + }, ), ], ), diff --git a/lib/widgets/measurements/categories_card.dart b/lib/widgets/measurements/categories_card.dart index b2605774f..57cb9d7c1 100644 --- a/lib/widgets/measurements/categories_card.dart +++ b/lib/widgets/measurements/categories_card.dart @@ -9,12 +9,14 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart'; class CategoriesCard extends StatelessWidget { MeasurementCategory currentCategory; + double? elevation; - CategoriesCard(this.currentCategory); + CategoriesCard(this.currentCategory,{this.elevation}); @override Widget build(BuildContext context) { return Card( + elevation: elevation, child: Column( children: [ Padding( From 1b724f3b1000f8f145b03e10717c17d7aeee2dc7 Mon Sep 17 00:00:00 2001 From: Bujdy Date: Thu, 6 Oct 2022 00:04:42 +0200 Subject: [PATCH 3/4] removed onPressed --- lib/widgets/dashboard/widgets.dart | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/lib/widgets/dashboard/widgets.dart b/lib/widgets/dashboard/widgets.dart index 5ad9bae88..2ac4d63b5 100644 --- a/lib/widgets/dashboard/widgets.dart +++ b/lib/widgets/dashboard/widgets.dart @@ -565,10 +565,9 @@ class _DashboardWorkoutWidgetState extends State { class NothingFound extends StatelessWidget { final String _title; final String _titleForm; - final Widget? _form; - final VoidCallback? onPressed; + final Widget _form; - const NothingFound(this._title, this._titleForm, this._form, {this.onPressed}); + const NothingFound(this._title, this._titleForm, this._form); @override Widget build(BuildContext context) { @@ -584,19 +583,16 @@ class NothingFound extends StatelessWidget { Icons.add_box, color: wgerPrimaryButtonColor, ), - onPressed: onPressed ?? - () async { - if (_form != null) { - Navigator.pushNamed( - context, - FormScreen.routeName, - arguments: FormScreenArguments( - _titleForm, - _form!, - ), - ); - } - }, + onPressed: () async { + Navigator.pushNamed( + context, + FormScreen.routeName, + arguments: FormScreenArguments( + _titleForm, + _form, + ), + ); + }, ), ], ), From ad83cfb20dafc3d37c66115a4cffe867874c3747 Mon Sep 17 00:00:00 2001 From: Bujdy Date: Thu, 6 Oct 2022 11:27:18 +0200 Subject: [PATCH 4/4] changed weight layout, added option to add measurement category, added navigation to measurement --- lib/l10n/app_en.arb | 6 +++- lib/widgets/dashboard/widgets.dart | 49 ++++++++++++++++++++---------- 2 files changed, 38 insertions(+), 17 deletions(-) diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index 20291659e..ad8c004ce 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -384,9 +384,13 @@ "description": "Message shown when the user has no logged weight entries" }, "noMeasurementEntries": "You have no measurement entries", - "@noMeasurementsntries": { + "@noMeasurementntries": { "description": "Message shown when the user has no logged measurement entries" }, + "moreMeasurementEntries": "Add new measurement", + "@moreMeasurementEntries": { + "description": "Message shown when the user wants to add new measurement" + }, "edit": "Edit", "@edit": {}, "loadingText": "Loading...", diff --git a/lib/widgets/dashboard/widgets.dart b/lib/widgets/dashboard/widgets.dart index 2ac4d63b5..fa8182ce8 100644 --- a/lib/widgets/dashboard/widgets.dart +++ b/lib/widgets/dashboard/widgets.dart @@ -31,6 +31,7 @@ import 'package:wger/providers/nutrition.dart'; import 'package:wger/providers/workout_plans.dart'; import 'package:wger/screens/form_screen.dart'; import 'package:wger/screens/gym_mode.dart'; +import 'package:wger/screens/measurement_categories_screen.dart'; import 'package:wger/screens/nutritional_plan_screen.dart'; import 'package:wger/screens/weight_screen.dart'; import 'package:wger/screens/workout_plan_screen.dart'; @@ -260,19 +261,6 @@ class _DashboardWeightWidgetState extends State { FontAwesomeIcons.weight, color: Colors.black, ), - trailing: IconButton( - icon: const Icon(Icons.add), - onPressed: () async { - Navigator.pushNamed( - context, - FormScreen.routeName, - arguments: FormScreenArguments( - AppLocalizations.of(context).newEntry, - WeightForm(), - ), - ); - }, - ), ), Column( children: [ @@ -287,13 +275,26 @@ class _DashboardWeightWidgetState extends State { .toList()), ), Row( - mainAxisAlignment: MainAxisAlignment.end, + mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ TextButton( child: Text(AppLocalizations.of(context).goToDetailPage), onPressed: () { Navigator.of(context).pushNamed(WeightScreen.routeName); }), + IconButton( + icon: const Icon(Icons.add), + onPressed: () async { + Navigator.pushNamed( + context, + FormScreen.routeName, + arguments: FormScreenArguments( + AppLocalizations.of(context).newEntry, + WeightForm(), + ), + ); + }, + ), ], ), ], @@ -326,14 +327,23 @@ class _DashboardMeasurementWidgetState extends State Widget build(BuildContext context) { final _provider = Provider.of(context, listen: false); - var items = _provider.categories - .map( + List items = _provider.categories + .map( (item) => CategoriesCard( item, elevation: 0, ), ) .toList(); + if (items.isNotEmpty) { + items.add( + NothingFound( + AppLocalizations.of(context).moreMeasurementEntries, + AppLocalizations.of(context).newEntry, + MeasurementCategoryForm(), + ), + ); + } return Consumer( builder: (context, workoutProvider, child) => Card( child: Column( @@ -348,6 +358,13 @@ class _DashboardMeasurementWidgetState extends State FontAwesomeIcons.weight, color: Colors.black, ), + trailing: IconButton( + icon: const Icon(Icons.arrow_forward), + onPressed: () => Navigator.pushNamed( + context, + MeasurementCategoriesScreen.routeName, + ), + ), ), Column( children: [