123 lines
4.0 KiB
Dart
123 lines
4.0 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import '../app_scope.dart';
|
|
|
|
class LoginScreen extends StatefulWidget {
|
|
const LoginScreen({super.key});
|
|
|
|
@override
|
|
State<LoginScreen> createState() => _LoginScreenState();
|
|
}
|
|
|
|
class _LoginScreenState extends State<LoginScreen> {
|
|
final _usernameController = TextEditingController();
|
|
final _passwordController = TextEditingController();
|
|
var _submitting = false;
|
|
String? _error;
|
|
|
|
@override
|
|
void dispose() {
|
|
_usernameController.dispose();
|
|
_passwordController.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
Future<void> _submit() async {
|
|
final username = _usernameController.text.trim();
|
|
final password = _passwordController.text;
|
|
if (username.isEmpty || password.isEmpty) {
|
|
setState(() => _error = 'Enter your username and password.');
|
|
return;
|
|
}
|
|
setState(() {
|
|
_submitting = true;
|
|
_error = null;
|
|
});
|
|
final session = AppScope.of(context).session;
|
|
final error = await session.signIn(username, password);
|
|
if (!mounted) {
|
|
return;
|
|
}
|
|
setState(() {
|
|
_submitting = false;
|
|
_error = error;
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final scheme = Theme.of(context).colorScheme;
|
|
return Scaffold(
|
|
body: SafeArea(
|
|
child: Center(
|
|
child: SingleChildScrollView(
|
|
padding: const EdgeInsets.all(24),
|
|
child: ConstrainedBox(
|
|
constraints: const BoxConstraints(maxWidth: 420),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
Icon(Icons.support_agent, size: 48, color: scheme.primary),
|
|
const SizedBox(height: 12),
|
|
Text(
|
|
'Kick Kings',
|
|
style: Theme.of(context).textTheme.headlineMedium,
|
|
textAlign: TextAlign.center,
|
|
),
|
|
const SizedBox(height: 4),
|
|
Text(
|
|
'Support staff',
|
|
style: Theme.of(context).textTheme.titleMedium
|
|
?.copyWith(color: scheme.onSurfaceVariant),
|
|
textAlign: TextAlign.center,
|
|
),
|
|
const SizedBox(height: 32),
|
|
TextField(
|
|
controller: _usernameController,
|
|
autofillHints: const [AutofillHints.username],
|
|
textInputAction: TextInputAction.next,
|
|
autocorrect: false,
|
|
enableSuggestions: false,
|
|
decoration: const InputDecoration(
|
|
labelText: 'Username',
|
|
border: OutlineInputBorder(),
|
|
),
|
|
onSubmitted: (_) => _submit(),
|
|
),
|
|
const SizedBox(height: 12),
|
|
TextField(
|
|
controller: _passwordController,
|
|
autofillHints: const [AutofillHints.password],
|
|
obscureText: true,
|
|
textInputAction: TextInputAction.done,
|
|
decoration: const InputDecoration(
|
|
labelText: 'Password',
|
|
border: OutlineInputBorder(),
|
|
),
|
|
onSubmitted: (_) => _submit(),
|
|
),
|
|
if (_error != null) ...[
|
|
const SizedBox(height: 16),
|
|
Text(_error!, style: TextStyle(color: scheme.error)),
|
|
],
|
|
const SizedBox(height: 20),
|
|
FilledButton(
|
|
onPressed: _submitting ? null : _submit,
|
|
child: _submitting
|
|
? const SizedBox(
|
|
width: 18,
|
|
height: 18,
|
|
child: CircularProgressIndicator(strokeWidth: 2),
|
|
)
|
|
: const Text('Sign in'),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|