import 'package:cofounderella/services/auth/auth_service.dart'; import 'package:flutter/material.dart'; import '../components/my_button.dart'; import '../components/my_textfield.dart'; class RegisterPage extends StatelessWidget { //text controllers final TextEditingController _nameController = TextEditingController(); final TextEditingController _lastnameController = TextEditingController(); final TextEditingController _emailController = TextEditingController(); final TextEditingController _passwordController = TextEditingController(); final TextEditingController _confirmPassController = TextEditingController(); // tap to go to login page final void Function()? onTap; RegisterPage({super.key, required this.onTap}); // register method void register(BuildContext context) { // get auth service final auth = AuthService(); // check if passwords match if (_passwordController.text == _confirmPassController.text) { try { auth.signUpWithEmailPassword( _emailController.text, _passwordController.text, ); } catch (e) { showDialog( context: context, builder: (context) => AlertDialog( title: Text(e.toString()), ), ); } } else { showDialog( context: context, builder: (context) => const AlertDialog( title: Text("Passwords do not match!"), ), ); } } @override Widget build(BuildContext context) { return Scaffold( backgroundColor: Theme.of(context).colorScheme.background, body: Center( child: Column(mainAxisAlignment: MainAxisAlignment.center, children: [ //logo Icon( Icons.people_alt, size: 60, color: Theme.of(context).colorScheme.primary, ), const SizedBox(height: 50), //welcome back message Text( "Let's create an account for you", style: TextStyle( color: Theme.of(context).colorScheme.primary, fontSize: 16, ), ), const SizedBox(height: 25), // name text field MyTextField( hintText: "First Name", obscureText: false, controller: _nameController, ), MyTextField( hintText: "Last Name", obscureText: false, controller: _lastnameController, ), // email text field MyTextField( hintText: "E-Mail", obscureText: false, controller: _emailController, ), const SizedBox(height: 10), // password text field MyTextField( hintText: "Password", obscureText: true, controller: _passwordController, ), MyTextField( hintText: "Confirm Password", obscureText: true, controller: _confirmPassController, ), //login button MyButton( text: "Register", onTap: () => register(context), ), const SizedBox(height: 25), // register now Row( mainAxisAlignment: MainAxisAlignment.center, children: [ Text( "Already have an account? ", style: TextStyle(color: Theme.of(context).colorScheme.primary), ), GestureDetector( onTap: onTap, child: const Text( "Login now", style: TextStyle( fontWeight: FontWeight.bold, ), ), ), ], ) ]), ), ); } }