From 47c1a3d472dbce3cffd7ac37d8ee876aa397707d Mon Sep 17 00:00:00 2001 From: Nikolai Rodionov Date: Thu, 28 May 2026 09:48:05 +0200 Subject: [PATCH] Update the sign up form Signed-off-by: Nikolai Rodionov --- .../presentation/register_form.dart | 158 ++++++++++-------- 1 file changed, 86 insertions(+), 72 deletions(-) diff --git a/lib/features/authorization/presentation/register_form.dart b/lib/features/authorization/presentation/register_form.dart index 21d28b9..ffc702b 100644 --- a/lib/features/authorization/presentation/register_form.dart +++ b/lib/features/authorization/presentation/register_form.dart @@ -11,94 +11,108 @@ class RegisterForm extends ConsumerStatefulWidget { } class _RegisterForm extends ConsumerState { + final _formKey = GlobalKey(); 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'), + ), + ], + ), ), ); }