Skip to content

Conversation

@Michal-MK
Copy link
Contributor

Implements #152064

Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement].
  • I signed the [CLA].
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is [test-exempt].
  • I followed the [breaking change policy] and added [Data Driven Fixes] where supported.
  • All existing and new tests are passing.

There is currently no test here as I am not sure how to do it efficiently, I tried making the painter public and adding the visibleForTestinhg attribute, but then I need to add comments to everything... And even when I did that I did not know how to test the painter itself maybe via Golden tests? I have not done those in the Flutter repo yet. And if it can be done without them then that is definitely a better way. I'll wait for what the review says I should do.

@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact "@test-exemption-reviewer" in the #hackers channel in Chat (don't just cc them here, they won't see it! Use Discord!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@github-actions github-actions bot added framework flutter/packages/flutter repository. See also f: labels. f: material design flutter/packages/flutter/material repository. labels Aug 3, 2024
@Michal-MK
Copy link
Contributor Author

Here is the test I have locally, it draws the scrim with the color, that I validated visually, but how do I check it using a test?

testWidgets('ZoomPageTransition respects scrim color when set', (WidgetTester tester) async {
    final Map<String, WidgetBuilder> routes = <String, WidgetBuilder>{
      '/': (BuildContext context) => Material(
        child: TextButton(
          child: const Text('push'),
          onPressed: () { Navigator.of(context).pushNamed('/b'); },
        ),
      ),
      '/b': (BuildContext context) => Container(color: const Color(0xff00ff00)),
    };

    await tester.pumpWidget(
      MaterialApp(
        routes: routes,
        theme: ThemeData(
          pageTransitionsTheme: const PageTransitionsTheme(
            builders: <TargetPlatform, PageTransitionsBuilder>{
              TargetPlatform.android: ZoomPageTransitionsBuilder(
                scrimColor: Color(0xffff0000),
              ),
            },
          ),
        ),
      ),
    );

    await tester.tap(find.text('push'));

    // Jump to the middle of the animation by pumping 8 frames, the scrim should be partially visible
    for (int i = 0; i < 8; i++) {
      await tester.pump(const Duration(milliseconds: 16));
    }

    final List<SnapshotWidget> snapshotWidgets = tester.widgetList(find.byType(SnapshotWidget)).cast<SnapshotWidget>().toList();

    // Filter only snapshots where the painter is ZoomEnterTransitionPainter going forward

    final List<ZoomEnterTransitionPainter> zoomTransitionPainters = snapshotWidgets.where((SnapshotWidget snapshot) {
      final SnapshotPainter painter = snapshot.painter;
      return painter is ZoomEnterTransitionPainter && !painter.reverse;
    }).map((SnapshotWidget snapshot) => snapshot.painter)
    .cast<ZoomEnterTransitionPainter>()
    .toList();

    final TestDisplay display = tester.binding.platformDispatcher.displays.first;
    final int width = display.size.width.toInt();
    final int height = display.size.height.toInt();
    for (final ZoomEnterTransitionPainter painter in zoomTransitionPainters) {
      final OffsetLayer offsetLayer = OffsetLayer();
      final PaintingContext context = PaintingContext(offsetLayer, Offset.zero & display.size);
      await tester.runAsync(() async {
        final ui.Image image = (await (await ui.ImageDescriptor.raw(
          await ui.ImmutableBuffer.fromUint8List(Uint8List.fromList(List<int>.filled(width * height * 4, 0xFF))),
          width: width,
          height: height,
          pixelFormat: ui.PixelFormat.rgba8888,
        ).instantiateCodec(targetHeight: height, targetWidth: width)).getNextFrame()).image;

        painter.paintSnapshot(context, Offset.zero, display.size, image, display.size, display.devicePixelRatio);
      });
    }
  }, variant: TargetPlatformVariant.only(TargetPlatform.android));

@ElvisOkereke
Copy link

add tests to packages/flutter/test/material/page_transitions_theme_test.dart

@Michal-MK
Copy link
Contributor Author

