saveHtmlFile method

Future<String> saveHtmlFile(
  1. String htmlString
)

Implementation

Future<String> saveHtmlFile (String htmlString) async {
  try {
    // Get the application's document directory
    final directory = await getApplicationDocumentsDirectory();

    // Create a specific folder for caching EPUB files

    // Define the file path
    final filePath = '${directory.path}/$title-epub.html';

    // Check if the file already exists
    final file = File(filePath);

    if (!await file.exists()) {
      // Save the file name to memory
      htmlFilesInMemory.add(filePath);
    }
    //  Save file, overwrite if exists
    file.writeAsStringSync(htmlString);
    //  CLEAR UP MEMORY
    epubBookRef!.closeBook();
    //  ENSURE GC INIT
    return filePath;
  } catch (error) {
    debugPrint(error.toString());
    throw Exception(error);
  }
}