@@ -287,6 +287,89 @@ void main() {
287287 }
288288 }, variant: TargetPlatformVariant .only (TargetPlatform .android), skip: kIsWeb); // [intended] rasterization is not used on the web.
289289
290+
291+ testWidgets (
292+ 'test page transition (_ZoomPageTransition) with rasterization disables snapshotting for enter route' ,
293+ (WidgetTester tester) async {
294+ Iterable <Layer > findLayers (Finder of) {
295+ return tester.layerListOf (
296+ find.ancestor (of: of, matching: find.byType (SnapshotWidget )).first,
297+ );
298+ }
299+
300+ bool isTransitioningWithoutSnapshotting (Finder of) {
301+ // When snapshotting is off, the OpacityLayer and TransformLayer will be
302+ // applied directly.
303+ final Iterable <Layer > layers = findLayers (of);
304+ return layers.whereType <OpacityLayer >().length == 1 &&
305+ layers.whereType <TransformLayer >().length == 1 ;
306+ }
307+
308+ bool isSnapshotted (Finder of) {
309+ final Iterable <Layer > layers = findLayers (of);
310+ // The scrim and the snapshot image are the only two layers.
311+ return layers.length == 2 &&
312+ layers.whereType <OffsetLayer >().length == 1 &&
313+ layers.whereType <PictureLayer >().length == 1 ;
314+ }
315+
316+ await tester.pumpWidget (
317+ MaterialApp (
318+ routes: < String , WidgetBuilder > {
319+ '/1' : (_) => const Material (child: Text ('Page 1' )),
320+ '/2' : (_) => const Material (child: Text ('Page 2' )),
321+ },
322+ initialRoute: '/1' ,
323+ builder: (BuildContext context, Widget ? child) {
324+ final ThemeData themeData = Theme .of (context);
325+ return Theme (
326+ data: themeData.copyWith (
327+ pageTransitionsTheme: PageTransitionsTheme (
328+ builders: < TargetPlatform , PageTransitionsBuilder > {
329+ ...themeData.pageTransitionsTheme.builders,
330+ TargetPlatform .android: const ZoomPageTransitionsBuilder (
331+ allowEnterRouteSnapshotting: false ,
332+ ),
333+ },
334+ ),
335+ ),
336+ child: Builder (builder: (_) => child! ),
337+ );
338+ },
339+ ),
340+ );
341+
342+ final Finder page1Finder = find.text ('Page 1' );
343+ final Finder page2Finder = find.text ('Page 2' );
344+
345+ // Page 1 on top.
346+ expect (isSnapshotted (page1Finder), isFalse);
347+
348+ // Transitioning from page 1 to page 2.
349+ tester.state <NavigatorState >(find.byType (Navigator )).pushNamed ('/2' );
350+ await tester.pump ();
351+ await tester.pump (const Duration (milliseconds: 50 ));
352+
353+ expect (isSnapshotted (page1Finder), isTrue);
354+ expect (isTransitioningWithoutSnapshotting (page2Finder), isTrue);
355+
356+ // Page 2 on top.
357+ await tester.pumpAndSettle ();
358+ expect (isSnapshotted (page2Finder), isFalse);
359+
360+ // Transitioning back from page 2 to page 1.
361+ tester.state <NavigatorState >(find.byType (Navigator )).pop ();
362+ await tester.pump ();
363+ await tester.pump (const Duration (milliseconds: 50 ));
364+
365+ expect (isTransitioningWithoutSnapshotting (page1Finder), isTrue);
366+ expect (isSnapshotted (page2Finder), isTrue);
367+
368+ // Page 1 on top.
369+ await tester.pumpAndSettle ();
370+ expect (isSnapshotted (page1Finder), isFalse);
371+ }, variant: TargetPlatformVariant .only (TargetPlatform .android), skip: kIsWeb); // [intended] rasterization is not used on the web.
372+
290373 testWidgets ('test fullscreen dialog transition' , (WidgetTester tester) async {
291374 await tester.pumpWidget (
292375 const MaterialApp (
0 commit comments