@@ -16,42 +16,35 @@ class GoldenCamera {
16
16
/// along with its [description] .
17
17
///
18
18
/// {@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.
19
24
Future <void > takePhoto (String description, [Finder ? finder]) async {
20
25
finder = finder ?? find.byType (GoldenImageBounds );
21
26
22
27
expect (finder, findsOne);
23
28
24
29
final renderObject = finder.evaluate ().first.findRenderObject ();
25
30
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
+ }
39
36
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;
46
40
47
- final paintingContext = TestRecordingPaintingContext (canvas);
48
- renderObject.paint (paintingContext, Offset .zero);
41
+ final paintingContext = TestRecordingPaintingContext (canvas);
42
+ renderObject.paint (paintingContext, Offset .zero);
49
43
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
+ );
55
48
56
49
_photos.add (
57
50
GoldenPhoto (description, photo),
0 commit comments