]> git.proxmox.com Git - flutter/proxmox_login_manager.git/commitdiff
login form: factor out the ConnectionErrorDialog
authorDominik Csapak <d.csapak@proxmox.com>
Tue, 25 Apr 2023 11:16:20 +0000 (13:16 +0200)
committerDominik Csapak <d.csapak@proxmox.com>
Tue, 25 Apr 2023 11:19:21 +0000 (13:19 +0200)
the implementations are nearly identical, but we actually always want to show
some context there.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
lib/proxmox_login_form.dart
lib/proxmox_tfa_form.dart

index 8ae81f609f2e1a7eb282953f9d2292cc1b21220f..d649dafc711ea9c4f247a3ba8b7535e8ab6c041c 100644 (file)
@@ -521,16 +521,7 @@ class _ProxmoxLoginPageState extends State<ProxmoxLoginPage> {
       } else {
         showDialog(
           context: context,
-          builder: (context) => AlertDialog(
-            title: Text('Connection error'),
-            content: Text('Could not establish connection: $e'),
-            actions: [
-              TextButton(
-                onPressed: () => Navigator.of(context).pop(),
-                child: Text('Close'),
-              ),
-            ],
-          ),
+          builder: (context) => ConnectionErrorDialog(exception: e),
         );
       }
     }
@@ -563,18 +554,10 @@ class _ProxmoxLoginPageState extends State<ProxmoxLoginPage> {
       } else {
         if (showConnectionError) {
           showDialog(
-            context: context,
-            builder: (context) => AlertDialog(
-              title: Text('Connection error'),
-              content: Text('Could not establish connection.'),
-              actions: [
-                TextButton(
-                  onPressed: () => Navigator.of(context).pop(),
-                  child: Text('Close'),
-                ),
-              ],
-            ),
-          );
+              context: context,
+              builder: (context) => ConnectionErrorDialog(
+                    exception: e,
+                  ));
         } else {
           throw e;
         }
@@ -681,6 +664,29 @@ class ProxmoxProgressOverlay extends StatelessWidget {
   }
 }
 
+class ConnectionErrorDialog extends StatelessWidget {
+  final exception;
+
+  const ConnectionErrorDialog({
+    Key? key,
+    required this.exception,
+  }) : super(key: key);
+
+  @override
+  Widget build(BuildContext context) {
+    return AlertDialog(
+      title: Text('Connection error'),
+      content: Text('Could not establish connection: ${this.exception}'),
+      actions: [
+        TextButton(
+          onPressed: () => Navigator.of(context).pop(),
+          child: Text('Close'),
+        ),
+      ],
+    );
+  }
+}
+
 class ProxmoxApiErrorDialog extends StatelessWidget {
   final proxclient.ProxmoxApiException exception;
 
index 945c75cb93b1a1306df0dae8be1db5b41d76b297..dfdb921089eab7733d37d39444c263e8ffb75598 100644 (file)
@@ -128,15 +128,8 @@ class _ProxmoxTfaFormState extends State<ProxmoxTfaForm> {
       print(trace);
       showDialog(
         context: context,
-        builder: (context) => AlertDialog(
-          title: Text('Connection error'),
-          content: Text('Could not establish connection.'),
-          actions: [
-            TextButton(
-              onPressed: () => Navigator.of(context).pop(),
-              child: Text('Close'),
-            ),
-          ],
+        builder: (context) => ConnectionErrorDialog(
+          exception: e,
         ),
       );
     }