]> git.proxmox.com Git - flutter/proxmox_login_manager.git/commitdiff
login form: make onOriginSubmitted a required callback
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 5 Jul 2023 10:08:51 +0000 (12:08 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 5 Jul 2023 10:08:53 +0000 (12:08 +0200)
as an user can hit enter on the field to start a submission even if
the submit button is disabled, e.g., due to no origin value being
entered at all yet.

Basically we already had that as contract, as forced dereferencing
via ! for accessing the callback.

As the callback already checks the validation state itself we do not
need to change anything there.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
lib/proxmox_login_form.dart

index 861947d11876c84e3cda4e9e0c741202c53f6f12..048fa236730a843e54d37e6b61ec3f7dfdc41991 100644 (file)
@@ -38,7 +38,7 @@ class ProxmoxLoginForm extends StatefulWidget {
   final PveAccessDomainModel? selectedDomain;
   final ValueChanged<PveAccessDomainModel?> onDomainChanged;
   final Function? onPasswordSubmitted;
-  final Function? onOriginSubmitted;
+  final Function onOriginSubmitted;
   final Function? onSavePasswordChanged;
   final bool? canSavePassword;
   final bool? passwordSaved;
@@ -53,7 +53,7 @@ class ProxmoxLoginForm extends StatefulWidget {
     this.selectedDomain,
     required this.onDomainChanged,
     this.onPasswordSubmitted,
-    this.onOriginSubmitted,
+    required this.onOriginSubmitted,
     this.onSavePasswordChanged,
     this.canSavePassword,
     this.passwordSaved,
@@ -80,7 +80,7 @@ class _ProxmoxLoginFormState extends State<ProxmoxLoginForm> {
                 'Protocol (https) and default port (8006 or 443) implied'),
         controller: widget.originController,
         validator: widget.originValidator,
-        onFieldSubmitted: (value) => widget.onOriginSubmitted!(),
+        onFieldSubmitted: (value) => widget.onOriginSubmitted(),
       );
     }
 
@@ -333,21 +333,18 @@ class _ProxmoxLoginPageState extends State<ProxmoxLoginPage> {
                                       _selectedDomain = value;
                                     });
                                   },
-                                  onOriginSubmitted: _submittButtonEnabled
-                                      ? () {
-                                          final isValid =
-                                              _formKey.currentState!.validate();
-                                          setState(() {
-                                            _submittButtonEnabled = isValid;
-                                          });
-                                          if (isValid) {
-                                            setState(() {
-                                              _accessDomains =
-                                                  _getAccessDomains();
-                                            });
-                                          }
-                                        }
-                                      : null,
+                                  onOriginSubmitted: () {
+                                    final isValid =
+                                        _formKey.currentState!.validate();
+                                    setState(() {
+                                      _submittButtonEnabled = isValid;
+                                    });
+                                    if (isValid) {
+                                      setState(() {
+                                        _accessDomains = _getAccessDomains();
+                                      });
+                                    }
+                                  },
                                   onPasswordSubmitted: _submittButtonEnabled
                                       ? () {
                                           final isValid =