]> git.proxmox.com Git - flutter/proxmox_login_manager.git/commitdiff
add onsubmitted handler for origin & password field
authorTim Marx <t.marx@proxmox.com>
Wed, 9 Sep 2020 11:56:07 +0000 (13:56 +0200)
committerTim Marx <t.marx@proxmox.com>
Wed, 9 Sep 2020 11:56:07 +0000 (13:56 +0200)
Signed-off-by: Tim Marx <t.marx@proxmox.com>
lib/proxmox_login_form.dart

index 15abc6d1217070a71e012100c99d232931988c2d..12b5fb59d828f16d843b382f1859e703a12f454b 100644 (file)
@@ -26,6 +26,8 @@ class ProxmoxLoginForm extends StatefulWidget {
   final List<PveAccessDomainModel> accessDomains;
   final PveAccessDomainModel selectedDomain;
   final ValueChanged<PveAccessDomainModel> onDomainChanged;
+  final Function onPasswordSubmitted;
+  final Function onOriginSubmitted;
 
   const ProxmoxLoginForm({
     Key key,
@@ -36,6 +38,8 @@ class ProxmoxLoginForm extends StatefulWidget {
     @required this.originValidator,
     this.selectedDomain,
     @required this.onDomainChanged,
+    this.onPasswordSubmitted,
+    this.onOriginSubmitted,
   }) : super(key: key);
 
   @override
@@ -67,6 +71,7 @@ class _ProxmoxLoginFormState extends State<ProxmoxLoginForm> {
             helperText: 'Protocol (https) and default port (8006) implied'),
         controller: widget.originController,
         validator: widget.originValidator,
+        onFieldSubmitted: (value) => widget.onOriginSubmitted(),
       );
     }
 
@@ -127,6 +132,7 @@ class _ProxmoxLoginFormState extends State<ProxmoxLoginForm> {
                 }
                 return null;
               },
+              onFieldSubmitted: (value) => widget.onPasswordSubmitted(),
             ),
             Align(
               alignment: Alignment.bottomRight,
@@ -266,6 +272,33 @@ class _ProxmoxLoginPageState extends State<ProxmoxLoginPage> {
                                     _selectedDomain = value;
                                   });
                                 },
+                                onOriginSubmitted: _submittButtonEnabled
+                                    ? () {
+                                        final isValid =
+                                            _formKey.currentState.validate();
+                                        setState(() {
+                                          _submittButtonEnabled = isValid;
+                                        });
+                                        if (isValid) {
+                                          setState(() {
+                                            _accessDomains =
+                                                _getAccessDomains();
+                                          });
+                                        }
+                                      }
+                                    : null,
+                                onPasswordSubmitted: _submittButtonEnabled
+                                    ? () {
+                                        final isValid =
+                                            _formKey.currentState.validate();
+                                        setState(() {
+                                          _submittButtonEnabled = isValid;
+                                        });
+                                        if (isValid) {
+                                          _onLoginButtonPressed();
+                                        }
+                                      }
+                                    : null,
                               ),
                               if (snapshot.hasData)
                                 Expanded(