]> git.proxmox.com Git - flutter/proxmox_login_manager.git/blobdiff - lib/proxmox_login_selector.dart
tree wide: check if build context is still valid after async call
[flutter/proxmox_login_manager.git] / lib / proxmox_login_selector.dart
index f51f21c23a403395391ebf06fe96e554ea66f48f..c9ec6f67667a0222d17d95d19731688f9752cea7 100644 (file)
@@ -98,7 +98,8 @@ class _ProxmoxLoginSelectorState extends State<ProxmoxLoginSelector> {
                         subtitle: Text(s.fullUsername),
                         trailing: const Icon(Icons.navigate_next),
                         leading: PopupMenuButton(
-                            icon: const Icon(Icons.more_vert, color: Colors.green),
+                            icon: const Icon(Icons.more_vert,
+                                color: Colors.green),
                             itemBuilder: (context) => [
                                   PopupMenuItem(
                                     child: ListTile(
@@ -112,7 +113,9 @@ class _ProxmoxLoginSelectorState extends State<ProxmoxLoginSelector> {
                                                     (b) => b..ticket = ''))
                                             .saveToDisk();
                                         refreshFromStorage();
-                                        Navigator.of(context).pop();
+                                        if (context.mounted) {
+                                          Navigator.of(context).pop();
+                                        }
                                       },
                                     ),
                                   ),
@@ -156,7 +159,9 @@ class _ProxmoxLoginSelectorState extends State<ProxmoxLoginSelector> {
                                                       b..passwordSaved = false))
                                             .saveToDisk();
                                         refreshFromStorage();
-                                        Navigator.of(context).pop();
+                                        if (context.mounted) {
+                                          Navigator.of(context).pop();
+                                        }
                                       },
                                     ),
                                   ),
@@ -172,7 +177,9 @@ class _ProxmoxLoginSelectorState extends State<ProxmoxLoginSelector> {
                                               (b) => b.logins.remove(login))
                                           .saveToDisk();
                                       refreshFromStorage();
-                                      Navigator.of(context).pop();
+                                      if (context.mounted) {
+                                        Navigator.of(context).pop();
+                                      }
                                     },
                                   ),
                                 ),
@@ -203,16 +210,18 @@ class _ProxmoxLoginSelectorState extends State<ProxmoxLoginSelector> {
       password = await getPassword(user.identifier!);
     }
 
-    final client = await Navigator.of(context).push(MaterialPageRoute(
-        builder: (context) => ProxmoxLoginPage(
-              userModel: user,
-              isCreate: isCreate,
-              ticket: ticket,
-              password: password,
-            )));
-    refreshFromStorage();
-    if (client != null) {
-      widget.onLogin!(client);
+    if (mounted) {
+      final client = await Navigator.of(context).push(MaterialPageRoute(
+          builder: (context) => ProxmoxLoginPage(
+                userModel: user,
+                isCreate: isCreate,
+                ticket: ticket,
+                password: password,
+              )));
+      refreshFromStorage();
+      if (client != null) {
+        widget.onLogin!(client);
+      }
     }
   }