SankethBK / diaryvault

A personal diary application written in Flutter
https://play.google.com/store/apps/details?id=me.sankethbk.dairyapp
MIT License
108 stars 71 forks source link

Support export to plaintext #26

Closed SankethBK closed 1 year ago

SankethBK commented 1 year ago

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

Naincy04 commented 1 year ago

Hello @SankethBK, can I work on this issue?

SankethBK commented 1 year ago

Hi @Naincy04 , sure assigning this to you

SankethBK commented 1 year ago

@Naincy04 please confirm if you're working on this

Naincy04 commented 1 year ago

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

Naincy04 commented 1 year ago

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

SankethBK commented 1 year ago

@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.

Naincy04 commented 1 year ago

Okay...thank you!

PratyushChauhan commented 1 year ago

Is anyone working on this?

SankethBK commented 1 year ago

@Naincy04 please confirm if you're working on this

nomanmaniyar commented 1 year ago

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

SankethBK commented 1 year ago

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