From df45bd4280b9bfff962981ccfb838a54bb844c3c Mon Sep 17 00:00:00 2001 From: Abhishek Saini <78199221+Abhisheksainii@users.noreply.github.com> Date: Wed, 1 Nov 2023 19:14:32 +0530 Subject: [PATCH 1/3] app performance related issues fixes --- android/build.gradle | 2 +- lib/providers/body_weight.dart | 2 + lib/providers/measurement.dart | 2 + lib/providers/nutrition.dart | 2 + lib/providers/workout_plans.dart | 2 + lib/screens/home_tabs_screen.dart | 64 +++++++++++----------- lib/widgets/core/app_bar.dart | 4 +- lib/widgets/dashboard/widgets.dart | 88 ++++++++++++++++++++++++++++-- lib/widgets/workouts/app_bar.dart | 2 +- pubspec.lock | 58 +++++++++++--------- pubspec.yaml | 5 +- test_driver/screenshot_driver.dart | 2 +- 12 files changed, 166 insertions(+), 67 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index 58a8c74b..713d7f6e 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -26,6 +26,6 @@ subprojects { project.evaluationDependsOn(':app') } -task clean(type: Delete) { +tasks.register("clean", Delete) { delete rootProject.buildDir } diff --git a/lib/providers/body_weight.dart b/lib/providers/body_weight.dart index 82b0ad4d..46248d4f 100644 --- a/lib/providers/body_weight.dart +++ b/lib/providers/body_weight.dart @@ -38,6 +38,8 @@ class BodyWeightProvider with ChangeNotifier { _entries = entries; } + bool wightDataInit = false; + /// Clears all lists void clear() { _entries = []; diff --git a/lib/providers/measurement.dart b/lib/providers/measurement.dart index 7f2c4ee3..2fc0fb52 100644 --- a/lib/providers/measurement.dart +++ b/lib/providers/measurement.dart @@ -40,6 +40,8 @@ class MeasurementProvider with ChangeNotifier { _categories = []; } + bool measurementDataInit = false; + /// Finds the category by ID MeasurementCategory findCategoryById(int id) { return _categories.firstWhere( diff --git a/lib/providers/nutrition.dart b/lib/providers/nutrition.dart index 789008a3..4e726b59 100644 --- a/lib/providers/nutrition.dart +++ b/lib/providers/nutrition.dart @@ -52,6 +52,8 @@ class NutritionPlansProvider with ChangeNotifier { return [..._plans]; } + bool nutritionDataInit = false; + set ingredients(items) { _ingredients = items; } diff --git a/lib/providers/workout_plans.dart b/lib/providers/workout_plans.dart index 7b8d8fa0..fbb056db 100644 --- a/lib/providers/workout_plans.dart +++ b/lib/providers/workout_plans.dart @@ -159,6 +159,8 @@ class WorkoutPlansProvider with ChangeNotifier { notifyListeners(); } + bool workoutPlansDatainit = false; + /// Fetches a workout plan sparsely, i.e. only with the data on the plan /// object itself and no child attributes Future fetchAndSetPlanSparse(int planId) async { diff --git a/lib/screens/home_tabs_screen.dart b/lib/screens/home_tabs_screen.dart index 87afd2e2..beda6e53 100644 --- a/lib/screens/home_tabs_screen.dart +++ b/lib/screens/home_tabs_screen.dart @@ -75,23 +75,23 @@ class _HomeTabsScreenState extends State with SingleTickerProvid final authProvider = context.read(); if (!authProvider.dataInit) { - final workoutPlansProvider = context.read(); - final nutritionPlansProvider = context.read(); - final exercisesProvider = context.read(); - final galleryProvider = context.read(); - final weightProvider = context.read(); - final measurementProvider = context.read(); - final userProvider = context.read(); + // final workoutPlansProvider = context.read(); + // final nutritionPlansProvider = context.read(); + // final exercisesProvider = context.read(); + // final galleryProvider = context.read(); + + // final userProvider = context.read(); // Base data log('Loading base data'); try { await Future.wait([ authProvider.setServerVersion(), - userProvider.fetchAndSetProfile(), - workoutPlansProvider.fetchAndSetUnits(), - nutritionPlansProvider.fetchIngredientsFromCache(), - exercisesProvider.fetchAndSetExercises(), + context.read().fetchAndSetProfile(), + context.read().fetchAndSetUnits(), + context.read().fetchIngredientsFromCache(), + context.read().fetchAndSetExercises(), + context.read().fetchAndSetGallery(), ]); } catch (e) { log('fire! fire!'); @@ -99,29 +99,29 @@ class _HomeTabsScreenState extends State with SingleTickerProvid } // Plans, weight and gallery - log('Loading plans, weight, measurements and gallery'); - await Future.wait([ - galleryProvider.fetchAndSetGallery(), - nutritionPlansProvider.fetchAndSetAllPlansSparse(), - workoutPlansProvider.fetchAndSetAllPlansSparse(), - weightProvider.fetchAndSetEntries(), - measurementProvider.fetchAndSetAllCategoriesAndEntries(), - ]); + // log('Loading plans, weight, measurements and gallery'); + // await Future.wait([ + // galleryProvider.fetchAndSetGallery(), + // nutritionPlansProvider.fetchAndSetAllPlansSparse(), + // workoutPlansProvider.fetchAndSetAllPlansSparse(), + // weightProvider.fetchAndSetEntries(), + // measurementProvider.fetchAndSetAllCategoriesAndEntries(), + // ]); // Current nutritional plan - log('Loading current nutritional plan'); - if (nutritionPlansProvider.currentPlan != null) { - final plan = nutritionPlansProvider.currentPlan!; - await nutritionPlansProvider.fetchAndSetPlanFull(plan.id!); - } - - // Current workout plan - log('Loading current workout plan'); - if (workoutPlansProvider.activePlan != null) { - final planId = workoutPlansProvider.activePlan!.id!; - await workoutPlansProvider.fetchAndSetWorkoutPlanFull(planId); - workoutPlansProvider.setCurrentPlan(planId); - } + // log('Loading current nutritional plan'); + // if (nutritionPlansProvider.currentPlan != null) { + // final plan = nutritionPlansProvider.currentPlan!; + // await nutritionPlansProvider.fetchAndSetPlanFull(plan.id!); + // } + + // // Current workout plan + // log('Loading current workout plan'); + // if (workoutPlansProvider.activePlan != null) { + // final planId = workoutPlansProvider.activePlan!.id!; + // await workoutPlansProvider.fetchAndSetWorkoutPlanFull(planId); + // workoutPlansProvider.setCurrentPlan(planId); + // } } authProvider.dataInit = true; diff --git a/lib/widgets/core/app_bar.dart b/lib/widgets/core/app_bar.dart index 6e420c79..8f618cd3 100644 --- a/lib/widgets/core/app_bar.dart +++ b/lib/widgets/core/app_bar.dart @@ -29,7 +29,7 @@ import 'package:wger/screens/form_screen.dart'; import 'package:wger/widgets/core/about.dart'; import 'package:wger/widgets/user/forms.dart'; -class MainAppBar extends StatelessWidget with PreferredSizeWidget { +class MainAppBar extends StatelessWidget implements PreferredSizeWidget { final String _title; MainAppBar(this._title); @@ -113,7 +113,7 @@ class MainAppBar extends StatelessWidget with PreferredSizeWidget { } /// App bar that only displays a title -class EmptyAppBar extends StatelessWidget with PreferredSizeWidget { +class EmptyAppBar extends StatelessWidget implements PreferredSizeWidget { final String _title; EmptyAppBar(this._title); diff --git a/lib/widgets/dashboard/widgets.dart b/lib/widgets/dashboard/widgets.dart index fa11ebfd..c8230505 100644 --- a/lib/widgets/dashboard/widgets.dart +++ b/lib/widgets/dashboard/widgets.dart @@ -16,6 +16,8 @@ * along with this program. If not, see . */ +import 'dart:developer'; + import 'package:carousel_slider/carousel_slider.dart'; import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; @@ -24,6 +26,7 @@ import 'package:intl/intl.dart'; 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/auth.dart'; import 'package:wger/providers/body_weight.dart'; import 'package:wger/providers/measurement.dart'; import 'package:wger/providers/nutrition.dart'; @@ -57,8 +60,24 @@ class _DashboardNutritionWidgetState extends State { @override void initState() { super.initState(); - _plan = Provider.of(context, listen: false).currentPlan; - _hasContent = _plan != null; + _initNutritionData(); + } + + Future _initNutritionData() async { + final nutritionPlansProvider = context.read(); + + if (!nutritionPlansProvider.nutritionDataInit) { + log('Loading Nutrition plans'); + await Future.wait([ + nutritionPlansProvider.fetchAndSetAllPlansSparse(), + ]); + log('Loading current nutritional plan'); + if (nutritionPlansProvider.currentPlan != null) { + final plan = nutritionPlansProvider.currentPlan!; + await nutritionPlansProvider.fetchAndSetPlanFull(plan.id!); + } + nutritionPlansProvider.nutritionDataInit = true; + } } List getContent() { @@ -156,6 +175,8 @@ class _DashboardNutritionWidgetState extends State { @override Widget build(BuildContext context) { + _plan = Provider.of(context, listen: true).currentPlan; + _hasContent = _plan != null; return Card( child: Column( children: [ @@ -239,6 +260,24 @@ class DashboardWeightWidget extends StatefulWidget { class _DashboardWeightWidgetState extends State { late BodyWeightProvider weightEntriesData; + @override + void initState() { + // TODO: implement initState + super.initState(); + _initWeightData(); + } + + Future _initWeightData() async { + final weightProvider = context.read(); + if (!weightProvider.wightDataInit) { + log('Loading weight'); + await Future.wait([ + weightProvider.fetchAndSetEntries(), + ]); + weightProvider.wightDataInit = true; + } + } + @override Widget build(BuildContext context) { weightEntriesData = Provider.of(context, listen: false); @@ -318,6 +357,24 @@ class _DashboardMeasurementWidgetState extends State int _current = 0; final CarouselController _controller = CarouselController(); + @override + void initState() { + // TODO: implement initState + super.initState(); + _initMeasurementData(); + } + + Future _initMeasurementData() async { + final measurementProvider = context.read(); + if (!measurementProvider.measurementDataInit) { + log('Loading measurements'); + await Future.wait([ + measurementProvider.fetchAndSetAllCategoriesAndEntries(), + ]); + measurementProvider.measurementDataInit = true; + } + } + @override Widget build(BuildContext context) { final _provider = Provider.of(context, listen: false); @@ -433,8 +490,29 @@ class _DashboardWorkoutWidgetState extends State { @override void initState() { super.initState(); - _workoutPlan = context.read().activePlan; - _hasContent = _workoutPlan != null; + _initWorkoutPlansData(); + } + + Future _initWorkoutPlansData() async { + final workoutPlansProvider = context.read(); + + if (!workoutPlansProvider.workoutPlansDatainit) { + log('Loading Workout plans'); + try { + await Future.wait([ + workoutPlansProvider.fetchAndSetAllPlansSparse(), + ]); + } catch (e, _) { + log(e.toString()); + } + log('Loading current workout plan'); + if (workoutPlansProvider.activePlan != null) { + final planId = workoutPlansProvider.activePlan!.id!; + await workoutPlansProvider.fetchAndSetWorkoutPlanFull(planId); + workoutPlansProvider.setCurrentPlan(planId); + } + workoutPlansProvider.workoutPlansDatainit = true; + } } Widget getTrailing() { @@ -518,6 +596,8 @@ class _DashboardWorkoutWidgetState extends State { @override Widget build(BuildContext context) { + _workoutPlan = Provider.of(context, listen: true).activePlan; + _hasContent = _workoutPlan != null; return Card( child: Column( children: [ diff --git a/lib/widgets/workouts/app_bar.dart b/lib/widgets/workouts/app_bar.dart index ab8bd148..73ce790d 100644 --- a/lib/widgets/workouts/app_bar.dart +++ b/lib/widgets/workouts/app_bar.dart @@ -26,7 +26,7 @@ enum _WorkoutAppBarOptions { contribute, } -class WorkoutOverviewAppBar extends StatelessWidget with PreferredSizeWidget { +class WorkoutOverviewAppBar extends StatelessWidget implements PreferredSizeWidget { @override Widget build(BuildContext context) { return AppBar( diff --git a/pubspec.lock b/pubspec.lock index 9f0f1936..5173e449 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -53,10 +53,10 @@ packages: dependency: transitive description: name: async - sha256: bfe67ef28df125b7dddcea62755991f807aa39a2492a23e1550161692950bbe0 + sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c" url: "https://pub.dev" source: hosted - version: "2.10.0" + version: "2.11.0" boolean_selector: dependency: transitive description: @@ -189,10 +189,10 @@ packages: dependency: transitive description: name: characters - sha256: e6a326c8af69605aec75ed6c187d06b349707a27fbff8222ca9cc2cff167975c + sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605" url: "https://pub.dev" source: hosted - version: "1.2.1" + version: "1.3.0" charcode: dependency: transitive description: @@ -253,10 +253,10 @@ packages: dependency: "direct main" description: name: collection - sha256: cfc915e6923fe5ce6e153b0723c753045de46de1b4d63771530504004a45fae0 + sha256: f092b211a4319e98e5ff58223576de6c2803db36221657b46c82574721240687 url: "https://pub.dev" source: hosted - version: "1.17.0" + version: "1.17.2" conventional_commit: dependency: transitive description: @@ -784,18 +784,18 @@ packages: dependency: transitive description: name: matcher - sha256: "16db949ceee371e9b99d22f88fa3a73c4e59fd0afed0bd25fc336eb76c198b72" + sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e" url: "https://pub.dev" source: hosted - version: "0.12.13" + version: "0.12.16" material_color_utilities: dependency: transitive description: name: material_color_utilities - sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724 + sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41" url: "https://pub.dev" source: hosted - version: "0.2.0" + version: "0.5.0" melos: dependency: transitive description: @@ -808,10 +808,10 @@ packages: dependency: transitive description: name: meta - sha256: "6c268b42ed578a53088d834796959e4a1814b5e9e164f147f580a386e5decf42" + sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3" url: "https://pub.dev" source: hosted - version: "1.8.0" + version: "1.9.1" mime: dependency: transitive description: @@ -824,10 +824,10 @@ packages: dependency: "direct dev" description: name: mockito - sha256: dd61809f04da1838a680926de50a9e87385c1de91c6579629c3d1723946e8059 + sha256: "8b46d7eb40abdda92d62edd01546051f0c27365e65608c284de336dccfef88cc" url: "https://pub.dev" source: hosted - version: "5.4.0" + version: "5.4.1" multi_select_flutter: dependency: "direct main" description: @@ -888,10 +888,10 @@ packages: dependency: transitive description: name: path - sha256: db9d4f58c908a4ba5953fcee2ae317c94889433e5024c27ce74a37f94267945b + sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917" url: "https://pub.dev" source: hosted - version: "1.8.2" + version: "1.8.3" path_parsing: dependency: transitive description: @@ -1157,10 +1157,10 @@ packages: dependency: transitive description: name: source_span - sha256: dd904f795d4b4f3b870833847c461801f6750a9fa8e61ea5ac53f9422b31f250 + sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c" url: "https://pub.dev" source: hosted - version: "1.9.1" + version: "1.10.0" stack_trace: dependency: transitive description: @@ -1221,10 +1221,10 @@ packages: dependency: transitive description: name: test_api - sha256: ad540f65f92caa91bf21dfc8ffb8c589d6e4dc0c2267818b4cc2792857706206 + sha256: "75760ffd7786fffdfb9597c35c5b27eaeec82be8edfb6d71d32651128ed7aab8" url: "https://pub.dev" source: hosted - version: "0.4.16" + version: "0.6.0" timing: dependency: transitive description: @@ -1405,10 +1405,10 @@ packages: dependency: transitive description: name: vm_service - sha256: e7fb6c2282f7631712b69c19d1bff82f3767eea33a2321c14fa59ad67ea391c7 + sha256: c620a6f783fa22436da68e42db7ebbf18b8c44b9a46ab911f666ff09ffd9153f url: "https://pub.dev" source: hosted - version: "9.4.0" + version: "11.7.1" watcher: dependency: transitive description: @@ -1417,6 +1417,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.2" + web: + dependency: transitive + description: + name: web + sha256: dc8ccd225a2005c1be616fe02951e2e342092edf968cf0844220383757ef8f10 + url: "https://pub.dev" + source: hosted + version: "0.1.4-beta" web_socket_channel: dependency: transitive description: @@ -1429,10 +1437,10 @@ packages: dependency: transitive description: name: webdriver - sha256: ef67178f0cc7e32c1494645b11639dd1335f1d18814aa8435113a92e9ef9d841 + sha256: "3c923e918918feeb90c4c9fdf1fe39220fa4c0e8e2c0fffaded174498ef86c49" url: "https://pub.dev" source: hosted - version: "3.0.1" + version: "3.0.2" win32: dependency: transitive description: @@ -1474,5 +1482,5 @@ packages: source: hosted version: "2.1.1" sdks: - dart: ">=2.19.0 <3.0.0" + dart: ">=3.1.0-185.0.dev <4.0.0" flutter: ">=3.7.0" diff --git a/pubspec.yaml b/pubspec.yaml index 04d8178d..80449496 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -24,7 +24,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev version: 1.5.6+34 environment: - sdk: '>=2.17.0 <3.0.0' + sdk: ">=2.17.0 <3.0.0" dependencies: flutter: @@ -60,6 +60,9 @@ dependencies: fl_chart: ^0.62.0 flutter_zxing: ^1.1.2 +dependency_overrides: + intl: any + dev_dependencies: flutter_test: sdk: flutter diff --git a/test_driver/screenshot_driver.dart b/test_driver/screenshot_driver.dart index 476709ee..f98d10c7 100644 --- a/test_driver/screenshot_driver.dart +++ b/test_driver/screenshot_driver.dart @@ -6,7 +6,7 @@ import 'package:integration_test/integration_test_driver_extended.dart'; Future main() async { try { await integrationDriver( - onScreenshot: (String screenshotName, List screenshotBytes) async { + onScreenshot: (String screenshotName, List screenshotBytes, [_]) async { final File image = await File(screenshotName).create(recursive: true); image.writeAsBytesSync(screenshotBytes); return true; From 5ebbbe563a033bf04f32dd68c98f9280b26ecfbf Mon Sep 17 00:00:00 2001 From: Abhishek Saini <78199221+Abhisheksainii@users.noreply.github.com> Date: Wed, 1 Nov 2023 19:20:51 +0530 Subject: [PATCH 2/3] app performance related issues fixes --- lib/providers/body_weight.dart | 2 + lib/providers/measurement.dart | 2 + lib/providers/nutrition.dart | 2 + lib/providers/workout_plans.dart | 2 + lib/screens/home_tabs_screen.dart | 64 +++++++++++----------- lib/widgets/dashboard/widgets.dart | 88 ++++++++++++++++++++++++++++-- pubspec.lock | 58 +++++++++++--------- 7 files changed, 157 insertions(+), 61 deletions(-) diff --git a/lib/providers/body_weight.dart b/lib/providers/body_weight.dart index 82b0ad4d..46248d4f 100644 --- a/lib/providers/body_weight.dart +++ b/lib/providers/body_weight.dart @@ -38,6 +38,8 @@ class BodyWeightProvider with ChangeNotifier { _entries = entries; } + bool wightDataInit = false; + /// Clears all lists void clear() { _entries = []; diff --git a/lib/providers/measurement.dart b/lib/providers/measurement.dart index 7f2c4ee3..2fc0fb52 100644 --- a/lib/providers/measurement.dart +++ b/lib/providers/measurement.dart @@ -40,6 +40,8 @@ class MeasurementProvider with ChangeNotifier { _categories = []; } + bool measurementDataInit = false; + /// Finds the category by ID MeasurementCategory findCategoryById(int id) { return _categories.firstWhere( diff --git a/lib/providers/nutrition.dart b/lib/providers/nutrition.dart index 789008a3..4e726b59 100644 --- a/lib/providers/nutrition.dart +++ b/lib/providers/nutrition.dart @@ -52,6 +52,8 @@ class NutritionPlansProvider with ChangeNotifier { return [..._plans]; } + bool nutritionDataInit = false; + set ingredients(items) { _ingredients = items; } diff --git a/lib/providers/workout_plans.dart b/lib/providers/workout_plans.dart index 7b8d8fa0..fbb056db 100644 --- a/lib/providers/workout_plans.dart +++ b/lib/providers/workout_plans.dart @@ -159,6 +159,8 @@ class WorkoutPlansProvider with ChangeNotifier { notifyListeners(); } + bool workoutPlansDatainit = false; + /// Fetches a workout plan sparsely, i.e. only with the data on the plan /// object itself and no child attributes Future fetchAndSetPlanSparse(int planId) async { diff --git a/lib/screens/home_tabs_screen.dart b/lib/screens/home_tabs_screen.dart index 87afd2e2..beda6e53 100644 --- a/lib/screens/home_tabs_screen.dart +++ b/lib/screens/home_tabs_screen.dart @@ -75,23 +75,23 @@ class _HomeTabsScreenState extends State with SingleTickerProvid final authProvider = context.read(); if (!authProvider.dataInit) { - final workoutPlansProvider = context.read(); - final nutritionPlansProvider = context.read(); - final exercisesProvider = context.read(); - final galleryProvider = context.read(); - final weightProvider = context.read(); - final measurementProvider = context.read(); - final userProvider = context.read(); + // final workoutPlansProvider = context.read(); + // final nutritionPlansProvider = context.read(); + // final exercisesProvider = context.read(); + // final galleryProvider = context.read(); + + // final userProvider = context.read(); // Base data log('Loading base data'); try { await Future.wait([ authProvider.setServerVersion(), - userProvider.fetchAndSetProfile(), - workoutPlansProvider.fetchAndSetUnits(), - nutritionPlansProvider.fetchIngredientsFromCache(), - exercisesProvider.fetchAndSetExercises(), + context.read().fetchAndSetProfile(), + context.read().fetchAndSetUnits(), + context.read().fetchIngredientsFromCache(), + context.read().fetchAndSetExercises(), + context.read().fetchAndSetGallery(), ]); } catch (e) { log('fire! fire!'); @@ -99,29 +99,29 @@ class _HomeTabsScreenState extends State with SingleTickerProvid } // Plans, weight and gallery - log('Loading plans, weight, measurements and gallery'); - await Future.wait([ - galleryProvider.fetchAndSetGallery(), - nutritionPlansProvider.fetchAndSetAllPlansSparse(), - workoutPlansProvider.fetchAndSetAllPlansSparse(), - weightProvider.fetchAndSetEntries(), - measurementProvider.fetchAndSetAllCategoriesAndEntries(), - ]); + // log('Loading plans, weight, measurements and gallery'); + // await Future.wait([ + // galleryProvider.fetchAndSetGallery(), + // nutritionPlansProvider.fetchAndSetAllPlansSparse(), + // workoutPlansProvider.fetchAndSetAllPlansSparse(), + // weightProvider.fetchAndSetEntries(), + // measurementProvider.fetchAndSetAllCategoriesAndEntries(), + // ]); // Current nutritional plan - log('Loading current nutritional plan'); - if (nutritionPlansProvider.currentPlan != null) { - final plan = nutritionPlansProvider.currentPlan!; - await nutritionPlansProvider.fetchAndSetPlanFull(plan.id!); - } - - // Current workout plan - log('Loading current workout plan'); - if (workoutPlansProvider.activePlan != null) { - final planId = workoutPlansProvider.activePlan!.id!; - await workoutPlansProvider.fetchAndSetWorkoutPlanFull(planId); - workoutPlansProvider.setCurrentPlan(planId); - } + // log('Loading current nutritional plan'); + // if (nutritionPlansProvider.currentPlan != null) { + // final plan = nutritionPlansProvider.currentPlan!; + // await nutritionPlansProvider.fetchAndSetPlanFull(plan.id!); + // } + + // // Current workout plan + // log('Loading current workout plan'); + // if (workoutPlansProvider.activePlan != null) { + // final planId = workoutPlansProvider.activePlan!.id!; + // await workoutPlansProvider.fetchAndSetWorkoutPlanFull(planId); + // workoutPlansProvider.setCurrentPlan(planId); + // } } authProvider.dataInit = true; diff --git a/lib/widgets/dashboard/widgets.dart b/lib/widgets/dashboard/widgets.dart index fa11ebfd..c8230505 100644 --- a/lib/widgets/dashboard/widgets.dart +++ b/lib/widgets/dashboard/widgets.dart @@ -16,6 +16,8 @@ * along with this program. If not, see . */ +import 'dart:developer'; + import 'package:carousel_slider/carousel_slider.dart'; import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; @@ -24,6 +26,7 @@ import 'package:intl/intl.dart'; 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/auth.dart'; import 'package:wger/providers/body_weight.dart'; import 'package:wger/providers/measurement.dart'; import 'package:wger/providers/nutrition.dart'; @@ -57,8 +60,24 @@ class _DashboardNutritionWidgetState extends State { @override void initState() { super.initState(); - _plan = Provider.of(context, listen: false).currentPlan; - _hasContent = _plan != null; + _initNutritionData(); + } + + Future _initNutritionData() async { + final nutritionPlansProvider = context.read(); + + if (!nutritionPlansProvider.nutritionDataInit) { + log('Loading Nutrition plans'); + await Future.wait([ + nutritionPlansProvider.fetchAndSetAllPlansSparse(), + ]); + log('Loading current nutritional plan'); + if (nutritionPlansProvider.currentPlan != null) { + final plan = nutritionPlansProvider.currentPlan!; + await nutritionPlansProvider.fetchAndSetPlanFull(plan.id!); + } + nutritionPlansProvider.nutritionDataInit = true; + } } List getContent() { @@ -156,6 +175,8 @@ class _DashboardNutritionWidgetState extends State { @override Widget build(BuildContext context) { + _plan = Provider.of(context, listen: true).currentPlan; + _hasContent = _plan != null; return Card( child: Column( children: [ @@ -239,6 +260,24 @@ class DashboardWeightWidget extends StatefulWidget { class _DashboardWeightWidgetState extends State { late BodyWeightProvider weightEntriesData; + @override + void initState() { + // TODO: implement initState + super.initState(); + _initWeightData(); + } + + Future _initWeightData() async { + final weightProvider = context.read(); + if (!weightProvider.wightDataInit) { + log('Loading weight'); + await Future.wait([ + weightProvider.fetchAndSetEntries(), + ]); + weightProvider.wightDataInit = true; + } + } + @override Widget build(BuildContext context) { weightEntriesData = Provider.of(context, listen: false); @@ -318,6 +357,24 @@ class _DashboardMeasurementWidgetState extends State int _current = 0; final CarouselController _controller = CarouselController(); + @override + void initState() { + // TODO: implement initState + super.initState(); + _initMeasurementData(); + } + + Future _initMeasurementData() async { + final measurementProvider = context.read(); + if (!measurementProvider.measurementDataInit) { + log('Loading measurements'); + await Future.wait([ + measurementProvider.fetchAndSetAllCategoriesAndEntries(), + ]); + measurementProvider.measurementDataInit = true; + } + } + @override Widget build(BuildContext context) { final _provider = Provider.of(context, listen: false); @@ -433,8 +490,29 @@ class _DashboardWorkoutWidgetState extends State { @override void initState() { super.initState(); - _workoutPlan = context.read().activePlan; - _hasContent = _workoutPlan != null; + _initWorkoutPlansData(); + } + + Future _initWorkoutPlansData() async { + final workoutPlansProvider = context.read(); + + if (!workoutPlansProvider.workoutPlansDatainit) { + log('Loading Workout plans'); + try { + await Future.wait([ + workoutPlansProvider.fetchAndSetAllPlansSparse(), + ]); + } catch (e, _) { + log(e.toString()); + } + log('Loading current workout plan'); + if (workoutPlansProvider.activePlan != null) { + final planId = workoutPlansProvider.activePlan!.id!; + await workoutPlansProvider.fetchAndSetWorkoutPlanFull(planId); + workoutPlansProvider.setCurrentPlan(planId); + } + workoutPlansProvider.workoutPlansDatainit = true; + } } Widget getTrailing() { @@ -518,6 +596,8 @@ class _DashboardWorkoutWidgetState extends State { @override Widget build(BuildContext context) { + _workoutPlan = Provider.of(context, listen: true).activePlan; + _hasContent = _workoutPlan != null; return Card( child: Column( children: [ diff --git a/pubspec.lock b/pubspec.lock index 9f0f1936..5173e449 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -53,10 +53,10 @@ packages: dependency: transitive description: name: async - sha256: bfe67ef28df125b7dddcea62755991f807aa39a2492a23e1550161692950bbe0 + sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c" url: "https://pub.dev" source: hosted - version: "2.10.0" + version: "2.11.0" boolean_selector: dependency: transitive description: @@ -189,10 +189,10 @@ packages: dependency: transitive description: name: characters - sha256: e6a326c8af69605aec75ed6c187d06b349707a27fbff8222ca9cc2cff167975c + sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605" url: "https://pub.dev" source: hosted - version: "1.2.1" + version: "1.3.0" charcode: dependency: transitive description: @@ -253,10 +253,10 @@ packages: dependency: "direct main" description: name: collection - sha256: cfc915e6923fe5ce6e153b0723c753045de46de1b4d63771530504004a45fae0 + sha256: f092b211a4319e98e5ff58223576de6c2803db36221657b46c82574721240687 url: "https://pub.dev" source: hosted - version: "1.17.0" + version: "1.17.2" conventional_commit: dependency: transitive description: @@ -784,18 +784,18 @@ packages: dependency: transitive description: name: matcher - sha256: "16db949ceee371e9b99d22f88fa3a73c4e59fd0afed0bd25fc336eb76c198b72" + sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e" url: "https://pub.dev" source: hosted - version: "0.12.13" + version: "0.12.16" material_color_utilities: dependency: transitive description: name: material_color_utilities - sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724 + sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41" url: "https://pub.dev" source: hosted - version: "0.2.0" + version: "0.5.0" melos: dependency: transitive description: @@ -808,10 +808,10 @@ packages: dependency: transitive description: name: meta - sha256: "6c268b42ed578a53088d834796959e4a1814b5e9e164f147f580a386e5decf42" + sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3" url: "https://pub.dev" source: hosted - version: "1.8.0" + version: "1.9.1" mime: dependency: transitive description: @@ -824,10 +824,10 @@ packages: dependency: "direct dev" description: name: mockito - sha256: dd61809f04da1838a680926de50a9e87385c1de91c6579629c3d1723946e8059 + sha256: "8b46d7eb40abdda92d62edd01546051f0c27365e65608c284de336dccfef88cc" url: "https://pub.dev" source: hosted - version: "5.4.0" + version: "5.4.1" multi_select_flutter: dependency: "direct main" description: @@ -888,10 +888,10 @@ packages: dependency: transitive description: name: path - sha256: db9d4f58c908a4ba5953fcee2ae317c94889433e5024c27ce74a37f94267945b + sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917" url: "https://pub.dev" source: hosted - version: "1.8.2" + version: "1.8.3" path_parsing: dependency: transitive description: @@ -1157,10 +1157,10 @@ packages: dependency: transitive description: name: source_span - sha256: dd904f795d4b4f3b870833847c461801f6750a9fa8e61ea5ac53f9422b31f250 + sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c" url: "https://pub.dev" source: hosted - version: "1.9.1" + version: "1.10.0" stack_trace: dependency: transitive description: @@ -1221,10 +1221,10 @@ packages: dependency: transitive description: name: test_api - sha256: ad540f65f92caa91bf21dfc8ffb8c589d6e4dc0c2267818b4cc2792857706206 + sha256: "75760ffd7786fffdfb9597c35c5b27eaeec82be8edfb6d71d32651128ed7aab8" url: "https://pub.dev" source: hosted - version: "0.4.16" + version: "0.6.0" timing: dependency: transitive description: @@ -1405,10 +1405,10 @@ packages: dependency: transitive description: name: vm_service - sha256: e7fb6c2282f7631712b69c19d1bff82f3767eea33a2321c14fa59ad67ea391c7 + sha256: c620a6f783fa22436da68e42db7ebbf18b8c44b9a46ab911f666ff09ffd9153f url: "https://pub.dev" source: hosted - version: "9.4.0" + version: "11.7.1" watcher: dependency: transitive description: @@ -1417,6 +1417,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.2" + web: + dependency: transitive + description: + name: web + sha256: dc8ccd225a2005c1be616fe02951e2e342092edf968cf0844220383757ef8f10 + url: "https://pub.dev" + source: hosted + version: "0.1.4-beta" web_socket_channel: dependency: transitive description: @@ -1429,10 +1437,10 @@ packages: dependency: transitive description: name: webdriver - sha256: ef67178f0cc7e32c1494645b11639dd1335f1d18814aa8435113a92e9ef9d841 + sha256: "3c923e918918feeb90c4c9fdf1fe39220fa4c0e8e2c0fffaded174498ef86c49" url: "https://pub.dev" source: hosted - version: "3.0.1" + version: "3.0.2" win32: dependency: transitive description: @@ -1474,5 +1482,5 @@ packages: source: hosted version: "2.1.1" sdks: - dart: ">=2.19.0 <3.0.0" + dart: ">=3.1.0-185.0.dev <4.0.0" flutter: ">=3.7.0" From 337d83ccbfd922d8d9894c793d7f35f4ff895743 Mon Sep 17 00:00:00 2001 From: Abhishek Saini <78199221+Abhisheksainii@users.noreply.github.com> Date: Sun, 19 Nov 2023 16:47:56 +0530 Subject: [PATCH 3/3] fix(common): removal of const and regeneration of pubspec.lock file --- lib/widgets/measurements/charts.dart | 2 +- lib/widgets/nutrition/charts.dart | 6 +- pubspec.lock | 87 ++++++++++------------------ 3 files changed, 33 insertions(+), 62 deletions(-) diff --git a/lib/widgets/measurements/charts.dart b/lib/widgets/measurements/charts.dart index 66f08c5a..a772f89d 100644 --- a/lib/widgets/measurements/charts.dart +++ b/lib/widgets/measurements/charts.dart @@ -135,7 +135,7 @@ class _MeasurementChartWidgetFlState extends State { color: Theme.of(context).colorScheme.secondary, barWidth: 2, isStrokeCapRound: true, - dotData: const FlDotData( + dotData: FlDotData( show: true, ), ), diff --git a/lib/widgets/nutrition/charts.dart b/lib/widgets/nutrition/charts.dart index cefc8434..129c4505 100644 --- a/lib/widgets/nutrition/charts.dart +++ b/lib/widgets/nutrition/charts.dart @@ -253,17 +253,17 @@ class NutritionalDiaryChartWidgetFlState extends State value % 10 == 0, - getDrawingHorizontalLine: (value) => const FlLine( + getDrawingHorizontalLine: (value) => FlLine( color: Colors.black, strokeWidth: 1, ), diff --git a/pubspec.lock b/pubspec.lock index 4ccb6db6..d211803b 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -5,18 +5,18 @@ packages: dependency: transitive description: name: _fe_analyzer_shared - sha256: ae92f5d747aee634b87f89d9946000c2de774be1d6ac3e58268224348cd0101a + sha256: eb376e9acf6938204f90eb3b1f00b578640d3188b4c8a8ec054f9f479af8d051 url: "https://pub.dev" source: hosted - version: "61.0.0" + version: "64.0.0" analyzer: dependency: transitive description: name: analyzer - sha256: ea3d8652bda62982addfd92fdc2d0214e5f82e43325104990d4f4c4a2a313562 + sha256: "69f54f967773f6c26c7dcb13e93d7ccee8b17a641689da39e878d5cf13b06893" url: "https://pub.dev" source: hosted - version: "5.13.0" + version: "6.2.0" android_metadata: dependency: "direct main" description: @@ -185,14 +185,6 @@ packages: url: "https://pub.dev" source: hosted version: "1.3.0" - charcode: - dependency: transitive - description: - name: charcode - sha256: fb98c0f6d12c920a02ee2d998da788bca066ca5f148492b7085ee23372b12306 - url: "https://pub.dev" - source: hosted - version: "1.3.1" checked_yaml: dependency: transitive description: @@ -230,18 +222,9 @@ packages: description: name: collection sha256: f092b211a4319e98e5ff58223576de6c2803db36221657b46c82574721240687 - url: "https://pub.dev" source: hosted version: "1.17.2" - conventional_commit: - dependency: transitive - description: - name: conventional_commit - sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a - url: "https://pub.dev" - source: hosted - version: "1.18.0" convert: dependency: transitive description: @@ -286,10 +269,10 @@ packages: dependency: transitive description: name: dart_style - sha256: "1efa911ca7086affd35f463ca2fc1799584fb6aa89883cf0af8e3664d6a02d55" + sha256: abd7625e16f51f554ea244d090292945ec4d4be7bfbaf2ec8cccea568919d334 url: "https://pub.dev" source: hosted - version: "2.3.2" + version: "2.3.3" equatable: dependency: "direct main" description: @@ -773,22 +756,14 @@ packages: url: "https://pub.dev" source: hosted version: "0.5.0" - melos: - dependency: transitive - description: - name: melos - sha256: ccbb6ecd8bb3f08ae8f9ce22920d816bff325a98940c845eda0257cd395503ac - url: "https://pub.dev" - source: hosted - version: "3.1.0" meta: dependency: transitive description: name: meta - sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e + sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3" url: "https://pub.dev" source: hosted - version: "1.10.0" + version: "1.9.1" mime: dependency: transitive description: @@ -801,10 +776,6 @@ packages: dependency: "direct dev" description: name: mockito - sha256: "8b46d7eb40abdda92d62edd01546051f0c27365e65608c284de336dccfef88cc" - url: "https://pub.dev" - source: hosted - version: "5.4.1" sha256: "4b693867cee1853c9d1d7ecc1871f27f39b2ef2c13c0d8d8507dfe5bebd8aaf1" url: "https://pub.dev" source: hosted @@ -909,18 +880,18 @@ packages: dependency: transitive description: name: platform - sha256: ae68c7bfcd7383af3629daafb32fb4e8681c7154428da4febcff06200585f102 + sha256: "4a451831508d7d6ca779f7ac6e212b4023dd5a7d08a27a63da33756410e32b76" url: "https://pub.dev" source: hosted - version: "3.1.2" + version: "3.1.0" plugin_platform_interface: dependency: transitive description: name: plugin_platform_interface - sha256: da3fdfeccc4d4ff2da8f8c556704c08f912542c5fb3cf2233ed75372384a034d + sha256: f4f88d4a900933e7267e2b353594774fc0d07fb072b47eedcd5b54e1ea3269f8 url: "https://pub.dev" source: hosted - version: "2.1.6" + version: "2.1.7" pointer_interceptor: dependency: transitive description: @@ -1122,18 +1093,18 @@ packages: dependency: transitive description: name: stack_trace - sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b" + sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5 url: "https://pub.dev" source: hosted - version: "1.11.1" + version: "1.11.0" stream_channel: dependency: transitive description: name: stream_channel - sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7 + sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8" url: "https://pub.dev" source: hosted - version: "2.1.2" + version: "2.1.1" stream_transform: dependency: transitive description: @@ -1178,10 +1149,10 @@ packages: dependency: transitive description: name: test_api - sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b" + sha256: "75760ffd7786fffdfb9597c35c5b27eaeec82be8edfb6d71d32651128ed7aab8" url: "https://pub.dev" source: hosted - version: "0.6.1" + version: "0.6.0" timing: dependency: transitive description: @@ -1218,10 +1189,10 @@ packages: dependency: transitive description: name: url_launcher_ios - sha256: "4ac97281cf60e2e8c5cc703b2b28528f9b50c8f7cebc71df6bdf0845f647268a" + sha256: bba3373219b7abb6b5e0d071b0fe66dfbe005d07517a68e38d4fc3638f35c6d3 url: "https://pub.dev" source: hosted - version: "6.2.0" + version: "6.2.1" url_launcher_linux: dependency: transitive description: @@ -1330,10 +1301,10 @@ packages: dependency: transitive description: name: video_player_avfoundation - sha256: fe73d636f82286a3739f5e644f95f09442cacdc436ebbe5436521dc915f3ecac + sha256: bc923884640d6dc403050586eb40713cdb8d1d84e6886d8aca50ab04c59124c2 url: "https://pub.dev" source: hosted - version: "2.5.1" + version: "2.5.2" video_player_platform_interface: dependency: transitive description: @@ -1354,10 +1325,10 @@ packages: dependency: transitive description: name: vm_service - sha256: c538be99af830f478718b51630ec1b6bee5e74e52c8a802d328d9e71d35d2583 + sha256: c620a6f783fa22436da68e42db7ebbf18b8c44b9a46ab911f666ff09ffd9153f url: "https://pub.dev" source: hosted - version: "11.10.0" + version: "11.7.1" watcher: dependency: transitive description: @@ -1370,10 +1341,10 @@ packages: dependency: transitive description: name: web - sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152 + sha256: dc8ccd225a2005c1be616fe02951e2e342092edf968cf0844220383757ef8f10 url: "https://pub.dev" source: hosted - version: "0.3.0" + version: "0.1.4-beta" web_socket_channel: dependency: transitive description: @@ -1394,10 +1365,10 @@ packages: dependency: transitive description: name: win32 - sha256: "350a11abd2d1d97e0cc7a28a81b781c08002aa2864d9e3f192ca0ffa18b06ed3" + sha256: "7c99c0e1e2fa190b48d25c81ca5e42036d5cac81430ef249027d97b0935c553f" url: "https://pub.dev" source: hosted - version: "5.0.9" + version: "5.1.0" xdg_directories: dependency: transitive description: @@ -1423,5 +1394,5 @@ packages: source: hosted version: "3.1.2" sdks: - dart: ">=3.2.0-194.0.dev <4.0.0" + dart: ">=3.1.0 <4.0.0" flutter: ">=3.13.0"