toPngFile static method
filePath is where to write the PNG. If null, writes under the OS
temp root; stale files accumulate until cleaned up by the caller.
Implementation
static Future<String> toPngFile({
required Widget widget,
required Size size,
double pixelRatio = 2.0,
Duration waitBeforeCapture = Duration.zero,
ThemeData? theme,
String? filePath,
}) async {
final bytes = await toPng(
widget: widget,
size: size,
pixelRatio: pixelRatio,
waitBeforeCapture: waitBeforeCapture,
theme: theme,
);
final path = filePath ?? _defaultPngPath();
final file = File(path);
await file.parent.create(recursive: true);
await file.writeAsBytes(bytes, flush: true);
return file.path;
}