@@ -21,7 +21,6 @@ import 'dart:io';
2121import 'package:drift/native.dart' ;
2222import 'package:flutter/material.dart' ;
2323import 'package:flutter_test/flutter_test.dart' ;
24- import 'package:golden_toolkit/golden_toolkit.dart' ;
2524import 'package:http/http.dart' as http;
2625import 'package:mockito/annotations.dart' ;
2726import 'package:provider/provider.dart' ;
@@ -67,6 +66,7 @@ void main() {
6766 ),
6867 ],
6968 child: MaterialApp (
69+ key: GlobalKey (),
7070 locale: Locale (locale),
7171 localizationsDelegates: AppLocalizations .localizationsDelegates,
7272 supportedLocales: AppLocalizations .supportedLocales,
@@ -84,23 +84,22 @@ void main() {
8484 );
8585 }
8686
87- testGoldens (
87+ testWidgets (
8888 'Test the widgets on the nutritional plan screen' ,
8989 (tester) async {
90- await loadAppFonts ();
91- final globalKey = GlobalKey ();
92- await tester.pumpWidgetBuilder (
93- Material (key: globalKey),
94- wrapper: materialAppWrapper (
95- localizations: [AppLocalizations .delegate],
96- ),
97- surfaceSize: const Size (500 , 1000 ),
98- );
90+ tester.view.physicalSize = const Size (500 , 1000 );
91+ tester.view.devicePixelRatio = 1.0 ; // Ensure correct pixel ratio
92+
9993 await tester.pumpWidget (createNutritionalPlan ());
10094 await tester.tap (find.byType (TextButton ));
10195 await tester.pumpAndSettle ();
10296
103- await screenMatchesGolden (tester, 'nutritional_plan_1_default_view' , skip: ! Platform .isLinux);
97+ if (Platform .isLinux) {
98+ await expectLater (
99+ find.byType (NutritionalPlanScreen ),
100+ matchesGoldenFile ('goldens/nutritional_plan_1_default_view.png' ),
101+ );
102+ }
104103
105104 // Default view shows plan description, info button, and no ingredients
106105 expect (find.text ('Less fat, more protein' ), findsOneWidget);
@@ -113,11 +112,13 @@ void main() {
113112 var infoOutlineButtons = find.byIcon (Icons .info_outline);
114113 await tester.tap (infoOutlineButtons.first); // 2nd button shows up also, but is off-screen
115114 await tester.pumpAndSettle ();
116- await screenMatchesGolden (
117- tester,
118- 'nutritional_plan_2_one_meal_with_ingredients' ,
119- skip: ! Platform .isLinux,
120- );
115+
116+ if (Platform .isLinux) {
117+ await expectLater (
118+ find.byType (NutritionalPlanScreen ),
119+ matchesGoldenFile ('goldens/nutritional_plan_2_one_meal_with_ingredients.png' ),
120+ );
121+ }
121122
122123 // Ingredients show up now
123124 expect (find.text ('100g Water' ), findsOneWidget);
@@ -136,19 +137,27 @@ void main() {
136137
137138 await tester.tap (infoOutlineButtons.first);
138139 await tester.pumpAndSettle ();
139- await screenMatchesGolden (
140- tester,
141- 'nutritional_plan_3_both_meals_with_ingredients' ,
142- skip: ! Platform .isLinux,
143- );
140+
141+ if (Platform .isLinux) {
142+ await expectLater (
143+ find.byType (MaterialApp ),
144+ matchesGoldenFile ('goldens/nutritional_plan_3_both_meals_with_ingredients.png' ),
145+ );
146+ }
147+
144148 expect (find.byIcon (Icons .info_outline), findsOneWidget);
145149 expect (find.byIcon (Icons .info), findsNWidgets (2 ));
146150
147151 await tester.scrollUntilVisible (find.text ('300g Broccoli cake' ), 30 );
148152 expect (find.text ('300g Broccoli cake' ), findsOneWidget);
149153
150154 expect (find.byType (Card ), findsNWidgets (3 ));
155+
156+ // Restore the original window size.
157+ tester.view.resetPhysicalSize ();
158+ tester.view.resetDevicePixelRatio ();
151159 },
160+ tags: ['golden' ],
152161 );
153162
154163 testWidgets ('Tests the localization of times - EN' , (WidgetTester tester) async {
0 commit comments