Skip to content

Commit

Permalink
Merge pull request #640 from wger-project/dcm-fix
Browse files Browse the repository at this point in the history
Dcm fixes
  • Loading branch information
Dieterbe authored Sep 18, 2024
2 parents 82db7c0 + f90609f commit cf5a944
Show file tree
Hide file tree
Showing 56 changed files with 409 additions and 486 deletions.
3 changes: 3 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ dart_code_metrics:
- prefer-prefixed-global-constants: false # we don't really care for the 'k' prefix
- prefer-single-widget-per-file: false
- avoid-passing-self-as-argument: false # fairly harmless. and e.g. drift calls are like this
- avoid-passing-async-when-sync-expected: false # we really like to do this in onTap() etc, and it seems harmless
- prefer-match-file-name: false # dieter wants to enable this. but requires a lot of renames. what does roland think?

formatter:
indent: 0
line-length: 100
Expand Down
6 changes: 3 additions & 3 deletions integration_test/1_dashboard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ Widget createDashboardScreen({locale = 'en'}) {
'date': '2022-12-01',
'impression': '3',
'time_start': '17:00',
'time_end': '19:00'
}
]
'time_end': '19:00',
},
],
};
when(mockWorkoutProvider.fetchSessionData()).thenAnswer((a) => Future.value(logs));

Expand Down
4 changes: 1 addition & 3 deletions integration_test/6_weight.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ Widget createWeightScreen({locale = 'en'}) {
supportedLocales: AppLocalizations.supportedLocales,
theme: wgerLightTheme,
home: const WeightScreen(),
routes: {
FormScreen.routeName: (ctx) => const FormScreen(),
},
routes: {FormScreen.routeName: (ctx) => const FormScreen()},
),
);
}
2 changes: 1 addition & 1 deletion integration_test/make_screenshots_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const languages = [
'ru-RU',
'tr-TR',
'uk',
'zh-CN'
'zh-CN',
];

void main() {
Expand Down
2 changes: 1 addition & 1 deletion lib/models/nutrition/ingredient.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
import 'package:json_annotation/json_annotation.dart';
import 'package:wger/helpers/json.dart';
import 'package:wger/models/nutrition/image.dart';
import 'package:wger/models/nutrition/ingredient_image.dart';
import 'package:wger/models/nutrition/nutritional_values.dart';

part 'ingredient.g.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
import 'package:json_annotation/json_annotation.dart';

part 'image.g.dart';
part 'ingredient_image.g.dart';

@JsonSerializable()
class IngredientImage {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/models/nutrition/nutritional_goals.dart
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ class NutritionalGoals {

@override
String toString() {
// ignore: avoid-nullable-interpolation
return 'e: $energy, p: $protein, c: $carbohydrates, cS: $carbohydratesSugar, f: $fat, fS: $fatSaturated, fi: $fiber, s: $sodium';
}

Expand Down
2 changes: 1 addition & 1 deletion lib/providers/nutrition.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import 'package:wger/exceptions/http_exception.dart';
import 'package:wger/exceptions/no_such_entry_exception.dart';
import 'package:wger/helpers/consts.dart';
import 'package:wger/models/exercises/ingredient_api.dart';
import 'package:wger/models/nutrition/image.dart';
import 'package:wger/models/nutrition/ingredient.dart';
import 'package:wger/models/nutrition/ingredient_image.dart';
import 'package:wger/models/nutrition/log.dart';
import 'package:wger/models/nutrition/meal.dart';
import 'package:wger/models/nutrition/meal_item.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/screens/measurement_categories_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class MeasurementCategoriesScreen extends StatelessWidget {
appBar: AppBar(title: Text(AppLocalizations.of(context).measurements)),
floatingActionButton: FloatingActionButton(
child: const Icon(Icons.add, color: Colors.white),
onPressed: () async {
onPressed: () {
Navigator.pushNamed(
context,
FormScreen.routeName,
Expand Down
2 changes: 1 addition & 1 deletion lib/screens/measurement_entries_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class MeasurementEntriesScreen extends StatelessWidget {
),
floatingActionButton: FloatingActionButton(
child: const Icon(Icons.add, color: Colors.white),
onPressed: () async {
onPressed: () {
Navigator.pushNamed(
context,
FormScreen.routeName,
Expand Down
31 changes: 17 additions & 14 deletions lib/screens/nutritional_plan_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,20 +112,23 @@ class NutritionalPlanScreen extends StatelessWidget {
PopupMenuButton<NutritionalPlanOptions>(
icon: const Icon(Icons.more_vert, color: appBarForeground),
onSelected: (value) {
if (value == NutritionalPlanOptions.edit) {
Navigator.pushNamed(
context,
FormScreen.routeName,
arguments: FormScreenArguments(
AppLocalizations.of(context).edit,
PlanForm(nutritionalPlan),
hasListView: true,
),
);
} else if (value == NutritionalPlanOptions.delete) {
Provider.of<NutritionPlansProvider>(context, listen: false)
.deletePlan(nutritionalPlan.id!);
Navigator.of(context).pop();
switch (value) {
case NutritionalPlanOptions.edit:
Navigator.pushNamed(
context,
FormScreen.routeName,
arguments: FormScreenArguments(
AppLocalizations.of(context).edit,
PlanForm(nutritionalPlan),
hasListView: true,
),
);
break;
case NutritionalPlanOptions.delete:
Provider.of<NutritionPlansProvider>(context, listen: false)
.deletePlan(nutritionalPlan.id!);
Navigator.of(context).pop();
break;
}
},
itemBuilder: (BuildContext context) {
Expand Down
2 changes: 1 addition & 1 deletion lib/screens/nutritional_plans_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class NutritionalPlansScreen extends StatelessWidget {
appBar: EmptyAppBar(AppLocalizations.of(context).nutritionalPlans),
floatingActionButton: FloatingActionButton(
child: const Icon(Icons.add, color: Colors.white),
onPressed: () async {
onPressed: () {
Navigator.pushNamed(
context,
FormScreen.routeName,
Expand Down
6 changes: 3 additions & 3 deletions lib/widgets/dashboard/widgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ class _DashboardWeightWidgetState extends State<DashboardWeightWidget> {
MeasurementOverallChangeWidget(
entries7dAvg.first,
entries7dAvg.last,
weightUnit(profile!.isMetric, context),
weightUnit(profile.isMetric, context),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
Expand All @@ -209,7 +209,7 @@ class _DashboardWeightWidgetState extends State<DashboardWeightWidget> {
),
IconButton(
icon: const Icon(Icons.add),
onPressed: () async {
onPressed: () {
Navigator.pushNamed(
context,
FormScreen.routeName,
Expand Down Expand Up @@ -526,7 +526,7 @@ class NothingFound extends StatelessWidget {
IconButton(
iconSize: 30,
icon: const Icon(Icons.add_box, color: wgerPrimaryButtonColor),
onPressed: () async {
onPressed: () {
Navigator.pushNamed(
context,
FormScreen.routeName,
Expand Down
23 changes: 9 additions & 14 deletions lib/widgets/nutrition/charts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,21 @@ import 'package:wger/models/nutrition/nutritional_plan.dart';
import 'package:wger/models/nutrition/nutritional_values.dart';
import 'package:wger/widgets/measurements/charts.dart';

class FlNutritionalPlanGoalWidget extends StatefulWidget {
const FlNutritionalPlanGoalWidget({
super.key,
required NutritionalPlan nutritionalPlan,
}) : _nutritionalPlan = nutritionalPlan;

final NutritionalPlan _nutritionalPlan;

@override
State<StatefulWidget> createState() => FlNutritionalPlanGoalWidgetState();
}

// * fl_chart doesn't support horizontal bar charts yet.
// see https://github.com/imaNNeo/fl_chart/issues/113
// even if it did, i doubt it would let us put text between the gauges/bars
// * LinearProgressIndicator has no way to visualize going beyond 100%, or
// using multiple colors to show multiple components such as surplus, deficit
// * here we draw our own simple gauges that can go beyond 100%,
// and support multiple segments
class FlNutritionalPlanGoalWidgetState extends State<FlNutritionalPlanGoalWidget> {
class FlNutritionalPlanGoalWidget extends StatelessWidget {
const FlNutritionalPlanGoalWidget({
super.key,
required NutritionalPlan nutritionalPlan,
}) : _nutritionalPlan = nutritionalPlan;

final NutritionalPlan _nutritionalPlan;

// normWidth is the width representing 100% completion
// note that if val > plan, we will draw beyond this width
// therefore, caller must set this width to accommodate surpluses.
Expand Down Expand Up @@ -91,7 +86,7 @@ class FlNutritionalPlanGoalWidgetState extends State<FlNutritionalPlanGoalWidget

@override
Widget build(BuildContext context) {
final plan = widget._nutritionalPlan;
final plan = _nutritionalPlan;
final goals = plan.nutritionalGoals;
final today = plan.loggedNutritionalValuesToday;

Expand Down
13 changes: 6 additions & 7 deletions lib/widgets/nutrition/forms.dart
Original file line number Diff line number Diff line change
Expand Up @@ -379,13 +379,12 @@ class IngredientFormState extends State<IngredientForm> {
style: const TextStyle(color: Colors.red),
),
);
} else {
return const SizedBox(
width: 20,
height: 20,
child: CircularProgressIndicator(),
);
}
return const SizedBox(
width: 20,
height: 20,
child: CircularProgressIndicator(),
);
},
),
],
Expand All @@ -394,7 +393,7 @@ class IngredientFormState extends State<IngredientForm> {
ElevatedButton(
key: const Key(SUBMIT_BUTTON_KEY_NAME),
child: Text(AppLocalizations.of(context).save),
onPressed: () async {
onPressed: () {
if (!_form.currentState!.validate()) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/nutrition/helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ void showIngredientDetails(BuildContext context, int id, {void Function()? selec
builder: (context) => FutureBuilder<Ingredient>(
future: Provider.of<NutritionPlansProvider>(context, listen: false).fetchIngredient(id),
builder: (BuildContext context, AsyncSnapshot<Ingredient> snapshot) {
return IngredientDetails(snapshot, select: select);
return IngredientDetails(snapshot, onSelect: select);
},
),
);
Expand Down
19 changes: 12 additions & 7 deletions lib/widgets/nutrition/ingredient_dialogs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ Widget ingredientImage(String url, BuildContext context) {

class IngredientDetails extends StatelessWidget {
final AsyncSnapshot<Ingredient> snapshot;
final void Function()? select;
const IngredientDetails(this.snapshot, {super.key, this.select});
final void Function()? onSelect;
const IngredientDetails(this.snapshot, {super.key, this.onSelect});

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -76,12 +76,12 @@ class IngredientDetails extends StatelessWidget {
),
),
actions: [
if (snapshot.hasData && select != null)
if (snapshot.hasData && onSelect != null)
TextButton(
key: const Key('ingredient-details-continue-button'),
child: Text(MaterialLocalizations.of(context).continueButtonLabel),
onPressed: () {
select!();
onSelect!();
Navigator.of(context).pop();
},
),
Expand All @@ -100,9 +100,14 @@ class IngredientDetails extends StatelessWidget {
class IngredientScanResultDialog extends StatelessWidget {
final AsyncSnapshot<Ingredient?> snapshot;
final String barcode;
final Function(int id, String name, num? amount) selectIngredient;
final Function(int id, String name, num? amount) onSelectIngredient;

const IngredientScanResultDialog(this.snapshot, this.barcode, this.selectIngredient, {super.key});
const IngredientScanResultDialog(
this.snapshot,
this.barcode,
this.onSelectIngredient, {
super.key,
});

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -181,7 +186,7 @@ class IngredientScanResultDialog extends StatelessWidget {
key: const Key('ingredient-scan-result-dialog-confirm-button'),
child: Text(MaterialLocalizations.of(context).continueButtonLabel),
onPressed: () {
selectIngredient(ingredient!.id, ingredient.name, null);
onSelectIngredient(ingredient!.id, ingredient.name, null);
Navigator.of(context).pop();
},
),
Expand Down
5 changes: 1 addition & 4 deletions lib/widgets/nutrition/nutrition_tiles.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ class MealItemValuesTile extends StatelessWidget {
trailing: IconButton(
icon: const Icon(Icons.info_outline),
onPressed: () {
showIngredientDetails(
context,
ingredient.id,
);
showIngredientDetails(context, ingredient.id);
},
),
);
Expand Down
9 changes: 5 additions & 4 deletions test/core/settings_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ void main() {
return ChangeNotifierProvider<ExercisesProvider>(
create: (context) => mockExerciseProvider,
child: MaterialApp(
locale: Locale(locale),
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
home: const SettingsPage()),
locale: Locale(locale),
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
home: const SettingsPage(),
),
);
}

Expand Down
12 changes: 4 additions & 8 deletions test/exercises/exercise_provider_load_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void main() {
await ServiceLocator().configure();
});

setUp(() async {
setUp(() {
WidgetsFlutterBinding.ensureInitialized();
driftRuntimeOptions.dontWarnAboutMultipleDatabases = true;

Expand All @@ -54,12 +54,8 @@ void main() {
provider.languages = [tLanguage1, tLanguage2, tLanguage3];

// Mock base info response
when(
mockBaseProvider.makeUrl(exerciseBaseInfoUrl, id: 9),
).thenReturn(tExerciseBaseInfoUri);
when(
mockBaseProvider.makeUrl(exerciseBaseInfoUrl, id: 1),
).thenReturn(tExerciseBaseInfoUri2);
when(mockBaseProvider.makeUrl(exerciseBaseInfoUrl, id: 9)).thenReturn(tExerciseBaseInfoUri);
when(mockBaseProvider.makeUrl(exerciseBaseInfoUrl, id: 1)).thenReturn(tExerciseBaseInfoUri2);

when(mockBaseProvider.fetch(tExerciseBaseInfoUri))
.thenAnswer((_) => Future.value(tExerciseInfoMap));
Expand Down Expand Up @@ -114,7 +110,7 @@ void main() {
'1f5d2b2f-d4ea-4eeb-9377-56176465e08d',
'ab645585-26ef-4992-a9ec-15425687ece9',
'd8aa5990-bb47-4111-9823-e2fbd98fe07f',
'49a159e1-1e00-409a-81c9-b4d4489fbd67'
'49a159e1-1e00-409a-81c9-b4d4489fbd67',
]);
expect(exercise.videos.map((v) => v.uuid), ['63e996e9-a772-4ca5-9d09-8b4be03f6be4']);

Expand Down
7 changes: 2 additions & 5 deletions test/exercises/exercise_provider_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void main() {
fixture('exercises/exercisebaseinfo_response.json'),
);

setUpAll(() async {
setUpAll(() {
// Needs to be configured here, setUp runs on every test, setUpAll only once
//await ServiceLocator().configure();
});
Expand Down Expand Up @@ -236,10 +236,7 @@ void main() {
// assert
verifyNever(provider.baseProvider.fetch(tSearchByNameUri));

expect(
provider.filteredExercises,
data.getTestExercises(),
);
expect(provider.filteredExercises, data.getTestExercises());
});

test('A muscle is selected with no search term. Should find results', () async {
Expand Down
Loading

0 comments on commit cf5a944

Please sign in to comment.