Support Enter to submit login

This commit is contained in:
2026-04-15 11:20:30 +08:00
parent 98666ab1ea
commit 146f05388e
2 changed files with 19 additions and 0 deletions

View File

@@ -24,6 +24,7 @@ func main() {
go func() { go func() {
r := api.SetupRouter(srv) r := api.SetupRouter(srv)
monitor.Infof("API server listening on :8080") monitor.Infof("API server listening on :8080")
monitor.Infof("Web console listening on :8080/admin")
if err := r.Run(":8080"); err != nil { if err := r.Run(":8080"); err != nil {
monitor.Errorf("Failed to start API server: %v", err) monitor.Errorf("Failed to start API server: %v", err)
} }

View File

@@ -17,8 +17,17 @@ class LoginPage extends StatefulWidget {
class _LoginPageState extends State<LoginPage> { class _LoginPageState extends State<LoginPage> {
final _usernameController = TextEditingController(); final _usernameController = TextEditingController();
final _passwordController = TextEditingController(); final _passwordController = TextEditingController();
final _passwordFocusNode = FocusNode();
bool _isLoading = false; bool _isLoading = false;
@override
void dispose() {
_usernameController.dispose();
_passwordController.dispose();
_passwordFocusNode.dispose();
super.dispose();
}
void _handleLogin() async { void _handleLogin() async {
if (_usernameController.text.isEmpty || _passwordController.text.isEmpty) { if (_usernameController.text.isEmpty || _passwordController.text.isEmpty) {
ScaffoldMessenger.of( ScaffoldMessenger.of(
@@ -108,6 +117,8 @@ class _LoginPageState extends State<LoginPage> {
// Fields // Fields
TextField( TextField(
controller: _usernameController, controller: _usernameController,
textInputAction: TextInputAction.next,
onSubmitted: (_) => _passwordFocusNode.requestFocus(),
decoration: InputDecoration( decoration: InputDecoration(
labelText: "Username", labelText: "Username",
prefixIcon: Icon(Icons.person), prefixIcon: Icon(Icons.person),
@@ -119,7 +130,14 @@ class _LoginPageState extends State<LoginPage> {
SizedBox(height: 16), SizedBox(height: 16),
TextField( TextField(
controller: _passwordController, controller: _passwordController,
focusNode: _passwordFocusNode,
obscureText: true, obscureText: true,
textInputAction: TextInputAction.done,
onSubmitted: (_) {
if (!_isLoading) {
_handleLogin();
}
},
decoration: InputDecoration( decoration: InputDecoration(
labelText: "Password", labelText: "Password",
prefixIcon: Icon(Icons.lock), prefixIcon: Icon(Icons.lock),