Files
softplayer-web/lib/features/authorization/presentation/register_form.dart
2026-05-28 09:48:05 +02:00

120 lines
4.0 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:softplayer_web/features/authorization/application/authorization_application.dart';
import 'package:softplayer_web/features/authorization/application/sign_up_data.dart';
class RegisterForm extends ConsumerStatefulWidget {
const RegisterForm({super.key});
@override
ConsumerState<RegisterForm> createState() => _RegisterForm();
}
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: 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,
),
child: const Text(
"Sign in",
style: TextStyle(decoration: TextDecoration.underline),
),
),
],
),
),
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'),
),
],
),
),
);
}
}