Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 27 additions & 6 deletions commet/lib/ui/pages/login/login_page_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class _LoginPageViewState extends State<LoginPageView> {
);
final TextEditingController _usernameTextField = TextEditingController();
final TextEditingController _passwordTextField = TextEditingController();
final FocusNode _passwordFocusNode = FocusNode();

String get promptHomeserver => Intl.message("Homeserver",
name: "promptHomeserver",
Expand Down Expand Up @@ -82,6 +83,12 @@ class _LoginPageViewState extends State<LoginPageView> {
super.initState();
}

@override
void dispose() {
_passwordFocusNode.dispose();
super.dispose();
}

@override
Widget build(BuildContext context) {
return Scaffold(
Expand Down Expand Up @@ -304,17 +311,12 @@ class _LoginPageViewState extends State<LoginPageView> {
}

SizedBox loginButton() {
var flow = widget.flows?.whereType<PasswordLoginFlow>().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(),
),
);
}
Expand All @@ -323,8 +325,11 @@ class _LoginPageViewState extends State<LoginPageView> {
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,
Expand All @@ -337,6 +342,14 @@ class _LoginPageViewState extends State<LoginPageView> {
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(),
Expand Down Expand Up @@ -394,4 +407,12 @@ class _LoginPageViewState extends State<LoginPageView> {
widget.updateHomeserver?.call(_homeserverTextField.text);
}
}

void _attemptLogin() {
var flow = widget.flows?.whereType<PasswordLoginFlow>().firstOrNull;
if (flow != null) {
widget.doPasswordLogin
?.call(flow, _usernameTextField.text, _passwordTextField.text);
}
}
}