]> git.proxmox.com Git - flutter/proxmox_login_manager.git/commitdiff
login form: move condition into handler
authorDominik Csapak <d.csapak@proxmox.com>
Tue, 13 Sep 2022 09:45:13 +0000 (11:45 +0200)
committerDominik Csapak <d.csapak@proxmox.com>
Fri, 21 Apr 2023 12:17:08 +0000 (14:17 +0200)
move the if(snapshot.hasData) check into the onPressed handler instead
of generating a new widget, that way the widget is not recreated
every time the condition changes and the code gets much shorter

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

index 2d9615327fd75cff9722d117ba6a72c30b5efab0..fe79c505e6b3bc5b9624a60d7b99956d989384b1 100644 (file)
@@ -323,63 +323,38 @@ class _ProxmoxLoginPageState extends State<ProxmoxLoginPage> {
                                         }
                                       : null,
                                 ),
-                                if (snapshot.hasData)
-                                  Expanded(
-                                    child: Align(
-                                      alignment: Alignment.bottomCenter,
-                                      child: Container(
-                                        width:
-                                            MediaQuery.of(context).size.width,
-                                        child: TextButton(
-                                          onPressed: _submittButtonEnabled
-                                              ? () {
-                                                  final isValid = _formKey
-                                                      .currentState!
-                                                      .validate();
-                                                  setState(() {
-                                                    _submittButtonEnabled =
-                                                        isValid;
-                                                  });
-                                                  if (isValid) {
+                                Expanded(
+                                  child: Align(
+                                    alignment: Alignment.bottomCenter,
+                                    child: Container(
+                                      width: MediaQuery.of(context).size.width,
+                                      child: TextButton(
+                                        onPressed: _submittButtonEnabled
+                                            ? () {
+                                                final isValid = _formKey
+                                                    .currentState!
+                                                    .validate();
+                                                setState(() {
+                                                  _submittButtonEnabled =
+                                                      isValid;
+                                                });
+                                                if (isValid) {
+                                                  if (snapshot.hasData) {
                                                     _onLoginButtonPressed();
-                                                  }
-                                                }
-                                              : null,
-                                          child: Text('Continue'),
-                                        ),
-                                      ),
-                                    ),
-                                  ),
-                                if (!snapshot.hasData)
-                                  Expanded(
-                                    child: Align(
-                                      alignment: Alignment.bottomCenter,
-                                      child: Container(
-                                        width:
-                                            MediaQuery.of(context).size.width,
-                                        child: TextButton(
-                                          onPressed: _submittButtonEnabled
-                                              ? () {
-                                                  final isValid = _formKey
-                                                      .currentState!
-                                                      .validate();
-                                                  setState(() {
-                                                    _submittButtonEnabled =
-                                                        isValid;
-                                                  });
-                                                  if (isValid) {
+                                                  } else {
                                                     setState(() {
                                                       _accessDomains =
                                                           _getAccessDomains();
                                                     });
                                                   }
                                                 }
-                                              : null,
-                                          child: Text('Continue'),
-                                        ),
+                                              }
+                                            : null,
+                                        child: Text('Continue'),
                                       ),
                                     ),
                                   ),
+                                ),
                               ],
                             ),
                           );