exportAnnotations method
Export annotations to a custom file path
Implementation
Future<void> exportAnnotations(
Map<int, List<Annotation>> annotations,
String filePath,
) async {
try {
final file = File(filePath);
final Map<String, dynamic> exportData = {
'version': '1.0',
'exported_at': DateTime.now().toIso8601String(),
'annotations': {},
};
for (final entry in annotations.entries) {
final pageNumber = entry.key.toString();
final pageAnnotations = entry.value;
exportData['annotations'][pageNumber] = pageAnnotations
.map((annotation) => annotation.toJson())
.toList();
}
final jsonString = jsonEncode(exportData);
await file.writeAsString(jsonString);
} catch (e) {
throw Exception('Failed to export annotations: $e');
}
}