Michal-MK commented Aug 3, 2024

@ElvisOkereke I know where to add them, the issue is that the class is private, I assume dynamic is not allowed in the official repo so how do I properly test it?

@Piinks Piinks requested a review from QuncCccccc August 7, 2024 18:07
const ZoomPageTransitionsBuilder({
this.allowSnapshotting = true,
this.allowEnterRouteSnapshotting = true,
this.scrimColor,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we set the default value here so we don't need to specifically set the color argument in line 927?

@Michal-MK
Copy link
Contributor Author

@QuncCccccc Sorry it took me so long, I changed the default parameter. But the question about the tests still holds.

@Michal-MK
Copy link
Contributor Author

Ping @QuncCccccc

@QuncCccccc
Copy link
Contributor

@QuncCccccc Sorry it took me so long, I changed the default parameter. But the question about the tests still holds.

Maybe we can provide a golden test so we can visually see the color change for the scrim:) What do you think?

@Michal-MK
Copy link
Contributor Author

Yes that could be the "get out of jail free" card, however I have not created a golden test for this repository yet. I'll have to look at some existing examples on how the image files are handled.

@MitchellGoodwin
Copy link
Contributor

There's another PR that seems to be fixing the same issue at #154057.

@QuncCccccc
Copy link
Contributor

Yes that could be the "get out of jail free" card, however I have not created a golden test for this repository yet. I'll have to look at some existing examples on how the image files are handled.

Ah you can global search "matchesGoldenFile" for some examples:) We probably can wait that PR(#154057) lands first and then add this property. What do you think:)?

@MitchellGoodwin
Copy link
Contributor

I think this PR should wait until the other one lands, then this PR can apply it's property to it, as well as use the test in the other PR as a basis to add another one.

@QuncCccccc
Copy link
Contributor

Looks like #154057 is merged:)! @Michal-MK Can you help resolve the conflicts and add the property?

@dy0gu
Copy link
Contributor

dy0gu commented Sep 5, 2024

Hey, author of #154057 here! I wouldn't mind helping out with this if you want me to. It was tricky for me to figure how to test a change to an animation like this so I think I can help spare you the pain I went through, even if with that part only 👀

@Michal-MK
Copy link
Contributor Author

@dy0gu Hi thanks for the offer, I'll take a look at your test approach and attempt doing it myself (trying to learn, not to dismiss you <3). If I get stuck somewhere I will reach out. Today or over the weekend I'll get the PR ready.

@Michal-MK
Copy link
Contributor Author

@dy0gu In the end I just shamelessly copied your test, had no idea that paints is a global matcher that exists. Initially I was attempting to create the MockCanvas myself and somehow force the painter inside to use it. Your approach is infinitely simpler :D. I do understand what it does. And it avoids a golden which is nice.

@QuncCccccc I changed the code.

Copy link
Contributor

@QuncCccccc QuncCccccc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for the contribution and the test:)!


/// The color of the scrim (background) that fades in and out during the transition.
///
/// If not provided, defaults to current theme's surface color.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// If not provided, defaults to current theme's surface color.
/// If not provided, defaults to current theme's [ColorScheme.surface] color.


/// The color of the scrim (background) that fades in and out during the transition.
///
/// If not provided, defaults to current theme's surface color.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// If not provided, defaults to current theme's surface color.
/// If not provided, defaults to current theme's [ColorScheme.surface] color.


// Pump till animation is half-way through.
await tester.pump();
await tester.pump(const Duration(milliseconds:75));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
await tester.pump(const Duration(milliseconds:75));
await tester.pump(const Duration(milliseconds: 75));


// Pump till animation is half-way through.
await tester.pump();
await tester.pump(const Duration(milliseconds:125));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
await tester.pump(const Duration(milliseconds:125));
await tester.pump(const Duration(milliseconds: 125));

engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 10, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 10, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 10, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 10, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 10, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 11, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 11, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 11, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 11, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 11, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 11, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 11, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 12, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 12, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 12, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 12, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Dec 11, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants