Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save Note Popup displays even when none of the note content is modified #211

Closed
SankethBK opened this issue Sep 30, 2024 · 3 comments · Fixed by #232
Closed

Save Note Popup displays even when none of the note content is modified #211

SankethBK opened this issue Sep 30, 2024 · 3 comments · Fixed by #232
Labels
bug Something isn't working ready for development There is a clear solution which can be implemented

Comments

@SankethBK
Copy link
Owner

SankethBK commented Sep 30, 2024

When I tap a note and view it, then try to go back it pops up a 'you have unsaved changes' popup.

ref issue: #209

image

This is the code used for showing unsaved changes popup in note_create_page.dart or note_read_only_page.dart,

    return WillPopScope(
      onWillPop: () async {
        bool? result = await showCloseDialog(context);

        if (result == true) {
          notesBloc.add(RefreshNote());
          return true;
        }
        return false;
      },

NotesBloc stores the state of currently opened note. NoteInitialState is the initial state and controller parameter holds the rich text editor's internal state. It will only be transitioned to NoteUpdatedState when title, createdAt, allNoteAssets or tags is updated. But if user types something into rich text editor without changing any of these, the state will still remain as NoteInitialState as controller takes care of managing rich text editor's state internally. So there's no way to distinguish if an actual edit has happened in such cases.

Solution:
When user clicks on back button in note_create_page.dart or note_read_only_page.dart, retrieve the note from database and compare it with the current note, if its different then only show the popup, otherwise pop the screen.

There are multiple ways for comparing two notes, easiest one can be to compare hash property of notes which will be modified if any of the content is changed. Refer saveNote method to know how hash is updated when a note is changed.

Relevant files:

- lib/features/notes/presentation/pages/note_create_page.dart
- lib/features/notes/presentation/pages/note_read_only_page.dart
- lib/features/notes/data/repositories/notes_repository.dart
@SankethBK SankethBK added bug Something isn't working ready for development There is a clear solution which can be implemented labels Sep 30, 2024
@malachieborohoul
Copy link
Contributor

Hi @SankethBK , I'd like to contribute to this issue. Is that okay?

@SankethBK
Copy link
Owner Author

Hi @malachieborohoul , sure

@malachieborohoul
Copy link
Contributor

Great, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working ready for development There is a clear solution which can be implemented
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants