From e82b948aac0aad62ab13e22f01608c21a4b58ba7 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Tue, 12 Jan 2021 08:32:33 +0200 Subject: [PATCH] Only show save/cancel if there are changes --- lib/redux/app/app_state.dart | 4 +-- lib/redux/ui/ui_state.dart | 2 +- lib/ui/app/edit_scaffold.dart | 50 ++++++++++++++++++++--------------- 3 files changed, 31 insertions(+), 25 deletions(-) diff --git a/lib/redux/app/app_state.dart b/lib/redux/app/app_state.dart index e0dc8d2fc..e7ce93273 100644 --- a/lib/redux/app/app_state.dart +++ b/lib/redux/app/app_state.dart @@ -619,11 +619,9 @@ abstract class AppState implements Built { case TaskStatusEditScreen.route: return hasTaskStatusChanges( taskStatusUIState.editing, taskStatusState.map); - case ExpenseCategoryEditScreen.route: return hasExpenseCategoryChanges( expenseCategoryUIState.editing, expenseCategoryState.map); - case RecurringInvoiceEditScreen.route: return hasRecurringInvoiceChanges( recurringInvoiceUIState.editing, recurringInvoiceState.map); @@ -638,7 +636,7 @@ abstract class AppState implements Built { return hasDesignChanges(designUIState.editing, designState.map); } - if (uiState.currentRoute.startsWith('/settings')) { + if (uiState.isInSettings) { return settingsUIState.isChanged; } diff --git a/lib/redux/ui/ui_state.dart b/lib/redux/ui/ui_state.dart index 93556b9c4..f54130136 100644 --- a/lib/redux/ui/ui_state.dart +++ b/lib/redux/ui/ui_state.dart @@ -197,7 +197,7 @@ abstract class UIState implements Built { bool get isViewing => !isEditing && !isEmailing; - bool get isInSettings => currentRoute.contains('settings'); + bool get isInSettings => currentRoute.startsWith('/settings'); bool get isPreviewing => previewStack.isNotEmpty; } diff --git a/lib/ui/app/edit_scaffold.dart b/lib/ui/app/edit_scaffold.dart index e392f7994..ec50425a5 100644 --- a/lib/ui/app/edit_scaffold.dart +++ b/lib/ui/app/edit_scaffold.dart @@ -38,6 +38,13 @@ class EditScaffold extends StatelessWidget { final store = StoreProvider.of(context); final state = store.state; + bool showButtons = true; + if (state.uiState.isInSettings && + !state.uiState.isEditing && + !state.settingsUIState.isChanged) { + showButtons = false; + } + return WillPopScope( onWillPop: () async { return true; @@ -50,18 +57,19 @@ class EditScaffold extends StatelessWidget { automaticallyImplyLeading: isMobile(context), title: Text(title), actions: [ - SaveCancelButtons( - saveLabel: saveLabel, - isSaving: state.isSaving, - onSavePressed: (context) { - // Clear focus now to prevent un-focus after save from - // marking the form as changed and to hide the keyboard - FocusScope.of(context).unfocus( - disposition: UnfocusDisposition.previouslyFocusedChild); + if (showButtons) + SaveCancelButtons( + saveLabel: saveLabel, + isSaving: state.isSaving, + onSavePressed: (context) { + // Clear focus now to prevent un-focus after save from + // marking the form as changed and to hide the keyboard + FocusScope.of(context).unfocus( + disposition: UnfocusDisposition.previouslyFocusedChild); - onSavePressed(context); + onSavePressed(context); - /* The debouncer has been disabled b/c if you click + /* The debouncer has been disabled b/c if you click save too quickly the changes are lost if (Debouncer.isDebouncing) { Timer(Duration(milliseconds: kDebounceDelay), () { @@ -71,17 +79,17 @@ class EditScaffold extends StatelessWidget { onSavePressed(context); } */ - }, - onCancelPressed: isMobile(context) - ? null - : (context) { - if (onCancelPressed != null) { - onCancelPressed(context); - } else { - store.dispatch(ResetSettings()); - } - }, - ), + }, + onCancelPressed: isMobile(context) + ? null + : (context) { + if (onCancelPressed != null) { + onCancelPressed(context); + } else { + store.dispatch(ResetSettings()); + } + }, + ), ], bottom: appBarBottom, ),