From 4208b05bb4db26cb5a57a20d0682f9f43c986b5a Mon Sep 17 00:00:00 2001 From: Vishesh Handa Date: Tue, 19 May 2020 00:02:07 +0200 Subject: [PATCH] NoteEditor: Only enable 'Discard Changes' option if we have changes Otherwise disable the button. --- lib/editors/checklist_editor.dart | 3 +++ lib/editors/common.dart | 3 +++ lib/editors/journal_editor.dart | 3 +++ lib/editors/markdown_editor.dart | 3 +++ lib/editors/raw_editor.dart | 3 +++ 5 files changed, 15 insertions(+) diff --git a/lib/editors/checklist_editor.dart b/lib/editors/checklist_editor.dart index 4db77c26..31486556 100644 --- a/lib/editors/checklist_editor.dart +++ b/lib/editors/checklist_editor.dart @@ -279,6 +279,9 @@ class ChecklistEditorState extends State _noteModified = true; }); } + + @override + bool get noteModified => _noteModified; } typedef TextChangedFunction = void Function(String); diff --git a/lib/editors/common.dart b/lib/editors/common.dart index bb075d7f..c3c8ae1c 100644 --- a/lib/editors/common.dart +++ b/lib/editors/common.dart @@ -26,6 +26,8 @@ abstract class Editor { abstract class EditorState { Note getNote(); Future addImage(File file); + + bool get noteModified; } class EditorAppBar extends StatelessWidget implements PreferredSizeWidget { @@ -214,6 +216,7 @@ Widget _buildBottomMenuSheet( editor.discardChangesSelected(note); }, + enabled: editorState.noteModified, ), ListTile( leading: Icon(Icons.share), diff --git a/lib/editors/journal_editor.dart b/lib/editors/journal_editor.dart index ffeca4c7..68112215 100644 --- a/lib/editors/journal_editor.dart +++ b/lib/editors/journal_editor.dart @@ -123,6 +123,9 @@ class JournalEditorState extends State implements EditorState { _noteModified = true; }); } + + @override + bool get noteModified => _noteModified; } class _NoteBodyEditor extends StatelessWidget { diff --git a/lib/editors/markdown_editor.dart b/lib/editors/markdown_editor.dart index 61716b4e..d687847b 100644 --- a/lib/editors/markdown_editor.dart +++ b/lib/editors/markdown_editor.dart @@ -163,6 +163,9 @@ class MarkdownEditorState extends State implements EditorState { _noteModified = true; }); } + + @override + bool get noteModified => _noteModified; } class _NoteBodyEditor extends StatelessWidget { diff --git a/lib/editors/raw_editor.dart b/lib/editors/raw_editor.dart index b3e9b6f4..acd73d86 100644 --- a/lib/editors/raw_editor.dart +++ b/lib/editors/raw_editor.dart @@ -119,6 +119,9 @@ class RawEditorState extends State implements EditorState { _noteModified = true; }); } + + @override + bool get noteModified => _noteModified; } class _NoteEditor extends StatelessWidget {