76 lines
2 KiB
Dart
76 lines
2 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:slothmu/api/user.dart';
|
|
import 'package:localization/localization.dart';
|
|
|
|
class Login extends StatefulWidget {
|
|
const Login({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
State<Login> createState() => _LoginState();
|
|
}
|
|
|
|
class _LoginState extends State<Login> {
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return const Scaffold(
|
|
body: Padding(
|
|
padding: EdgeInsets.all(24),
|
|
child: LoginForm(),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class LoginForm extends StatefulWidget {
|
|
const LoginForm({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
State<LoginForm> createState() => _LoginFormState();
|
|
}
|
|
|
|
class _LoginFormState extends State<LoginForm> {
|
|
final formKey = GlobalKey<FormState>();
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Form(
|
|
onChanged: () {
|
|
formKey.currentState!.validate();
|
|
},
|
|
key: formKey,
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
children: [
|
|
Text("greeting".i18n(), style: const TextStyle(fontSize: 64)),
|
|
TextFormField(
|
|
decoration: InputDecoration(
|
|
labelText: "user-id".i18n(),
|
|
hintText: "user-id-example".i18n(),
|
|
icon: const Icon(Icons.person),
|
|
prefixText: "@",
|
|
),
|
|
autofocus: true,
|
|
validator: (value) {
|
|
if (value!.isEmpty || !isValidUsername(name: value)) {
|
|
return "user-id-not-valid".i18n();
|
|
} else {
|
|
return null;
|
|
}
|
|
},
|
|
),
|
|
TextButton.icon(
|
|
onPressed: () {
|
|
bool isValid = formKey.currentState!.validate();
|
|
if (!isValid) {
|
|
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
|
content: Text("login-failed-snackbar-text".i18n())));
|
|
}
|
|
},
|
|
icon: const Icon(Icons.login),
|
|
label: Text("authorize-in-browser".i18n()))
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|