diff --git a/lib/redux/auth/auth_middleware.dart b/lib/redux/auth/auth_middleware.dart index faab77db4..7da1e8232 100644 --- a/lib/redux/auth/auth_middleware.dart +++ b/lib/redux/auth/auth_middleware.dart @@ -275,6 +275,8 @@ Middleware _createCompany(AuthRepository repository) { store.dispatch(SelectCompany(companyIndex: state.companies.length)); store.dispatch(ViewDashboard( navigator: Navigator.of(action.context), force: true)); + + action.completer.complete(); }), )); }); diff --git a/lib/redux/company/company_actions.dart b/lib/redux/company/company_actions.dart index f706aef72..1d71f0d90 100644 --- a/lib/redux/company/company_actions.dart +++ b/lib/redux/company/company_actions.dart @@ -48,9 +48,10 @@ class SaveCompanyFailure implements StopSaving { } class AddCompany implements StartSaving { - AddCompany(this.context); + AddCompany({this.context, this.completer}); final BuildContext context; + final Completer completer; } class AddCompanySuccess implements StopSaving {} diff --git a/lib/ui/app/menu_drawer_vm.dart b/lib/ui/app/menu_drawer_vm.dart index e2800ae58..b31278575 100644 --- a/lib/ui/app/menu_drawer_vm.dart +++ b/lib/ui/app/menu_drawer_vm.dart @@ -1,4 +1,5 @@ import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; import 'package:flutter_redux/flutter_redux.dart'; import 'package:invoiceninja_flutter/constants.dart'; @@ -7,6 +8,8 @@ import 'package:invoiceninja_flutter/redux/client/client_actions.dart'; import 'package:invoiceninja_flutter/redux/company/company_actions.dart'; import 'package:invoiceninja_flutter/redux/settings/settings_actions.dart'; import 'package:invoiceninja_flutter/ui/app/app_builder.dart'; +import 'package:invoiceninja_flutter/ui/app/dialogs/loading_dialog.dart'; +import 'package:invoiceninja_flutter/utils/completers.dart'; import 'package:invoiceninja_flutter/utils/dialogs.dart'; import 'package:invoiceninja_flutter/utils/localization.dart'; import 'package:redux/redux.dart'; @@ -97,8 +100,20 @@ class MenuDrawerVM { confirmCallback( context: context, message: AppLocalization.of(context).addCompany, - callback: () { - store.dispatch(AddCompany(context)); + callback: () async { + final completer = snackBarCompleter( + context, AppLocalization.of(context).addedCompany, + shouldPop: true); + + store + .dispatch(AddCompany(context: context, completer: completer)); + + await showDialog( + context: context, + barrierDismissible: false, + builder: (BuildContext context) => SimpleDialog( + children: [LoadingDialog()], + )); }); }, ); diff --git a/lib/utils/completers.dart b/lib/utils/completers.dart index 3b656a3dc..1e0f35441 100644 --- a/lib/utils/completers.dart +++ b/lib/utils/completers.dart @@ -37,7 +37,7 @@ Completer snackBarCompleter(BuildContext context, String message, } completer.future.then((_) { - if (shouldPop) { + if (shouldPop && Navigator.of(context).canPop()) { Navigator.of(context).pop(); } if (scaffold != null) { @@ -47,7 +47,7 @@ Completer snackBarCompleter(BuildContext context, String message, ))); } }).catchError((Object error) { - if (shouldPop) { + if (shouldPop && Navigator.of(context).canPop()) { Navigator.of(context).pop(); } showDialog(