diff --git a/commet/lib/ui/pages/login/login_page_view.dart b/commet/lib/ui/pages/login/login_page_view.dart index fc4b4009b..6d38b29bf 100644 --- a/commet/lib/ui/pages/login/login_page_view.dart +++ b/commet/lib/ui/pages/login/login_page_view.dart @@ -55,6 +55,7 @@ class _LoginPageViewState extends State { ); final TextEditingController _usernameTextField = TextEditingController(); final TextEditingController _passwordTextField = TextEditingController(); + final FocusNode _passwordFocusNode = FocusNode(); String get promptHomeserver => Intl.message("Homeserver", name: "promptHomeserver", @@ -82,6 +83,12 @@ class _LoginPageViewState extends State { super.initState(); } + @override + void dispose() { + _passwordFocusNode.dispose(); + super.dispose(); + } + @override Widget build(BuildContext context) { return Scaffold( @@ -304,17 +311,12 @@ class _LoginPageViewState extends State { } SizedBox loginButton() { - var flow = widget.flows?.whereType().firstOrNull; - return SizedBox( width: double.infinity, height: 50, child: tiamat.Button( text: promptSubmitLogin, - onTap: flow != null - ? () => widget.doPasswordLogin - ?.call(flow, _usernameTextField.text, _passwordTextField.text) - : null, + onTap: () => _attemptLogin(), ), ); } @@ -323,8 +325,11 @@ class _LoginPageViewState extends State { return TextField( autocorrect: false, controller: _passwordTextField, + focusNode: _passwordFocusNode, obscureText: true, readOnly: widget.isLoggingIn, + textInputAction: TextInputAction.go, + onSubmitted: (_) => _attemptLogin(), decoration: InputDecoration( border: const OutlineInputBorder(), labelText: promptPassword, @@ -337,6 +342,14 @@ class _LoginPageViewState extends State { autocorrect: false, controller: _usernameTextField, readOnly: widget.isLoggingIn, + textInputAction: TextInputAction.next, + onSubmitted: (_) { + if (_passwordTextField.text.isEmpty) { + _passwordFocusNode.requestFocus(); + } else { + _attemptLogin(); + } + }, inputFormatters: [FilteringTextInputFormatter.deny(RegExp("[ ]"))], decoration: InputDecoration( border: const OutlineInputBorder(), @@ -394,4 +407,12 @@ class _LoginPageViewState extends State { widget.updateHomeserver?.call(_homeserverTextField.text); } } + + void _attemptLogin() { + var flow = widget.flows?.whereType().firstOrNull; + if (flow != null) { + widget.doPasswordLogin + ?.call(flow, _usernameTextField.text, _passwordTextField.text); + } + } }