exportToJson method
Exports data to a JSON file
filename
is the name of the file to export to
Implementation
Future<String> exportToJson(String filename) async {
final data = await getAllStructuredData();
final jsonData = jsonEncode(data);
try {
final directory = await getApplicationDocumentsDirectory();
final file = File('${directory.path}/$filename');
await file.writeAsString(jsonData);
return file.path;
} catch (e) {
// If we can't write to a file, return the JSON data as a string
return jsonData;
}
}