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> {
|
class _RegisterForm extends ConsumerState<RegisterForm> {
|
||||||
|
final _formKey = GlobalKey<FormState>();
|
||||||
final emailCtrl = TextEditingController();
|
final emailCtrl = TextEditingController();
|
||||||
final nameCtrl = TextEditingController();
|
final nameCtrl = TextEditingController();
|
||||||
final surnameCtrl = TextEditingController();
|
final surnameCtrl = TextEditingController();
|
||||||
final passwordCtrl = TextEditingController();
|
final passwordCtrl = TextEditingController();
|
||||||
final repeatPasswordCtrl = 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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final controller = ref.read(authorizationControllerProvider.notifier);
|
final controller = ref.read(authorizationControllerProvider.notifier);
|
||||||
return SizedBox(
|
return SizedBox(
|
||||||
width: 400,
|
width: 400,
|
||||||
child: Column(
|
child: Form(
|
||||||
children: [
|
key: _formKey,
|
||||||
Container(
|
child: Column(
|
||||||
alignment: Alignment.topLeft,
|
children: [
|
||||||
child: SelectableText(
|
Container(
|
||||||
"Welcome!",
|
alignment: Alignment.topLeft,
|
||||||
style: Theme.of(context).textTheme.headlineLarge,
|
child: SelectableText(
|
||||||
|
"Welcome!",
|
||||||
|
style: Theme.of(context).textTheme.headlineLarge,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
SizedBox(height: 12),
|
||||||
SizedBox(height: 12),
|
Container(
|
||||||
Container(
|
alignment: Alignment.topLeft,
|
||||||
alignment: Alignment.topLeft,
|
child: Row(
|
||||||
child: Row(
|
children: [
|
||||||
children: [
|
Text(
|
||||||
Text(
|
"Already have an account? ",
|
||||||
"Already have an account? ",
|
style: Theme.of(context).textTheme.bodyMedium,
|
||||||
style: Theme.of(context).textTheme.bodyMedium,
|
|
||||||
),
|
|
||||||
TextButton(
|
|
||||||
onPressed: controller.toggleAuthMode,
|
|
||||||
style: TextButton.styleFrom(
|
|
||||||
padding: EdgeInsets.zero,
|
|
||||||
minimumSize: Size(0, 0),
|
|
||||||
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
|
||||||
),
|
),
|
||||||
child: const Text(
|
TextButton(
|
||||||
"Sign in",
|
onPressed: controller.toggleAuthMode,
|
||||||
style: TextStyle(
|
style: TextButton.styleFrom(
|
||||||
decoration: TextDecoration.underline,
|
padding: EdgeInsets.zero,
|
||||||
color: Colors.blue,
|
minimumSize: Size(0, 0),
|
||||||
|
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||||
|
),
|
||||||
|
child: const Text(
|
||||||
|
"Sign in",
|
||||||
|
style: TextStyle(decoration: TextDecoration.underline),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
],
|
||||||
],
|
),
|
||||||
),
|
),
|
||||||
),
|
SizedBox(height: 36),
|
||||||
SizedBox(height: 36),
|
TextFormField(
|
||||||
TextField(
|
controller: nameCtrl,
|
||||||
controller: nameCtrl,
|
onFieldSubmitted: (_) => _submitForm(),
|
||||||
decoration: InputDecoration(hintText: "Name"),
|
decoration: InputDecoration(hintText: "Name"),
|
||||||
),
|
),
|
||||||
SizedBox(height: 16),
|
SizedBox(height: 16),
|
||||||
TextField(
|
TextFormField(
|
||||||
controller: surnameCtrl,
|
controller: surnameCtrl,
|
||||||
decoration: InputDecoration(hintText: "Surname"),
|
onFieldSubmitted: (_) => _submitForm(),
|
||||||
),
|
decoration: InputDecoration(hintText: "Surname"),
|
||||||
SizedBox(height: 16),
|
),
|
||||||
TextField(
|
SizedBox(height: 16),
|
||||||
controller: emailCtrl,
|
TextFormField(
|
||||||
decoration: InputDecoration(hintText: "Email address"),
|
controller: emailCtrl,
|
||||||
),
|
onFieldSubmitted: (_) => _submitForm(),
|
||||||
SizedBox(height: 16),
|
decoration: InputDecoration(hintText: "Email address"),
|
||||||
TextField(
|
),
|
||||||
controller: passwordCtrl,
|
SizedBox(height: 16),
|
||||||
obscureText: true,
|
TextFormField(
|
||||||
decoration: InputDecoration(hintText: "Password"),
|
controller: passwordCtrl,
|
||||||
),
|
onFieldSubmitted: (_) => _submitForm(),
|
||||||
SizedBox(height: 16),
|
obscureText: true,
|
||||||
TextField(
|
decoration: InputDecoration(hintText: "Password"),
|
||||||
controller: repeatPasswordCtrl,
|
),
|
||||||
obscureText: true,
|
SizedBox(height: 16),
|
||||||
decoration: InputDecoration(hintText: "Repeat the password"),
|
TextFormField(
|
||||||
),
|
controller: repeatPasswordCtrl,
|
||||||
TextButton(
|
onFieldSubmitted: (_) => _submitForm(),
|
||||||
onPressed: () {
|
obscureText: true,
|
||||||
final form = SignUpData(
|
decoration: InputDecoration(hintText: "Repeat the password"),
|
||||||
email: emailCtrl.text,
|
),
|
||||||
password: passwordCtrl.text,
|
ElevatedButton(
|
||||||
name: nameCtrl.text,
|
onPressed: _submitForm,
|
||||||
surname: surnameCtrl.text,
|
child: const Text('Sign up'),
|
||||||
);
|
),
|
||||||
|
],
|
||||||
ref.read(authorizationControllerProvider.notifier).signup(form);
|
),
|
||||||
},
|
|
||||||
child: const Text('Sign up'),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user