diff --git a/lib/src/screenshot/screenshot.dart b/lib/src/screenshot/screenshot.dart index e581f1fc..2da02065 100644 --- a/lib/src/screenshot/screenshot.dart +++ b/lib/src/screenshot/screenshot.dart @@ -137,6 +137,14 @@ extension TimelineSyncScreenshot on Timeline { List? annotators, }) { final Frame? frame = _caller(); + + if (timeline.mode == TimelineMode.off) { + // ignore: avoid_print + print( + 'Warning: The timeline is off, do not take screenshots for the timeline\n' + ' at ${frame?.member} ${frame?.uri}:${frame?.line}:${frame?.column}', + ); + } final liveElement = _findSingleElement( element: element, snapshot: snapshot, diff --git a/lib/src/spot/snapshot.dart b/lib/src/spot/snapshot.dart index 4598e220..756b13c5 100644 --- a/lib/src/spot/snapshot.dart +++ b/lib/src/spot/snapshot.dart @@ -442,16 +442,18 @@ extension MultiWidgetSelectorMatcher on WidgetSnapshot { final errorBuilder = StringBuffer(); errorBuilder.writeln('Could not find $selector in widget tree'); _dumpWidgetTree(errorBuilder); - timeline.addEvent( - eventType: 'Assertion Failed', - details: errorBuilder.toString(), - color: Colors.red, - screenshot: timeline.takeScreenshotSync( - annotators: [ - HighlightAnnotator.elements(discoveredElements), - ], - ), - ); + if (timeline.mode != TimelineMode.off) { + timeline.addEvent( + eventType: 'Assertion Failed', + details: errorBuilder.toString(), + color: Colors.red, + screenshot: timeline.takeScreenshotSync( + annotators: [ + HighlightAnnotator.elements(discoveredElements), + ], + ), + ); + } fail('Could not find $selector in widget tree'); } } @@ -470,32 +472,36 @@ extension MultiWidgetSelectorMatcher on WidgetSnapshot { }); final tree = findCommonAncestor(discoveredElements).toStringDeep(); - timeline.addEvent( - eventType: 'Assertion Failed', - details: '$errorBuilder\n' - '$tree', - color: Colors.red, - screenshot: timeline.takeScreenshotSync( - annotators: [ - HighlightAnnotator.elements(discoveredElements), - ], - ), - ); + if (timeline.mode != TimelineMode.off) { + timeline.addEvent( + eventType: 'Assertion Failed', + details: '$errorBuilder\n' + '$tree', + color: Colors.red, + screenshot: timeline.takeScreenshotSync( + annotators: [ + HighlightAnnotator.elements(discoveredElements), + ], + ), + ); + } fail(errorBuilder.toString()); } } - timeline.addEvent( - eventType: 'Assertion', - details: - 'Found ${discovered.length} widgets matching $selector.\nExpected: ${min != null ? "min:$min," : ''}${max != null ? "max:$max," : ''}', - color: Colors.grey, - screenshot: timeline.takeScreenshotSync( - annotators: [ - HighlightAnnotator.elements(discoveredElements), - ], - ), - ); + if (timeline.mode != TimelineMode.off) { + timeline.addEvent( + eventType: 'Assertion', + details: + 'Found ${discovered.length} widgets matching $selector.\nExpected: ${min != null ? "min:$min," : ''}${max != null ? "max:$max," : ''}', + color: Colors.grey, + screenshot: timeline.takeScreenshotSync( + annotators: [ + HighlightAnnotator.elements(discoveredElements), + ], + ), + ); + } return this; } }