60 lines
1.8 KiB
Dart
60 lines
1.8 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
class LoginScreen extends StatelessWidget {
|
|
final Function(String, String) onLogin;
|
|
|
|
LoginScreen({required this.onLogin});
|
|
|
|
final TextEditingController usernameController = TextEditingController();
|
|
final TextEditingController passwordController = TextEditingController();
|
|
|
|
final FocusNode usernameFocusNode = FocusNode();
|
|
final FocusNode passwordFocusNode = FocusNode();
|
|
|
|
void _handleLogin() {
|
|
onLogin(usernameController.text, passwordController.text);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(title: Text('Login')),
|
|
body: Center(
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(16.0),
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
TextField(
|
|
controller: usernameController,
|
|
focusNode: usernameFocusNode,
|
|
decoration: InputDecoration(labelText: 'Username'),
|
|
textInputAction: TextInputAction.next,
|
|
onSubmitted: (_) {
|
|
FocusScope.of(context).requestFocus(passwordFocusNode);
|
|
},
|
|
),
|
|
SizedBox(height: 20),
|
|
TextField(
|
|
controller: passwordController,
|
|
focusNode: passwordFocusNode,
|
|
decoration: InputDecoration(labelText: 'Password'),
|
|
obscureText: true,
|
|
textInputAction: TextInputAction.done,
|
|
onSubmitted: (_) {
|
|
_handleLogin();
|
|
},
|
|
),
|
|
SizedBox(height: 20),
|
|
ElevatedButton(
|
|
onPressed: _handleLogin,
|
|
child: Text('Login'),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|