write method
Implementation
Future<ManifestV2> write({
required CaptureReport report,
required Map<String, List<int>> screenshots,
String? outDir,
}) async {
final dir = Directory(outDir ?? report.outDir);
await dir.create(recursive: true);
final captures = <ScreenCapture>[];
for (final capture in report.captures) {
final screen = screenshots[_stem(capture.file)];
if (screen == null) continue;
await File('${dir.path}/${capture.file}').writeAsBytes(screen);
final elements = <ElementCapture>[];
for (final element in capture.elements) {
final png = report.elementPngs[element.file];
if (png == null) continue;
await File('${dir.path}/${element.file}')
.writeAsBytes(base64.decode(png));
elements.add(element);
}
captures.add(ScreenCapture(
platform: capture.platform,
device: capture.device,
locale: capture.locale,
appearance: capture.appearance,
screenId: capture.screenId,
file: capture.file,
width: capture.width,
height: capture.height,
dpr: capture.dpr,
elements: elements,
));
}
final manifest = ManifestV2(
project: report.project,
captures: captures,
gitSha: _nonEmpty(environment['GITHUB_SHA']),
gitBranch: _nonEmpty(environment['GITHUB_REF_NAME']),
);
await File('${dir.path}/manifest.json').writeAsString(
const JsonEncoder.withIndent(' ').convert(manifest.toJson()),
);
return manifest;
}