diff --git a/lib/redux/app/app_middleware.dart b/lib/redux/app/app_middleware.dart index 1bf7fbdc8..ef088498d 100644 --- a/lib/redux/app/app_middleware.dart +++ b/lib/redux/app/app_middleware.dart @@ -215,7 +215,7 @@ Middleware _createLoadState( final Completer completer = Completer(); completer.future.then((_) { if (uiState.layout == AppLayout.mobile) { - store.dispatch(ViewDashboard(action.context)); + store.dispatch(ViewDashboard(context: action.context)); } else { store.dispatch(ViewMainScreen(action.context)); } @@ -426,6 +426,14 @@ void _setLastLoadWasSuccesfull() async { */ bool hasChanges(Store store, dynamic action) { + if (action.context == null) { + print('WARNING: context is null in hasChanges'); + return false; + } else if (action.force == null) { + print('WARNING: force is null in hasChanges'); + return false; + } + if (store.state.hasChanges() && !isMobile(action.context) && !action.force) { showDialog( context: action.context, @@ -436,4 +444,4 @@ bool hasChanges(Store store, dynamic action) { } else { return false; } -} \ No newline at end of file +} diff --git a/lib/redux/app/app_state.dart b/lib/redux/app/app_state.dart index 68ebd8353..0b774da10 100644 --- a/lib/redux/app/app_state.dart +++ b/lib/redux/app/app_state.dart @@ -21,6 +21,7 @@ import 'package:invoiceninja_flutter/redux/project/project_state.dart'; import 'package:invoiceninja_flutter/redux/payment/payment_state.dart'; import 'package:invoiceninja_flutter/redux/quote/quote_state.dart'; import 'package:invoiceninja_flutter/ui/client/edit/client_edit_vm.dart'; +import 'package:invoiceninja_flutter/ui/product/edit/product_edit_vm.dart'; part 'app_state.g.dart'; @@ -209,6 +210,10 @@ abstract class AppState implements Built { case ClientEditScreen.route: return clientUIState.editing.isNew || clientState.map[clientUIState.editing.id] != clientUIState.editing; + case ProductEditScreen.route: + return productUIState.editing.isNew || + productState.map[productUIState.editing.id] != + productUIState.editing; } if (uiState.currentRoute.endsWith('/edit')) { diff --git a/lib/redux/client/client_actions.dart b/lib/redux/client/client_actions.dart index 6f61ab4e1..88a658e5a 100644 --- a/lib/redux/client/client_actions.dart +++ b/lib/redux/client/client_actions.dart @@ -36,12 +36,14 @@ class EditClient implements PersistUI { @required this.context, this.contact, this.completer, + this.force = false, this.trackRoute = true}); final ClientEntity client; final ContactEntity contact; final BuildContext context; final Completer completer; + final bool force; final bool trackRoute; } diff --git a/lib/redux/dashboard/dashboard_actions.dart b/lib/redux/dashboard/dashboard_actions.dart index 29584b724..b099158f7 100644 --- a/lib/redux/dashboard/dashboard_actions.dart +++ b/lib/redux/dashboard/dashboard_actions.dart @@ -6,9 +6,10 @@ import 'package:invoiceninja_flutter/data/models/models.dart'; import 'package:invoiceninja_flutter/redux/app/app_actions.dart'; class ViewDashboard implements PersistUI { - ViewDashboard([this.context]); + ViewDashboard({@required this.context, this.force = false}); final BuildContext context; + final bool force; } class UpdateDashboardSettings implements PersistUI { diff --git a/lib/redux/dashboard/dashboard_middleware.dart b/lib/redux/dashboard/dashboard_middleware.dart index 1af20f191..06adb794f 100644 --- a/lib/redux/dashboard/dashboard_middleware.dart +++ b/lib/redux/dashboard/dashboard_middleware.dart @@ -1,4 +1,5 @@ import 'package:flutter/widgets.dart'; +import 'package:invoiceninja_flutter/redux/app/app_middleware.dart'; import 'package:invoiceninja_flutter/redux/client/client_actions.dart'; import 'package:invoiceninja_flutter/redux/ui/ui_actions.dart'; import 'package:invoiceninja_flutter/ui/dashboard/dashboard_screen.dart'; @@ -22,10 +23,15 @@ List> createStoreDashboardMiddleware([ Middleware _createViewDashboard() { return (Store store, dynamic action, NextDispatcher next) { + + if (hasChanges(store, action)) { + return; + } + store.dispatch(LoadDashboard()); store.dispatch(UpdateCurrentRoute(DashboardScreen.route)); - if (action.context != null && isMobile(action.context)) { + if (isMobile(action.context)) { Navigator.of(action.context).pushNamedAndRemoveUntil( DashboardScreen.route, (Route route) => false); } diff --git a/lib/ui/app/app_drawer.dart b/lib/ui/app/app_drawer.dart index 7b6bdfcbb..66c172c23 100644 --- a/lib/ui/app/app_drawer.dart +++ b/lib/ui/app/app_drawer.dart @@ -170,7 +170,7 @@ class AppDrawer extends StatelessWidget { company: company, icon: FontAwesomeIcons.tachometerAlt, title: localization.dashboard, - onTap: () => store.dispatch(ViewDashboard(context)), + onTap: () => store.dispatch(ViewDashboard(context: context)), ), DrawerTile( key: Key(ClientKeys.drawer), diff --git a/lib/ui/app/dialogs/alert_dialog.dart b/lib/ui/app/dialogs/alert_dialog.dart index 4173cfef8..b664ac15b 100644 --- a/lib/ui/app/dialogs/alert_dialog.dart +++ b/lib/ui/app/dialogs/alert_dialog.dart @@ -4,6 +4,7 @@ import 'package:invoiceninja_flutter/utils/localization.dart'; class MessageDialog extends StatelessWidget { const MessageDialog(this.message); + final String message; @override @@ -25,7 +26,10 @@ class MessageDialog extends StatelessWidget { style: Theme.of(context).textTheme.title), */ SizedBox(height: 20.0), - Text(message), + Text( + message, + style: Theme.of(context).textTheme.title, + ), SizedBox(height: 40.0), ElevatedButton( onPressed: () => Navigator.of(context).pop(), diff --git a/lib/ui/auth/login_vm.dart b/lib/ui/auth/login_vm.dart index 43011f6b2..b81214377 100644 --- a/lib/ui/auth/login_vm.dart +++ b/lib/ui/auth/login_vm.dart @@ -68,7 +68,7 @@ class LoginVM { AppBuilder.of(context).rebuild(); if (isMobile(context)) { - store.dispatch(ViewDashboard(context)); + store.dispatch(ViewDashboard(context: context)); } else { store.dispatch(ViewMainScreen(context)); } diff --git a/lib/ui/client/client_screen.dart b/lib/ui/client/client_screen.dart index 2b770538a..9556d81ae 100644 --- a/lib/ui/client/client_screen.dart +++ b/lib/ui/client/client_screen.dart @@ -28,7 +28,7 @@ class ClientScreen extends StatelessWidget { return WillPopScope( onWillPop: () async { - store.dispatch(ViewDashboard(context)); + store.dispatch(ViewDashboard(context: context)); return false; }, child: Scaffold( diff --git a/lib/ui/document/document_screen.dart b/lib/ui/document/document_screen.dart index d58843e7a..177667aa6 100644 --- a/lib/ui/document/document_screen.dart +++ b/lib/ui/document/document_screen.dart @@ -24,7 +24,7 @@ class DocumentScreen extends StatelessWidget { return WillPopScope( onWillPop: () async { - store.dispatch(ViewDashboard(context)); + store.dispatch(ViewDashboard(context: context)); return false; }, child: Scaffold( diff --git a/lib/ui/expense/expense_screen.dart b/lib/ui/expense/expense_screen.dart index ca6532ee6..45a5fb0de 100644 --- a/lib/ui/expense/expense_screen.dart +++ b/lib/ui/expense/expense_screen.dart @@ -24,7 +24,7 @@ class ExpenseScreen extends StatelessWidget { return WillPopScope( onWillPop: () async { - store.dispatch(ViewDashboard(context)); + store.dispatch(ViewDashboard(context: context)); return false; }, child: Scaffold( diff --git a/lib/ui/invoice/invoice_screen.dart b/lib/ui/invoice/invoice_screen.dart index e511494c1..7bcc583e5 100644 --- a/lib/ui/invoice/invoice_screen.dart +++ b/lib/ui/invoice/invoice_screen.dart @@ -23,7 +23,7 @@ class InvoiceScreen extends StatelessWidget { return WillPopScope( onWillPop: () async { - store.dispatch(ViewDashboard(context)); + store.dispatch(ViewDashboard(context: context)); return false; }, child: Scaffold( diff --git a/lib/ui/payment/payment_screen.dart b/lib/ui/payment/payment_screen.dart index a78eeb1b2..7503e3f6f 100644 --- a/lib/ui/payment/payment_screen.dart +++ b/lib/ui/payment/payment_screen.dart @@ -23,7 +23,7 @@ class PaymentScreen extends StatelessWidget { return WillPopScope( onWillPop: () async { - store.dispatch(ViewDashboard(context)); + store.dispatch(ViewDashboard(context: context)); return false; }, child: Scaffold( diff --git a/lib/ui/product/product_screen.dart b/lib/ui/product/product_screen.dart index 5ed9773e8..4c078e1c8 100644 --- a/lib/ui/product/product_screen.dart +++ b/lib/ui/product/product_screen.dart @@ -24,7 +24,7 @@ class ProductScreen extends StatelessWidget { return WillPopScope( onWillPop: () async { - store.dispatch(ViewDashboard(context)); + store.dispatch(ViewDashboard(context: context)); return false; }, child: Scaffold( diff --git a/lib/ui/project/project_screen.dart b/lib/ui/project/project_screen.dart index c1ef29095..10b97fbc0 100644 --- a/lib/ui/project/project_screen.dart +++ b/lib/ui/project/project_screen.dart @@ -23,7 +23,7 @@ class ProjectScreen extends StatelessWidget { return WillPopScope( onWillPop: () async { - store.dispatch(ViewDashboard(context)); + store.dispatch(ViewDashboard(context: context)); return false; }, child: Scaffold( diff --git a/lib/ui/quote/quote_screen.dart b/lib/ui/quote/quote_screen.dart index 3840263f9..a11a67876 100644 --- a/lib/ui/quote/quote_screen.dart +++ b/lib/ui/quote/quote_screen.dart @@ -23,7 +23,7 @@ class QuoteScreen extends StatelessWidget { return WillPopScope( onWillPop: () async { - store.dispatch(ViewDashboard(context)); + store.dispatch(ViewDashboard(context: context)); return false; }, child: Scaffold( diff --git a/lib/ui/task/task_screen.dart b/lib/ui/task/task_screen.dart index bd052ae6f..71163ce7a 100644 --- a/lib/ui/task/task_screen.dart +++ b/lib/ui/task/task_screen.dart @@ -24,7 +24,7 @@ class TaskScreen extends StatelessWidget { return WillPopScope( onWillPop: () async { - store.dispatch(ViewDashboard(context)); + store.dispatch(ViewDashboard(context: context)); return false; }, child: Scaffold( diff --git a/lib/ui/vendor/vendor_screen.dart b/lib/ui/vendor/vendor_screen.dart index 39cedb35e..f3acabcf5 100644 --- a/lib/ui/vendor/vendor_screen.dart +++ b/lib/ui/vendor/vendor_screen.dart @@ -23,7 +23,7 @@ class VendorScreen extends StatelessWidget { return WillPopScope( onWillPop: () async { - store.dispatch(ViewDashboard(context)); + store.dispatch(ViewDashboard(context: context)); return false; }, child: Scaffold(