previewInBrowser static method

Future<void> previewInBrowser(
  1. FlintWidget content, {
  2. String? outputPath,
})

Save preview to file and open in browser

Implementation

static Future<void> previewInBrowser(FlintWidget content,
    {String? outputPath}) async {
  final tempDir = Directory.systemTemp;
  final previewFile = File(path.join(tempDir.path,
      'flint_preview_${DateTime.now().millisecondsSinceEpoch}.html'));

  final html = FlintPreview.generatePreviewHtml(content);
  await previewFile.writeAsString(html);

  // Open in default browser
  if (Platform.isWindows) {
    Process.run('start', [previewFile.path], runInShell: true);
  } else if (Platform.isMacOS) {
    Process.run('open', [previewFile.path]);
  } else if (Platform.isLinux) {
    Process.run('xdg-open', [previewFile.path]);
  }

  print('📧 Preview generated: ${previewFile.path}');
}