SankethBK/diaryvault

Support export to plaintext

Closed this issue · 11 comments

Refer documentation of notes schema

We need to display "Export your notes as text file" option in settings, on clicking it it should create a text file by fetching the contents of all notes using fetchNotes function from NotesRepository and write it to a text file and download it.

We don't need to worry about rich text here as these are plain text files. We store plain text for a note in plainText column. So the contents to be displayed for a note would be

Create an accordion with title "Export your notes", it should display two options on expanding "Export as Text file", "Export as PDF" (This issues is only for text file)

On clicking "Export as Text file" all notes will be written into a text file in this format

$title
$created_timestamp
$plaintext_body

and a popup should show the option to download / share that text file (using share_plus package) (refer to the 2nd screen recording)

export_your_notes.webm

Sample code to generate a text file and download it using share_plus.

String fileContent = "$title \n\n $created_at \n\n $plainText"
  Future<String> createAndWriteToFile(String content) async {
    final directory = await getApplicationDocumentsDirectory();
    final file = File('${directory.path}/my_file.txt');
    await file.writeAsString(content);
    return file.path;
  }

  void shareFileWithUser(String filePath) {
    Share.shareXFiles([XFile(filePath)], text: 'Great picture');
  }
  
  ElevatedButton(
  onPressed: () async {
    final filePath = await createAndWriteToFile('Hello, this is your text content.');
    shareFileWithUser(filePath);
  },
  child: Text('Export your notes as text file'),
)

I did a POC with dummy content, it works

export_to_Text.webm

Hello @SankethBK, can I work on this issue?

Hi @Naincy04 , sure assigning this to you

@Naincy04 please confirm if you're working on this

Yeah...I'm still working on it...

But the notes schema documentation reference that u have provided in the first line is not working... can u please link it again?

@Naincy04 thanks for confirming, i have updated the docs to notes. Also for this functionality, can you create a separate folder export under features folder and create a new repository ExportRepository and add exportAllNotesAsPlainText as one of the method on this repository class. (We can place export to PDF logic in same repository class in future). Let us know if you need help with anything else.

Okay...thank you!

Is anyone working on this?

@Naincy04 please confirm if you're working on this

Hi @SankethBK is this issue is completed, if not then can i work on it and can you assign it to me.

Hey @nomanmaniyar , sorry this is already done. I'll create some new issues in 2-3 days