From b832f71569e506c97d7e9b878e39a1fe1c1898cf Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Wed, 30 Jun 2021 11:35:07 -0700 Subject: [PATCH] Fix: #22 - Explictly pop to conversations after AddContact Also a few checks to prevent post-acceptence onChange events from breaking context. --- lib/views/addcontactview.dart | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/views/addcontactview.dart b/lib/views/addcontactview.dart index 5947d3fb..a8a1a422 100644 --- a/lib/views/addcontactview.dart +++ b/lib/views/addcontactview.dart @@ -152,9 +152,14 @@ class _AddContactViewState extends State { Future.delayed(const Duration(milliseconds: 500), () { if (globalErrorHandler.importBundleSuccess) { - final snackBar = SnackBar(content: Text(AppLocalizations.of(context)!.successfullAddedContact + importBundle)); - ScaffoldMessenger.of(context).showSnackBar(snackBar); - Navigator.pop(context); + // TODO: This isn't ideal, but because onChange can be fired during this future check + // and because the context can change after being popped we have this kind of double assertion... + // There is probably a better pattern to handle this... + if (AppLocalizations.of(context) != null) { + final snackBar = SnackBar(content: Text(AppLocalizations.of(context)!.successfullAddedContact + importBundle)); + ScaffoldMessenger.of(context).showSnackBar(snackBar); + Navigator.popUntil(context, (route) => route.settings.name == "conversations"); + } } }); },