Support Enter to submit login
This commit is contained in:
@@ -24,6 +24,7 @@ func main() {
|
||||
go func() {
|
||||
r := api.SetupRouter(srv)
|
||||
monitor.Infof("API server listening on :8080")
|
||||
monitor.Infof("Web console listening on :8080/admin")
|
||||
if err := r.Run(":8080"); err != nil {
|
||||
monitor.Errorf("Failed to start API server: %v", err)
|
||||
}
|
||||
|
||||
@@ -17,8 +17,17 @@ class LoginPage extends StatefulWidget {
|
||||
class _LoginPageState extends State<LoginPage> {
|
||||
final _usernameController = TextEditingController();
|
||||
final _passwordController = TextEditingController();
|
||||
final _passwordFocusNode = FocusNode();
|
||||
bool _isLoading = false;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_usernameController.dispose();
|
||||
_passwordController.dispose();
|
||||
_passwordFocusNode.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _handleLogin() async {
|
||||
if (_usernameController.text.isEmpty || _passwordController.text.isEmpty) {
|
||||
ScaffoldMessenger.of(
|
||||
@@ -108,6 +117,8 @@ class _LoginPageState extends State<LoginPage> {
|
||||
// Fields
|
||||
TextField(
|
||||
controller: _usernameController,
|
||||
textInputAction: TextInputAction.next,
|
||||
onSubmitted: (_) => _passwordFocusNode.requestFocus(),
|
||||
decoration: InputDecoration(
|
||||
labelText: "Username",
|
||||
prefixIcon: Icon(Icons.person),
|
||||
@@ -119,7 +130,14 @@ class _LoginPageState extends State<LoginPage> {
|
||||
SizedBox(height: 16),
|
||||
TextField(
|
||||
controller: _passwordController,
|
||||
focusNode: _passwordFocusNode,
|
||||
obscureText: true,
|
||||
textInputAction: TextInputAction.done,
|
||||
onSubmitted: (_) {
|
||||
if (!_isLoading) {
|
||||
_handleLogin();
|
||||
}
|
||||
},
|
||||
decoration: InputDecoration(
|
||||
labelText: "Password",
|
||||
prefixIcon: Icon(Icons.lock),
|
||||
|
||||
Reference in New Issue
Block a user