@@ -16,42 +16,35 @@ class GoldenCamera {
1616 /// along with its [description] .
1717 ///
1818 /// {@macro golden_image_bounds_default_finder}
19+ ///
20+ /// The photo captures a screenshot of the entire widget tree, and then extracts the pixels
21+ /// within the [finder] region. This requires moving more pixel data, but this is done so
22+ /// that the photo captures widgets that sit in the app overlay, such as the mobile drag
23+ /// handles, magnifier, or popover toolbar for a text field.
1924 Future <void > takePhoto (String description, [Finder ? finder]) async {
2025 finder = finder ?? find.byType (GoldenImageBounds );
2126
2227 expect (finder, findsOne);
2328
2429 final renderObject = finder.evaluate ().first.findRenderObject ();
2530 late final Image photo;
26- if (renderObject! .isRepaintBoundary) {
27- // The render object that we want to screenshot is already a repaint boundary,
28- // so we can directly request an image from it.
29- final repaintBoundary = finder.evaluate ().first.renderObject! as RenderRepaintBoundary ;
30- photo = await repaintBoundary.toImage (pixelRatio: 1.0 );
31- } else {
32- // The render object that we want to screenshot is NOT a repaint boundary, so we need
33- // to screenshot the entire UI and then extract the region belonging to this widget.
34- if (renderObject is ! RenderBox ) {
35- throw Exception (
36- "Can't take screenshot because the root of the widget tree isn't a RenderBox. It's a ${renderObject .runtimeType }" ,
37- );
38- }
31+ if (renderObject is ! RenderBox ) {
32+ throw Exception (
33+ "Can't take screenshot because the root of the widget tree isn't a RenderBox. It's a ${renderObject .runtimeType }" ,
34+ );
35+ }
3936
40- // TODO: Try the following approach. It probably doesn't work because we're
41- // using a TestRecordingPaintingContext with a non-test version of Canvas.
42- // But maybe it will work out.
43- final pictureRecorder = PictureRecorder ();
44- final canvas = Canvas (pictureRecorder);
45- final screenSize = renderObject.size;
37+ final pictureRecorder = PictureRecorder ();
38+ final canvas = Canvas (pictureRecorder);
39+ final screenSize = renderObject.size;
4640
47- final paintingContext = TestRecordingPaintingContext (canvas);
48- renderObject.paint (paintingContext, Offset .zero);
41+ final paintingContext = TestRecordingPaintingContext (canvas);
42+ renderObject.paint (paintingContext, Offset .zero);
4943
50- photo = await pictureRecorder.endRecording ().toImage (
51- screenSize.width.round (),
52- screenSize.height.round (),
53- );
54- }
44+ photo = await pictureRecorder.endRecording ().toImage (
45+ screenSize.width.round (),
46+ screenSize.height.round (),
47+ );
5548
5649 _photos.add (
5750 GoldenPhoto (description, photo),
0 commit comments