Skip to content

Commit 4920c2a

Browse files
committed
Fix overflow bug in meal.dart
This should also fix the problem when generating the goldens. The loadAppFonts and the check for Linux was removed as well, if the pseudo-font helps with a constant rendering among all platforms we don't need those.
1 parent a62ef07 commit 4920c2a

10 files changed

+69
-151
lines changed

ios/Podfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,6 @@ SPEC CHECKSUMS:
117117
url_launcher_ios: 694010445543906933d732453a59da0a173ae33d
118118
video_player_avfoundation: 2cef49524dd1f16c5300b9cd6efd9611ce03639b
119119

120-
PODFILE CHECKSUM: 4e8f8b2be68aeea4c0d5beb6ff1e79fface1d048
120+
PODFILE CHECKSUM: 775997f741c536251164e3eacf6e34abf2eb7a17
121121

122122
COCOAPODS: 1.16.2

lib/widgets/nutrition/meal.dart

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -301,40 +301,27 @@ class MealHeader extends StatelessWidget {
301301

302302
@override
303303
Widget build(BuildContext context) {
304+
final subtitleTime = _meal.time != null ? '${_meal.time!.format(context)} / ' : '';
305+
final subtitleCalories = _meal.isRealMeal
306+
? getKcalConsumedVsPlanned(_meal, context)
307+
: getKcalConsumed(_meal, context);
308+
final subtitle = '$subtitleTime $subtitleCalories';
309+
304310
return Column(
305311
crossAxisAlignment: CrossAxisAlignment.start,
306312
children: [
307313
ListTile(
308314
contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
309-
title: Row(children: [
310-
Expanded(
311-
child: Column(
312-
crossAxisAlignment: CrossAxisAlignment.start,
313-
children: [
314-
Text(
315-
_meal.name,
316-
style: Theme.of(context).textTheme.titleLarge,
317-
),
318-
Row(
319-
children: [
320-
if (_meal.time != null)
321-
Text(
322-
_meal.time!.format(context),
323-
style: Theme.of(context).textTheme.titleSmall,
324-
),
325-
if (_meal.time != null) const SizedBox(width: 12),
326-
Text(
327-
_meal.isRealMeal
328-
? getKcalConsumedVsPlanned(_meal, context)
329-
: getKcalConsumed(_meal, context),
330-
style: Theme.of(context).textTheme.titleSmall,
331-
),
332-
],
333-
),
334-
],
335-
),
336-
),
337-
]),
315+
title: Text(
316+
_meal.name,
317+
style: Theme.of(context).textTheme.titleLarge,
318+
overflow: TextOverflow.ellipsis,
319+
),
320+
subtitle: Text(
321+
subtitle,
322+
style: Theme.of(context).textTheme.titleSmall,
323+
overflow: TextOverflow.ellipsis,
324+
),
338325
trailing: Row(
339326
mainAxisSize: MainAxisSize.min,
340327
children: [
-1.12 KB
Loading
-1.57 KB
Loading
-2.42 KB
Loading

test/nutrition/nutritional_plan_screen_test.dart

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
*/
1818

19-
import 'dart:io';
20-
2119
import 'package:drift/native.dart';
2220
import 'package:flutter/material.dart';
2321
import 'package:flutter_test/flutter_test.dart';
@@ -33,7 +31,6 @@ import 'package:wger/providers/nutrition.dart';
3331
import 'package:wger/screens/nutritional_plan_screen.dart';
3432

3533
import '../../test_data/nutritional_plans.dart';
36-
import '../utils.dart';
3734
import 'nutritional_plan_screen_test.mocks.dart';
3835

3936
@GenerateMocks([WgerBaseProvider, AuthProvider, http.Client])
@@ -88,40 +85,34 @@ void main() {
8885
testWidgets(
8986
'Test the widgets on the nutritional plan screen',
9087
(tester) async {
91-
await loadAppFonts();
92-
9388
tester.view.physicalSize = const Size(500, 1000);
9489
tester.view.devicePixelRatio = 1.0; // Ensure correct pixel ratio
9590

9691
await tester.pumpWidget(createNutritionalPlan());
9792
await tester.tap(find.byType(TextButton));
9893
await tester.pumpAndSettle();
9994

100-
if(Platform.isLinux) {
101-
await expectLater(find.byType(NutritionalPlanScreen),
102-
matchesGoldenFile('goldens/nutritional_plan_1_default_view.png'));
103-
}
95+
await expectLater(
96+
find.byType(NutritionalPlanScreen),
97+
matchesGoldenFile('goldens/nutritional_plan_1_default_view.png'),
98+
);
10499

105100
// Default view shows plan description, info button, and no ingredients
106101
expect(find.text('Less fat, more protein'), findsOneWidget);
107-
expect(find.byIcon(Icons.info_outline),
108-
findsNWidgets(3)); // 2 meals, 1 "other logs"
102+
expect(find.byIcon(Icons.info_outline), findsNWidgets(3)); // 2 meals, 1 "other logs"
109103
expect(find.byIcon(Icons.info), findsNothing);
110104
expect(find.text('100g Water'), findsNothing);
111105
expect(find.text('75g Burger soup'), findsNothing);
112106

113107
// tap the first info button changes it and reveals ingredients for the first meal
114108
var infoOutlineButtons = find.byIcon(Icons.info_outline);
115-
await tester.tap(infoOutlineButtons
116-
.first); // 2nd button shows up also, but is off-screen
109+
await tester.tap(infoOutlineButtons.first); // 2nd button shows up also, but is off-screen
117110
await tester.pumpAndSettle();
118111

119-
if(Platform.isLinux) {
120-
await expectLater(
121-
find.byType(NutritionalPlanScreen),
122-
matchesGoldenFile(
123-
'goldens/nutritional_plan_2_one_meal_with_ingredients.png'));
124-
}
112+
await expectLater(
113+
find.byType(NutritionalPlanScreen),
114+
matchesGoldenFile('goldens/nutritional_plan_2_one_meal_with_ingredients.png'),
115+
);
125116

126117
// Ingredients show up now
127118
expect(find.text('100g Water'), findsOneWidget);
@@ -140,12 +131,10 @@ void main() {
140131

141132
await tester.tap(infoOutlineButtons.first);
142133
await tester.pumpAndSettle();
143-
if(Platform.isLinux) {
144-
await expectLater(
145-
find.byType(MaterialApp),
146-
matchesGoldenFile(
147-
'goldens/nutritional_plan_3_both_meals_with_ingredients.png'));
148-
}
134+
await expectLater(
135+
find.byType(MaterialApp),
136+
matchesGoldenFile('goldens/nutritional_plan_3_both_meals_with_ingredients.png'),
137+
);
149138

150139
expect(find.byIcon(Icons.info_outline), findsOneWidget);
151140
expect(find.byIcon(Icons.info), findsNWidgets(2));
@@ -159,19 +148,18 @@ void main() {
159148
tester.view.resetPhysicalSize();
160149
tester.view.resetDevicePixelRatio();
161150
},
151+
tags: ['golden'],
162152
);
163153

164-
testWidgets('Tests the localization of times - EN',
165-
(WidgetTester tester) async {
154+
testWidgets('Tests the localization of times - EN', (WidgetTester tester) async {
166155
await tester.pumpWidget(createNutritionalPlan());
167156
await tester.tap(find.byType(TextButton));
168157
await tester.pumpAndSettle();
169158

170159
expect(find.textContaining('5:00 PM'), findsOneWidget);
171160
});
172161

173-
testWidgets('Tests the localization of times - DE',
174-
(WidgetTester tester) async {
162+
testWidgets('Tests the localization of times - DE', (WidgetTester tester) async {
175163
await tester.pumpWidget(createNutritionalPlan(locale: 'de'));
176164
await tester.tap(find.byType(TextButton));
177165
await tester.pumpAndSettle();

test/utils.dart

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@
1616
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
*/
1818

19-
import 'dart:convert';
20-
21-
import 'package:flutter/services.dart';
22-
import 'package:flutter_test/flutter_test.dart';
2319
import 'package:wger/providers/auth.dart';
2420
import 'package:wger/providers/exercises.dart';
2521

@@ -34,57 +30,3 @@ final AuthProvider testAuthProvider = AuthProvider(MockClient())
3430
// Test Exercises provider
3531
final mockBaseProvider = MockWgerBaseProvider();
3632
final ExercisesProvider testExercisesProvider = ExercisesProvider(mockBaseProvider);
37-
38-
// Load app fonts
39-
Future<void> loadAppFonts() async {
40-
TestWidgetsFlutterBinding.ensureInitialized();
41-
42-
String derivedFontFamily(Map<String, dynamic> fontDefinition) {
43-
const List<String> overridableFonts = <String>[
44-
'Roboto',
45-
'.SF UI Display',
46-
'.SF UI Text',
47-
'.SF Pro Text',
48-
'.SF Pro Display',
49-
];
50-
51-
if (!fontDefinition.containsKey('family')) {
52-
return '';
53-
}
54-
55-
final String fontFamily = fontDefinition['family'];
56-
57-
if (overridableFonts.contains(fontFamily)) {
58-
return fontFamily;
59-
}
60-
61-
if (fontFamily.startsWith('packages/')) {
62-
final fontFamilyName = fontFamily.split('/').last;
63-
if (overridableFonts.any((font) => font == fontFamilyName)) {
64-
return fontFamilyName;
65-
}
66-
} else {
67-
for (final Map<String, dynamic> fontType in fontDefinition['fonts']) {
68-
final String? asset = fontType['asset'];
69-
if (asset != null && asset.startsWith('packages')) {
70-
final packageName = asset.split('/')[1];
71-
return 'packages/$packageName/$fontFamily';
72-
}
73-
}
74-
}
75-
return fontFamily;
76-
}
77-
78-
final fontManifest = await rootBundle.loadStructuredData<Iterable<dynamic>>(
79-
'FontManifest.json',
80-
(string) async => json.decode(string),
81-
);
82-
83-
for (final Map<String, dynamic> font in fontManifest) {
84-
final fontLoader = FontLoader(derivedFontFamily(font));
85-
for (final Map<String, dynamic> fontType in font['fonts']) {
86-
fontLoader.addFont(rootBundle.load(fontType['asset']));
87-
}
88-
await fontLoader.load();
89-
}
90-
}
-577 Bytes
Loading

test/workout/routine_logs_screen_test.dart

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
*/
1818

19-
import 'dart:io';
20-
2119
import 'package:clock/clock.dart';
2220
import 'package:flutter/material.dart';
2321
import 'package:flutter_test/flutter_test.dart';
@@ -31,7 +29,6 @@ import 'package:wger/screens/routine_screen.dart';
3129
import 'package:wger/widgets/routines/workout_logs.dart';
3230

3331
import '../../test_data/routines.dart';
34-
import '../utils.dart';
3532
import 'routine_logs_screen_test.mocks.dart';
3633

3734
@GenerateMocks([RoutinesProvider])
@@ -70,18 +67,21 @@ void main() {
7067
);
7168
}
7269

73-
testWidgets('Smoke test the widgets on the routine logs screen', (WidgetTester tester) async {
74-
await withClock(Clock.fixed(DateTime(2025, 3, 29)), () async {
75-
await loadAppFonts();
76-
await tester.pumpWidget(renderWidget());
77-
await tester.tap(find.byType(TextButton));
78-
await tester.pumpAndSettle();
70+
testWidgets(
71+
'Smoke test the widgets on the routine logs screen',
72+
(WidgetTester tester) async {
73+
await withClock(Clock.fixed(DateTime(2025, 3, 29)), () async {
74+
await tester.pumpWidget(renderWidget());
75+
await tester.tap(find.byType(TextButton));
76+
await tester.pumpAndSettle();
7977

80-
await expectLater(find.byType(WorkoutLogsScreen),
81-
matchesGoldenFile('goldens/routine_logs_screen_detail.png'));
78+
await expectLater(find.byType(WorkoutLogsScreen),
79+
matchesGoldenFile('goldens/routine_logs_screen_detail.png'));
8280

83-
expect(find.text('Training logs'), findsOneWidget);
84-
expect(find.byType(WorkoutLogCalendar), findsOneWidget);
85-
});
86-
});
81+
expect(find.text('Training logs'), findsOneWidget);
82+
expect(find.byType(WorkoutLogCalendar), findsOneWidget);
83+
});
84+
},
85+
tags: ['golden'],
86+
);
8787
}

test/workout/routine_screen_test.dart

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import 'package:wger/providers/routines.dart';
3131
import 'package:wger/screens/routine_screen.dart';
3232

3333
import '../../test_data/routines.dart';
34-
import '../utils.dart';
3534
import 'routine_screen_test.mocks.dart';
3635

3736
@GenerateMocks([WgerBaseProvider])
@@ -70,27 +69,29 @@ void main() {
7069
);
7170
}
7271

73-
testWidgets('Test the widgets on the routine screen',
74-
(WidgetTester tester) async {
75-
await loadAppFonts();
76-
await tester.pumpWidget(renderWidget());
77-
await tester.tap(find.byType(TextButton));
78-
await tester.pumpAndSettle();
72+
testWidgets(
73+
'Test the widgets on the routine screen',
74+
(WidgetTester tester) async {
75+
await tester.pumpWidget(renderWidget());
76+
await tester.tap(find.byType(TextButton));
77+
await tester.pumpAndSettle();
7978

80-
if(Platform.isLinux) {
81-
await expectLater(find.byType(MaterialApp),
82-
matchesGoldenFile('goldens/routine_logs_screen_detail.png'));
83-
}
79+
if (Platform.isLinux) {
80+
await expectLater(
81+
find.byType(MaterialApp), matchesGoldenFile('goldens/routine_logs_screen_detail.png'));
82+
}
8483

85-
expect(find.text('3 day workout'), findsOneWidget);
84+
expect(find.text('3 day workout'), findsOneWidget);
8685

87-
expect(find.text('first day'), findsOneWidget);
88-
expect(find.text('chest, shoulders'), findsOneWidget);
86+
expect(find.text('first day'), findsOneWidget);
87+
expect(find.text('chest, shoulders'), findsOneWidget);
8988

90-
expect(find.text('second day'), findsOneWidget);
91-
expect(find.text('legs'), findsOneWidget);
89+
expect(find.text('second day'), findsOneWidget);
90+
expect(find.text('legs'), findsOneWidget);
9291

93-
expect(find.byType(Card), findsWidgets);
94-
// expect(find.byType(Card), findsNWidgets(4));
95-
});
92+
expect(find.byType(Card), findsWidgets);
93+
// expect(find.byType(Card), findsNWidgets(4));
94+
},
95+
tags: ['golden'],
96+
);
9697
}

0 commit comments

Comments
 (0)