Update the sign up form
Signed-off-by: Nikolai Rodionov <iam@allanger.xyz>
This commit is contained in:
@@ -11,94 +11,108 @@ class RegisterForm extends ConsumerStatefulWidget {
|
||||
}
|
||||
|
||||
class _RegisterForm extends ConsumerState<RegisterForm> {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
final emailCtrl = TextEditingController();
|
||||
final nameCtrl = TextEditingController();
|
||||
final surnameCtrl = TextEditingController();
|
||||
final passwordCtrl = TextEditingController();
|
||||
final repeatPasswordCtrl = TextEditingController();
|
||||
|
||||
void _submitForm() {
|
||||
if (_formKey.currentState!.validate()) {
|
||||
// If valid, you can use the values
|
||||
final name = nameCtrl.text;
|
||||
final surname = surnameCtrl.text;
|
||||
final email = emailCtrl.text;
|
||||
final password = passwordCtrl.text;
|
||||
final data = SignUpData(
|
||||
email: email,
|
||||
password: password,
|
||||
name: name,
|
||||
surname: surname,
|
||||
);
|
||||
ref.read(authorizationControllerProvider.notifier).signup(data);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final controller = ref.read(authorizationControllerProvider.notifier);
|
||||
return SizedBox(
|
||||
width: 400,
|
||||
child: Column(
|
||||
children: [
|
||||
Container(
|
||||
alignment: Alignment.topLeft,
|
||||
child: SelectableText(
|
||||
"Welcome!",
|
||||
style: Theme.of(context).textTheme.headlineLarge,
|
||||
child: Form(
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
children: [
|
||||
Container(
|
||||
alignment: Alignment.topLeft,
|
||||
child: SelectableText(
|
||||
"Welcome!",
|
||||
style: Theme.of(context).textTheme.headlineLarge,
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 12),
|
||||
Container(
|
||||
alignment: Alignment.topLeft,
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
"Already have an account? ",
|
||||
style: Theme.of(context).textTheme.bodyMedium,
|
||||
),
|
||||
TextButton(
|
||||
onPressed: controller.toggleAuthMode,
|
||||
style: TextButton.styleFrom(
|
||||
padding: EdgeInsets.zero,
|
||||
minimumSize: Size(0, 0),
|
||||
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
SizedBox(height: 12),
|
||||
Container(
|
||||
alignment: Alignment.topLeft,
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
"Already have an account? ",
|
||||
style: Theme.of(context).textTheme.bodyMedium,
|
||||
),
|
||||
child: const Text(
|
||||
"Sign in",
|
||||
style: TextStyle(
|
||||
decoration: TextDecoration.underline,
|
||||
color: Colors.blue,
|
||||
TextButton(
|
||||
onPressed: controller.toggleAuthMode,
|
||||
style: TextButton.styleFrom(
|
||||
padding: EdgeInsets.zero,
|
||||
minimumSize: Size(0, 0),
|
||||
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
),
|
||||
child: const Text(
|
||||
"Sign in",
|
||||
style: TextStyle(decoration: TextDecoration.underline),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 36),
|
||||
TextField(
|
||||
controller: nameCtrl,
|
||||
decoration: InputDecoration(hintText: "Name"),
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
TextField(
|
||||
controller: surnameCtrl,
|
||||
decoration: InputDecoration(hintText: "Surname"),
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
TextField(
|
||||
controller: emailCtrl,
|
||||
decoration: InputDecoration(hintText: "Email address"),
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
TextField(
|
||||
controller: passwordCtrl,
|
||||
obscureText: true,
|
||||
decoration: InputDecoration(hintText: "Password"),
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
TextField(
|
||||
controller: repeatPasswordCtrl,
|
||||
obscureText: true,
|
||||
decoration: InputDecoration(hintText: "Repeat the password"),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
final form = SignUpData(
|
||||
email: emailCtrl.text,
|
||||
password: passwordCtrl.text,
|
||||
name: nameCtrl.text,
|
||||
surname: surnameCtrl.text,
|
||||
);
|
||||
|
||||
ref.read(authorizationControllerProvider.notifier).signup(form);
|
||||
},
|
||||
child: const Text('Sign up'),
|
||||
),
|
||||
],
|
||||
SizedBox(height: 36),
|
||||
TextFormField(
|
||||
controller: nameCtrl,
|
||||
onFieldSubmitted: (_) => _submitForm(),
|
||||
decoration: InputDecoration(hintText: "Name"),
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
TextFormField(
|
||||
controller: surnameCtrl,
|
||||
onFieldSubmitted: (_) => _submitForm(),
|
||||
decoration: InputDecoration(hintText: "Surname"),
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
TextFormField(
|
||||
controller: emailCtrl,
|
||||
onFieldSubmitted: (_) => _submitForm(),
|
||||
decoration: InputDecoration(hintText: "Email address"),
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
TextFormField(
|
||||
controller: passwordCtrl,
|
||||
onFieldSubmitted: (_) => _submitForm(),
|
||||
obscureText: true,
|
||||
decoration: InputDecoration(hintText: "Password"),
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
TextFormField(
|
||||
controller: repeatPasswordCtrl,
|
||||
onFieldSubmitted: (_) => _submitForm(),
|
||||
obscureText: true,
|
||||
decoration: InputDecoration(hintText: "Repeat the password"),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: _submitForm,
|
||||
child: const Text('Sign up'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user