From 50aadf1b48e4d7de58827d386a091bd74e155e1c Mon Sep 17 00:00:00 2001 From: Rafael <1024481@stud.hs-mannheim.de> Date: Tue, 18 Jun 2024 15:01:38 +0200 Subject: [PATCH] Revised Login and Register Pages --- lib/components/my_textfield.dart | 2 +- lib/pages/login_page.dart | 137 +++++++++++----------- lib/pages/register_page.dart | 84 ++++++------- lib/pages/registration_complete_page.dart | 5 +- 4 files changed, 113 insertions(+), 115 deletions(-) diff --git a/lib/components/my_textfield.dart b/lib/components/my_textfield.dart index bf1afcb..e9d5c3e 100644 --- a/lib/components/my_textfield.dart +++ b/lib/components/my_textfield.dart @@ -17,7 +17,7 @@ class MyTextField extends StatelessWidget { @override Widget build(BuildContext context) { return Padding( - padding: const EdgeInsets.symmetric(horizontal: 25.0, vertical: 15), + padding: const EdgeInsets.symmetric(horizontal: 25.0, vertical: 8), child: TextField( obscureText: obscureText, controller: controller, diff --git a/lib/pages/login_page.dart b/lib/pages/login_page.dart index 87ed83c..bfca7da 100644 --- a/lib/pages/login_page.dart +++ b/lib/pages/login_page.dart @@ -2,6 +2,7 @@ import 'package:firebase_auth/firebase_auth.dart'; import 'package:flutter/material.dart'; import '../components/my_button.dart'; import '../components/my_textfield.dart'; +import '../constants.dart'; import '../utils/helper_dialogs.dart'; import '../services/auth/auth_service.dart'; @@ -16,7 +17,7 @@ class LoginPage extends StatelessWidget { LoginPage({super.key, required this.onTap}); // login method - void login(BuildContext context) async { + void _login(BuildContext context) async { if (_emailController.text.trim().isEmpty || _passwordController.text.trim().isEmpty) { showMsg( @@ -27,12 +28,9 @@ class LoginPage extends StatelessWidget { return; } - // auth service - final auth = AuthService(); - // try login try { - await auth.signInWithEmailPassword( + await AuthService().signInWithEmailPassword( _emailController.text, _passwordController.text, ); @@ -51,77 +49,76 @@ class LoginPage extends StatelessWidget { Widget build(BuildContext context) { return Scaffold( backgroundColor: Theme.of(context).colorScheme.surface, - body: Center( - child: SingleChildScrollView( - 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( - "Welcome back, you've been missed", - style: TextStyle( + body: SafeArea( + child: Center( + child: SingleChildScrollView( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + // logo and welcome message + Icon( + Icons.people_alt, + size: 60, color: Theme.of(context).colorScheme.primary, - fontSize: 16, ), - ), - - const SizedBox(height: 25), - - // email textfield - MyTextField( - hintText: "E-Mail", - obscureText: false, - controller: _emailController, - ), - - // password textfield - MyTextField( - hintText: "Password", - obscureText: true, - controller: _passwordController, - ), - - const SizedBox(height: 25), - - // login button - MyButton( - text: "Login", - onTap: () => login(context), - ), - - const SizedBox(height: 25), - - // register now - Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text( - "Not a member? ", - style: TextStyle( - color: Theme.of(context).colorScheme.primary, - ), + const SizedBox(height: 16), + Text( + 'Welcome to ${Constants.appTitle}', + style: TextStyle( + color: Theme.of(context).colorScheme.primary, + fontSize: 16, ), - GestureDetector( - onTap: onTap, - child: const Text( - "Register now", + ), + + const SizedBox(height: 25), + + // email textfield + MyTextField( + hintText: 'E-Mail', + obscureText: false, + controller: _emailController, + ), + + // password textfield + MyTextField( + hintText: 'Password', + obscureText: true, + controller: _passwordController, + ), + + const SizedBox(height: 25), + + // login button + MyButton( + text: 'Login', + onTap: () => _login(context), + ), + + const SizedBox(height: 25), + + // register now + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text( + 'Don\'t have an account? ', style: TextStyle( - fontWeight: FontWeight.bold, + color: Theme.of(context).colorScheme.primary, ), ), - ), - ], - ) - ], + GestureDetector( + onTap: onTap, + child: const Text( + 'Register now', + style: TextStyle( + fontWeight: FontWeight.bold, + ), + ), + ), + ], + ) + ], + ), ), ), ), diff --git a/lib/pages/register_page.dart b/lib/pages/register_page.dart index 4b4309f..b610b3e 100644 --- a/lib/pages/register_page.dart +++ b/lib/pages/register_page.dart @@ -7,7 +7,6 @@ import '../services/auth/auth_service.dart'; import '../services/user_service.dart'; class RegisterPage extends StatelessWidget { - //text controllers final TextEditingController _nameController = TextEditingController(); final TextEditingController _lastnameController = TextEditingController(); final TextEditingController _emailController = TextEditingController(); @@ -50,89 +49,90 @@ class RegisterPage extends StatelessWidget { } } + bool _validateFields(BuildContext context) { + if ((_nameController.text.trim().isEmpty && + _lastnameController.text.trim().isEmpty) || + _emailController.text.trim().isEmpty || + _passwordController.text.trim().isEmpty) { + showMsg( + context, + 'Missing information', + 'Please enter your name, email and password', + ); + return false; + } + return true; + } + @override Widget build(BuildContext context) { return Scaffold( backgroundColor: Theme.of(context).colorScheme.surface, - body: Center( - child: ListView( - children: [ - Column( + body: SafeArea( + child: Center( + child: SingleChildScrollView( + child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ - // logo + const SizedBox(height: 25), + // logo and register message Icon( Icons.people_alt, size: 60, color: Theme.of(context).colorScheme.primary, ), - - const SizedBox(height: 50), - - // register message - Text( - "Let's create an account for you", - style: TextStyle( - color: Theme.of(context).colorScheme.primary, - fontSize: 16, + const SizedBox(height: 16), + Padding( + padding: const EdgeInsets.symmetric(horizontal: 25.0), + child: Text( + textAlign: TextAlign.center, + 'Create an account ' + 'and start connecting with potential co-founders.', + style: TextStyle( + color: Theme.of(context).colorScheme.primary, + fontSize: 16, + ), ), ), const SizedBox(height: 25), - // name text field + // text fields MyTextField( - hintText: "First Name", + hintText: 'First Name', obscureText: false, controller: _nameController, ), MyTextField( - hintText: "Last Name", + hintText: 'Last Name', obscureText: false, controller: _lastnameController, ), - // email text field MyTextField( - hintText: "E-Mail", + hintText: 'E-Mail', obscureText: false, controller: _emailController, ), - const SizedBox(height: 10), - - // password text field MyTextField( - hintText: "Password", + hintText: 'Password', obscureText: true, controller: _passwordController, ), - MyTextField( - hintText: "Confirm Password", + hintText: 'Confirm Password', obscureText: true, controller: _confirmPassController, ), const SizedBox(height: 25), - //login button + // register button MyButton( - text: "Register", + text: 'Register', onTap: () => { - if ((_nameController.text.trim().isEmpty && - _lastnameController.text.trim().isEmpty) || - _emailController.text.trim().isEmpty || - _passwordController.text.trim().isEmpty) - { - showMsg( - context, - 'Missing information', - 'Please enter your name, email and password', - ) - } - else - {register(context)} + if (_validateFields(context)) {register(context)} }, ), @@ -161,7 +161,7 @@ class RegisterPage extends StatelessWidget { ) ], ), - ], + ), ), ), ); diff --git a/lib/pages/registration_complete_page.dart b/lib/pages/registration_complete_page.dart index a9024cc..eda6646 100644 --- a/lib/pages/registration_complete_page.dart +++ b/lib/pages/registration_complete_page.dart @@ -31,8 +31,9 @@ class RegistrationCompletePage extends StatelessWidget { ), const SizedBox(height: 40), const Text( - 'Additional information such as a short biography or a ' - 'profile picture can be entered in the profile options.', + 'Enhance your profile by adding additional information, ' + 'such as a short biography or a profile picture, ' + 'in the profile settings.', textAlign: TextAlign.center, style: TextStyle(fontSize: 18), ),