From 48eb8f416a1cd26072d4b58de467b123249f6bcc Mon Sep 17 00:00:00 2001 From: sweier2 Date: Sun, 16 Jun 2024 20:21:14 +0200 Subject: [PATCH 1/4] login see password --- ios/Podfile.lock | 2 +- lib/Screens/Chat/chat_page.dart | 1 + lib/Screens/LogIn/auth_page.dart | 74 ++++++------------- lib/Screens/LogIn/login_page.dart | 34 ++++++++- lib/Screens/LogIn/register_page.dart | 1 + lib/Screens/LogIn/services/auth_service.dart | 74 ++++++++++++++----- .../Settingsscreens/settingsscreenSimon.dart | 1 + lib/Screens/chatscreen.dart | 1 + lib/main.dart | 4 +- 9 files changed, 111 insertions(+), 81 deletions(-) diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 52ebb2e..8fa36b8 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -916,4 +916,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: d5ebeed53a738c4992d155ad65b0166c472906e5 -COCOAPODS: 1.14.3 +COCOAPODS: 1.15.2 diff --git a/lib/Screens/Chat/chat_page.dart b/lib/Screens/Chat/chat_page.dart index 20e2a64..707dbfc 100644 --- a/lib/Screens/Chat/chat_page.dart +++ b/lib/Screens/Chat/chat_page.dart @@ -1,5 +1,6 @@ import 'package:app_prototyo/Screens/Chat/chat_service.dart'; import 'package:app_prototyo/Screens/Findscreen/SeeUser/seeuser.dart'; +import 'package:app_prototyo/Screens/LogIn/auth_page.dart'; import 'package:app_prototyo/Screens/LogIn/services/auth_service.dart'; import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:flutter/material.dart'; diff --git a/lib/Screens/LogIn/auth_page.dart b/lib/Screens/LogIn/auth_page.dart index b81c15c..e6576a2 100644 --- a/lib/Screens/LogIn/auth_page.dart +++ b/lib/Screens/LogIn/auth_page.dart @@ -1,61 +1,29 @@ -import 'dart:async'; - -import 'package:flutter/material.dart'; import 'package:firebase_auth/firebase_auth.dart'; -import 'package:cloud_firestore/cloud_firestore.dart'; -import 'package:app_prototyo/Screens/LogIn/login_or_register_page.dart'; -import 'package:app_prototyo/Screens/homebar.dart'; -import 'package:app_prototyo/Screens/CreateUser/welcomescreen.dart'; - -class AuthPage extends StatelessWidget { - const AuthPage({Key? key}); +import 'package:google_sign_in/google_sign_in.dart'; - @override - Widget build(BuildContext context) { - return Scaffold( - body: StreamBuilder( - stream: FirebaseAuth.instance.authStateChanges(), - builder: (context, snapshot) { - if (snapshot.connectionState == ConnectionState.waiting) { - // Warte 3 Sekunden, bevor der Ladeindikator angezeigt wird - Future.delayed(Duration(seconds: 3)); - return Center( - child: CircularProgressIndicator(), - ); - } +class AuthService { + final FirebaseAuth _auth = FirebaseAuth.instance; - if (snapshot.hasData && snapshot.data != null) { - // Wenn eingeloggt - User? user = snapshot.data; + // Google Sign in + signInWithGoogle() async { + // begin interactive sign in process + final GoogleSignInAccount? gUser = await GoogleSignIn().signIn(); - return FutureBuilder( - future: FirebaseFirestore.instance - .collection('user') - .doc(user?.uid) - .get(), - builder: (context, snapshot) { - if (snapshot.connectionState == ConnectionState.waiting) { - return Center( - child: CircularProgressIndicator(), - ); - } + // obtain auth details from request + final GoogleSignInAuthentication gAuth = await gUser!.authentication; - if (snapshot.hasData && - snapshot.data != null && - snapshot.data!.exists) { - // Benutzer ist bereits registriert - return TabsScreen(); // Navigiere zum TabsScreen nach der Anmeldung - } else { - // Benutzer ist neu registriert - return WelcomeScreen(); // Navigiere zum WelcomeScreen nach der Registrierung - } - }, - ); - } else { - return LoginOrRegisterPage(); // Wenn nicht eingeloggt, zur LoginPage-Seite navigieren oder zur Register Page - } - }, - ), + // create a new credential for user (credential = Berechtigung) + final credential = GoogleAuthProvider.credential( + accessToken: gAuth.accessToken, + idToken: gAuth.idToken, ); + + // sign in + return await FirebaseAuth.instance.signInWithCredential(credential); + } + + User? getCurrentUser() { + return _auth.currentUser; } } + diff --git a/lib/Screens/LogIn/login_page.dart b/lib/Screens/LogIn/login_page.dart index 9fe5e0e..ebc51d2 100644 --- a/lib/Screens/LogIn/login_page.dart +++ b/lib/Screens/LogIn/login_page.dart @@ -1,4 +1,5 @@ import 'package:app_prototyo/Provider/user_provider.dart'; +import 'package:app_prototyo/Screens/LogIn/auth_page.dart'; import 'package:app_prototyo/Screens/LogIn/forgot_pw_page.dart'; import 'package:app_prototyo/Screens/LogIn/register_page.dart'; import 'package:app_prototyo/Screens/LogIn/services/auth_service.dart'; @@ -22,6 +23,7 @@ class _LoginPageState extends State { final emailController = TextEditingController(); final passwordController = TextEditingController(); bool _isLoading = false; + bool _obscureText = true; @override void dispose() { @@ -155,10 +157,34 @@ class _LoginPageState extends State { obscureText: false, ), const SizedBox(height: 10), - MyTextField( - controller: passwordController, - hintText: 'Password', - obscureText: true, + Stack( + alignment: Alignment.centerRight, + children: [ + MyTextField( + controller: passwordController, + hintText: 'Password', + obscureText: _obscureText, + ), + GestureDetector( + onTapDown: (_) { + setState(() { + _obscureText = false; + }); + }, + onTapUp: (_) { + setState(() { + _obscureText = true; + }); + }, + child: Padding( + padding: const EdgeInsets.only(right: 10), + child: Icon( + _obscureText ? Icons.visibility_off : Icons.visibility, + color: Colors.white, + ), + ), + ), + ], ), const SizedBox(height: 4), Padding( diff --git a/lib/Screens/LogIn/register_page.dart b/lib/Screens/LogIn/register_page.dart index b6af0cc..41d1782 100644 --- a/lib/Screens/LogIn/register_page.dart +++ b/lib/Screens/LogIn/register_page.dart @@ -1,4 +1,5 @@ import 'package:app_prototyo/Screens/CreateUser/welcomescreen.dart'; +import 'package:app_prototyo/Screens/LogIn/auth_page.dart'; import 'package:app_prototyo/Screens/LogIn/services/auth_service.dart'; import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:flutter/material.dart'; diff --git a/lib/Screens/LogIn/services/auth_service.dart b/lib/Screens/LogIn/services/auth_service.dart index a52f47e..9847a36 100644 --- a/lib/Screens/LogIn/services/auth_service.dart +++ b/lib/Screens/LogIn/services/auth_service.dart @@ -1,28 +1,62 @@ -import 'package:firebase_auth/firebase_auth.dart'; -import 'package:google_sign_in/google_sign_in.dart'; +import 'dart:async'; -class AuthService { - final FirebaseAuth _auth = FirebaseAuth.instance; +import 'package:flutter/material.dart'; +import 'package:firebase_auth/firebase_auth.dart'; +import 'package:cloud_firestore/cloud_firestore.dart'; +import 'package:app_prototyo/Screens/LogIn/login_or_register_page.dart'; +import 'package:app_prototyo/Screens/homebar.dart'; +import 'package:app_prototyo/Screens/CreateUser/welcomescreen.dart'; - // Google Sign in - signInWithGoogle() async { - // begin interactive sign in process - final GoogleSignInAccount? gUser = await GoogleSignIn().signIn(); +class AuthPage extends StatelessWidget { + const AuthPage({Key? key}); - // obtain auth details from request - final GoogleSignInAuthentication gAuth = await gUser!.authentication; + @override + Widget build(BuildContext context) { + return Scaffold( + body: StreamBuilder( + stream: FirebaseAuth.instance.authStateChanges(), + builder: (context, snapshot) { + if (snapshot.connectionState == ConnectionState.waiting) { + // Warte 3 Sekunden, bevor der Ladeindikator angezeigt wird + Future.delayed(Duration(seconds: 3)); + return Center( + child: CircularProgressIndicator(), + ); + } - // create a new credential for user (credential = Berechtigung) - final credential = GoogleAuthProvider.credential( - accessToken: gAuth.accessToken, - idToken: gAuth.idToken, - ); + if (snapshot.hasData && snapshot.data != null) { + // Wenn eingeloggt + User? user = snapshot.data; - // sign in - return await FirebaseAuth.instance.signInWithCredential(credential); - } + return FutureBuilder( + future: FirebaseFirestore.instance + .collection('user') + .doc(user?.uid) + .get(), + builder: (context, snapshot) { + if (snapshot.connectionState == ConnectionState.waiting) { + return Center( + child: CircularProgressIndicator(), + ); + } - User? getCurrentUser() { - return _auth.currentUser; + if (snapshot.hasData && + snapshot.data != null && + snapshot.data!.exists) { + // Benutzer ist bereits registriert + return TabsScreen(); // Navigiere zum TabsScreen nach der Anmeldung + } else { + // Benutzer ist neu registriert + return WelcomeScreen(); // Navigiere zum WelcomeScreen nach der Registrierung + } + }, + ); + } else { + return LoginOrRegisterPage(); // Wenn nicht eingeloggt, zur LoginPage-Seite navigieren oder zur Register Page + } + }, + ), + ); } } + diff --git a/lib/Screens/Settingsscreens/settingsscreenSimon.dart b/lib/Screens/Settingsscreens/settingsscreenSimon.dart index 983178a..48a7cbf 100644 --- a/lib/Screens/Settingsscreens/settingsscreenSimon.dart +++ b/lib/Screens/Settingsscreens/settingsscreenSimon.dart @@ -1,6 +1,7 @@ import 'package:app_prototyo/Provider/user_provider.dart'; import 'package:app_prototyo/Screens/LogIn/auth_page.dart'; import 'package:app_prototyo/Screens/LogIn/login_or_register_page.dart'; +import 'package:app_prototyo/Screens/LogIn/services/auth_service.dart'; import 'package:app_prototyo/Screens/Settingsscreens/Settings_SWSR/components/button.dart'; import 'package:app_prototyo/Screens/Settingsscreens/Settings_SWSR/emailreset.dart'; diff --git a/lib/Screens/chatscreen.dart b/lib/Screens/chatscreen.dart index 814fe60..7e039f6 100644 --- a/lib/Screens/chatscreen.dart +++ b/lib/Screens/chatscreen.dart @@ -1,6 +1,7 @@ import 'package:app_prototyo/Screens/Chat/chat_page.dart'; import 'package:app_prototyo/Screens/Chat/chat_service.dart'; import 'package:app_prototyo/Screens/Chat/user_tile.dart'; +import 'package:app_prototyo/Screens/LogIn/auth_page.dart'; import 'package:app_prototyo/Screens/LogIn/services/auth_service.dart'; import 'package:flutter/material.dart'; diff --git a/lib/main.dart b/lib/main.dart index 0380ea1..4d2365f 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,10 +1,8 @@ import 'package:app_prototyo/Plans/FindPlans/find_plans_provider.dart'; - import 'package:app_prototyo/Provider/plans_provider.dart'; - import 'package:app_prototyo/Provider/user_provider.dart'; import 'package:app_prototyo/Screens/Findscreen/SeeUser/user_provider.dart'; -import 'package:app_prototyo/Screens/LogIn/auth_page.dart'; +import 'package:app_prototyo/Screens/LogIn/services/auth_service.dart'; import 'package:app_prototyo/Screens/homebar.dart'; import 'package:firebase_auth/firebase_auth.dart'; From 5c43690cd69b4087da07723e195f1765868a603b Mon Sep 17 00:00:00 2001 From: sweier2 Date: Sun, 16 Jun 2024 21:16:41 +0200 Subject: [PATCH 2/4] =?UTF-8?q?login=20h=C3=BCpft=20nicht=20mehr=20mit=20r?= =?UTF-8?q?egister?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/Screens/LogIn/login_page.dart | 384 ++++++++++++++++----------- lib/Screens/LogIn/register_page.dart | 168 ++++++------ 2 files changed, 314 insertions(+), 238 deletions(-) diff --git a/lib/Screens/LogIn/login_page.dart b/lib/Screens/LogIn/login_page.dart index ebc51d2..86f77d9 100644 --- a/lib/Screens/LogIn/login_page.dart +++ b/lib/Screens/LogIn/login_page.dart @@ -11,6 +11,21 @@ import 'package:firebase_auth/firebase_auth.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:provider/provider.dart'; +void main() { + runApp(MyApp()); +} + +class MyApp extends StatelessWidget { + @override + Widget build(BuildContext context) { + return MaterialApp( + home: LoginPage(onTap: () { + print("Register now tapped"); + }), + ); + } +} + class LoginPage extends StatefulWidget { final Function()? onTap; const LoginPage({Key? key, required this.onTap}) : super(key: key); @@ -96,7 +111,6 @@ class _LoginPageState extends State { } } catch (error) { if (mounted) { - // Überprüfung auf mounted print('Error loading user data: $error'); } } @@ -118,191 +132,243 @@ class _LoginPageState extends State { } } + Widget buildTextField({ + required TextEditingController controller, + required String hintText, + required bool obscureText, + }) { + return TextField( + controller: controller, + obscureText: obscureText, + style: const TextStyle(color: Colors.white), + decoration: InputDecoration( + hintText: hintText, + hintStyle: const TextStyle(color: Colors.white70), + filled: true, + fillColor: const Color.fromRGBO(1, 25, 45, 0.7), + enabledBorder: OutlineInputBorder( + borderSide: const BorderSide(color: Colors.transparent), + borderRadius: BorderRadius.circular(10), + ), + focusedBorder: OutlineInputBorder( + borderSide: const BorderSide(color: Colors.white), + borderRadius: BorderRadius.circular(10), + ), + ), + ); + } + @override Widget build(BuildContext context) { + final screenHeight = MediaQuery.of(context).size.height; + final screenWidth = MediaQuery.of(context).size.width; + return Scaffold( backgroundColor: const Color.fromRGBO(75, 173, 193, 1.0), - resizeToAvoidBottomInset: false, body: SafeArea( - child: LayoutBuilder( - builder: (context, constraints) { - double paddingHorizontal = constraints.maxWidth * 0.1; - return SingleChildScrollView( - child: Padding( - padding: EdgeInsets.symmetric(horizontal: paddingHorizontal), - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - const Text( - 'Fall in love with the world', - style: TextStyle( - color: Colors.white, - fontSize: 20, - fontStyle: FontStyle.italic, - ), + child: Center( + child: SingleChildScrollView( + child: Padding( + padding: const EdgeInsets.symmetric(horizontal: 30), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + SizedBox(height: screenHeight * 0.02), + Container( + margin: const EdgeInsets.symmetric(vertical: 20), + width: screenWidth * 0.4, + child: Image.asset('assets/bilder/Applogo.png'), + ), + const Text( + 'Fall in love with the world', + style: TextStyle( + color: Colors.white, + fontSize: 20, + fontStyle: FontStyle.italic, ), - const SizedBox(height: 20), - Container( - margin: const EdgeInsets.only( - top: 20, - bottom: 5, + ), + SizedBox(height: screenHeight * 0.02), + buildTextField( + controller: emailController, + hintText: 'Email', + obscureText: false, + ), + SizedBox(height: screenHeight * 0.02), + Stack( + alignment: Alignment.centerRight, + children: [ + buildTextField( + controller: passwordController, + hintText: 'Password', + obscureText: _obscureText, ), - width: constraints.maxWidth * 0.5, - child: Image.asset('assets/bilder/Applogo.png'), - ), - const SizedBox(height: 20), - MyTextField( - controller: emailController, - hintText: 'Email', - obscureText: false, - ), - const SizedBox(height: 10), - Stack( - alignment: Alignment.centerRight, - children: [ - MyTextField( - controller: passwordController, - hintText: 'Password', - obscureText: _obscureText, + GestureDetector( + onTapDown: (_) { + setState(() { + _obscureText = false; + }); + }, + onTapUp: (_) { + setState(() { + _obscureText = true; + }); + }, + child: Padding( + padding: const EdgeInsets.only(right: 10), + child: Icon( + _obscureText ? Icons.visibility_off : Icons.visibility, + color: Colors.white, + ), ), + ), + ], + ), + SizedBox(height: screenHeight * 0.02), + Padding( + padding: const EdgeInsets.symmetric(horizontal: 30), + child: Row( + mainAxisAlignment: MainAxisAlignment.end, + children: [ GestureDetector( - onTapDown: (_) { - setState(() { - _obscureText = false; - }); - }, - onTapUp: (_) { - setState(() { - _obscureText = true; - }); + onTap: () { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) { + return const ForgotPasswordPage(); + }, + ), + ); }, - child: Padding( - padding: const EdgeInsets.only(right: 10), - child: Icon( - _obscureText ? Icons.visibility_off : Icons.visibility, - color: Colors.white, + child: const Text( + 'Forgot Password?', + style: TextStyle( + color: Color.fromARGB(255, 41, 51, 76), + fontWeight: FontWeight.bold, ), ), ), ], ), - const SizedBox(height: 4), - Padding( - padding: const EdgeInsets.symmetric(horizontal: 30), - child: Row( - mainAxisAlignment: MainAxisAlignment.end, - children: [ - GestureDetector( - onTap: () { - Navigator.push( - context, - MaterialPageRoute( - builder: (context) { - return const ForgotPasswordPage(); - }, - ), - ); - }, - child: const Text( - 'Forgot Password?', - style: TextStyle( - color: Color.fromARGB(255, 41, 51, 76), - fontWeight: FontWeight.bold, - ), - ), - ), - ], - ), - ), - const SizedBox(height: 20), - MyButton( - text: "Log In", - onTap: () { - signUserIn(); - }, - ), - const SizedBox(height: 90), - const Padding( - padding: EdgeInsets.symmetric(horizontal: 30), - child: Row( - children: [ - Expanded( - child: Divider( - thickness: 0.5, - color: Colors.white, - ), - ), - Padding( - padding: EdgeInsets.symmetric(horizontal: 15), - child: Text( - 'Or continue with', - style: TextStyle( - color: Color.fromARGB(255, 66, 66, 66)), - ), - ), - Expanded( - child: Divider( - thickness: 0.5, - color: Colors.white, - ), - ), - ], - ), - ), - const SizedBox(height: 20), - Row( - mainAxisAlignment: MainAxisAlignment.center, + ), + const SizedBox(height: 86.5), + MyButton( + text: "Log In", + onTap: () { + signUserIn(); + }, + ), + SizedBox(height: screenHeight * 0.05), + const Padding( + padding: EdgeInsets.symmetric(horizontal: 30), + child: Row( children: [ - IconButton( - onPressed: () => AuthService().signInWithGoogle(), - icon: Icon( - FontAwesomeIcons.google, - size: 50, - color: const Color.fromRGBO(1, 25, 45, 0.7), + Expanded( + child: Divider( + thickness: 0.5, + color: Colors.white, + ), + ), + Padding( + padding: EdgeInsets.symmetric(horizontal: 15), + child: Text( + 'Or continue with', + style: TextStyle(color: Color.fromARGB(255, 66, 66, 66)), ), ), - SizedBox(width: 10), - IconButton( - onPressed: () {}, - icon: Icon( - FontAwesomeIcons.apple, - size: 50, - color: const Color.fromRGBO(1, 25, 45, 0.7), + Expanded( + child: Divider( + thickness: 0.5, + color: Colors.white, ), ), ], ), - const SizedBox(height: 20), - Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - const Text( - 'Not am Member?', - style: - TextStyle(color: Color.fromARGB(255, 66, 66, 66)), + ), + SizedBox(height: screenHeight * 0.02), + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + IconButton( + onPressed: () => AuthService().signInWithGoogle(), + icon: Icon( + FontAwesomeIcons.google, + size: 50, + color: const Color.fromRGBO(1, 25, 45, 0.7), ), - const SizedBox(width: 4), - GestureDetector( - onTap: widget.onTap, - child: const Text( - 'Register now', - style: TextStyle( - color: Color.fromARGB(255, 41, 51, 76), - fontWeight: FontWeight.bold, - ), + ), + SizedBox(width: screenWidth * 0.05), + IconButton( + onPressed: () {}, + icon: Icon( + FontAwesomeIcons.apple, + size: 50, + color: const Color.fromRGBO(1, 25, 45, 0.7), + ), + ), + ], + ), + SizedBox(height: screenHeight * 0.02), + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + const Text( + 'Not a Member?', + style: TextStyle(color: Color.fromARGB(255, 66, 66, 66)), + ), + const SizedBox(width: 4), + GestureDetector( + onTap: widget.onTap, + child: const Text( + 'Register now', + style: TextStyle( + color: Color.fromARGB(255, 41, 51, 76), + fontWeight: FontWeight.bold, ), ), - ], - ), - if (_isLoading) - const CircularProgressIndicator( - color: Color.fromARGB(255, 41, 51, 76), ), - ], - ), + ], + ), + SizedBox(height: screenHeight * 0.05), + if (_isLoading) + const CircularProgressIndicator( + color: Color.fromARGB(255, 41, 51, 76), + ), + ], ), - ); - }, + ), + ), + ), + ), + ); + } +} + +class MyButton extends StatelessWidget { + final String text; + final VoidCallback onTap; + + const MyButton({Key? key, required this.text, required this.onTap}) + : super(key: key); + + @override + Widget build(BuildContext context) { + return GestureDetector( + onTap: onTap, + child: Container( + width: double.infinity, + padding: const EdgeInsets.symmetric(vertical: 12), + decoration: BoxDecoration( + color: const Color.fromRGBO(41, 51, 76, 1.0), + borderRadius: BorderRadius.circular(10), + ), + alignment: Alignment.center, + child: Text( + text, + style: const TextStyle( + color: Colors.white, + fontSize: 16, + ), ), ), ); diff --git a/lib/Screens/LogIn/register_page.dart b/lib/Screens/LogIn/register_page.dart index 41d1782..a048718 100644 --- a/lib/Screens/LogIn/register_page.dart +++ b/lib/Screens/LogIn/register_page.dart @@ -2,9 +2,6 @@ import 'package:app_prototyo/Screens/CreateUser/welcomescreen.dart'; import 'package:app_prototyo/Screens/LogIn/auth_page.dart'; import 'package:app_prototyo/Screens/LogIn/services/auth_service.dart'; import 'package:cloud_firestore/cloud_firestore.dart'; -import 'package:flutter/material.dart'; -import 'package:firebase_auth/firebase_auth.dart'; - import 'package:flutter/material.dart'; import 'package:firebase_auth/firebase_auth.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; @@ -22,6 +19,8 @@ class _RegisterPageState extends State { final emailController = TextEditingController(); final passwordController = TextEditingController(); final confirmPasswordController = TextEditingController(); + bool _obscurePassword = true; + bool _obscureConfirmPassword = true; Future signUserUp() async { try { @@ -72,6 +71,32 @@ class _RegisterPageState extends State { ); } + Widget buildTextField({ + required TextEditingController controller, + required String hintText, + required bool obscureText, + }) { + return TextField( + controller: controller, + obscureText: obscureText, + style: const TextStyle(color: Colors.white), + decoration: InputDecoration( + hintText: hintText, + hintStyle: const TextStyle(color: Colors.white70), + filled: true, + fillColor: const Color.fromRGBO(1, 25, 45, 0.7), + enabledBorder: OutlineInputBorder( + borderSide: const BorderSide(color: Colors.transparent), + borderRadius: BorderRadius.circular(10), + ), + focusedBorder: OutlineInputBorder( + borderSide: const BorderSide(color: Colors.white), + borderRadius: BorderRadius.circular(10), + ), + ), + ); + } + @override Widget build(BuildContext context) { final screenHeight = MediaQuery.of(context).size.height; @@ -85,7 +110,7 @@ class _RegisterPageState extends State { child: Padding( padding: const EdgeInsets.symmetric(horizontal: 30), child: Column( - mainAxisAlignment: MainAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ SizedBox(height: screenHeight * 0.02), Container( @@ -102,22 +127,70 @@ class _RegisterPageState extends State { ), ), SizedBox(height: screenHeight * 0.02), - MyTextField( + buildTextField( controller: emailController, hintText: 'Email', obscureText: false, ), SizedBox(height: screenHeight * 0.02), - MyTextField( - controller: passwordController, - hintText: 'Password', - obscureText: true, + Stack( + alignment: Alignment.centerRight, + children: [ + buildTextField( + controller: passwordController, + hintText: 'Password', + obscureText: _obscurePassword, + ), + GestureDetector( + onTapDown: (_) { + setState(() { + _obscurePassword = false; + }); + }, + onTapUp: (_) { + setState(() { + _obscurePassword = true; + }); + }, + child: Padding( + padding: const EdgeInsets.only(right: 10), + child: Icon( + _obscurePassword ? Icons.visibility_off : Icons.visibility, + color: Colors.white, + ), + ), + ), + ], ), SizedBox(height: screenHeight * 0.02), - MyTextField( - controller: confirmPasswordController, - hintText: 'Confirm Password', - obscureText: true, + Stack( + alignment: Alignment.centerRight, + children: [ + buildTextField( + controller: confirmPasswordController, + hintText: 'Confirm Password', + obscureText: _obscureConfirmPassword, + ), + GestureDetector( + onTapDown: (_) { + setState(() { + _obscureConfirmPassword = false; + }); + }, + onTapUp: (_) { + setState(() { + _obscureConfirmPassword = true; + }); + }, + child: Padding( + padding: const EdgeInsets.only(right: 10), + child: Icon( + _obscureConfirmPassword ? Icons.visibility_off : Icons.visibility, + color: Colors.white, + ), + ), + ), + ], ), SizedBox(height: screenHeight * 0.05), MyButton( @@ -151,8 +224,7 @@ class _RegisterPageState extends State { padding: EdgeInsets.symmetric(horizontal: 15), child: Text( 'Or continue with', - style: TextStyle( - color: Color.fromARGB(255, 66, 66, 66)), + style: TextStyle(color: Color.fromARGB(255, 66, 66, 66)), ), ), Expanded( @@ -193,8 +265,7 @@ class _RegisterPageState extends State { children: [ const Text( 'Already have an account?', - style: - TextStyle(color: Color.fromARGB(255, 66, 66, 66)), + style: TextStyle(color: Color.fromARGB(255, 66, 66, 66)), ), const SizedBox(width: 4), GestureDetector( @@ -209,6 +280,7 @@ class _RegisterPageState extends State { ), ], ), + SizedBox(height: screenHeight * 0.05), ], ), ), @@ -219,42 +291,6 @@ class _RegisterPageState extends State { } } -class MyTextField extends StatelessWidget { - final TextEditingController controller; - final String hintText; - final bool obscureText; - - const MyTextField({ - Key? key, - required this.controller, - required this.hintText, - this.obscureText = false, - }) : super(key: key); - - @override - Widget build(BuildContext context) { - return TextField( - controller: controller, - obscureText: obscureText, - style: const TextStyle(color: Colors.white), - decoration: InputDecoration( - hintText: hintText, - hintStyle: const TextStyle(color: Colors.white70), - filled: true, - fillColor: const Color.fromRGBO(1, 25, 45, 0.7), - enabledBorder: OutlineInputBorder( - borderSide: const BorderSide(color: Colors.transparent), - borderRadius: BorderRadius.circular(10), - ), - focusedBorder: OutlineInputBorder( - borderSide: const BorderSide(color: Colors.white), - borderRadius: BorderRadius.circular(10), - ), - ), - ); - } -} - class MyButton extends StatelessWidget { final String text; final VoidCallback onTap; @@ -285,29 +321,3 @@ class MyButton extends StatelessWidget { ); } } - -class SquareTile extends StatelessWidget { - final VoidCallback onTap; - final String imagePath; - - const SquareTile({Key? key, required this.onTap, required this.imagePath}) - : super(key: key); - - @override - Widget build(BuildContext context) { - return GestureDetector( - onTap: onTap, - child: Container( - width: 60, - height: 60, - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(10), - image: DecorationImage( - image: AssetImage(imagePath), - fit: BoxFit.cover, - ), - ), - ), - ); - } -} From 070a0670085edefdedf02689bbbc9ffd5ef7cb7d Mon Sep 17 00:00:00 2001 From: sweier2 Date: Sun, 16 Jun 2024 22:07:11 +0200 Subject: [PATCH 3/4] forgot password page --- lib/Screens/LogIn/forgot_pw_page.dart | 147 ++++++++++++++++---------- 1 file changed, 94 insertions(+), 53 deletions(-) diff --git a/lib/Screens/LogIn/forgot_pw_page.dart b/lib/Screens/LogIn/forgot_pw_page.dart index 9194d1b..53ffa0b 100644 --- a/lib/Screens/LogIn/forgot_pw_page.dart +++ b/lib/Screens/LogIn/forgot_pw_page.dart @@ -17,7 +17,7 @@ class _ForgotPasswordPageState extends State { super.dispose(); } - Future passwordReset() async { + Future passwordReset() async { try { await FirebaseAuth.instance .sendPasswordResetEmail(email: _emailController.text.trim()); @@ -25,7 +25,7 @@ class _ForgotPasswordPageState extends State { context: context, builder: (context) { return const AlertDialog( - content: Text('Password reset link sent! Check your email'), + content: Text('Password reset link sent! Check your email.'), ); }, ); @@ -41,8 +41,61 @@ class _ForgotPasswordPageState extends State { } } + Widget buildTextField({ + required TextEditingController controller, + required String hintText, + required bool obscureText, + }) { + return TextField( + controller: controller, + obscureText: obscureText, + style: const TextStyle(color: Colors.white), + decoration: InputDecoration( + hintText: hintText, + hintStyle: const TextStyle(color: Colors.white70), + filled: true, + fillColor: const Color.fromRGBO(1, 25, 45, 0.7), + enabledBorder: OutlineInputBorder( + borderSide: const BorderSide(color: Colors.transparent), + borderRadius: BorderRadius.circular(10), + ), + focusedBorder: OutlineInputBorder( + borderSide: const BorderSide(color: Colors.white), + borderRadius: BorderRadius.circular(10), + ), + ), + ); + } + + Widget buildButton({ + required String text, + required VoidCallback onTap, + }) { + return GestureDetector( + onTap: onTap, + child: Container( + width: double.infinity, + padding: const EdgeInsets.symmetric(vertical: 12), + decoration: BoxDecoration( + color: const Color.fromRGBO(41, 51, 76, 1.0), + borderRadius: BorderRadius.circular(10), + ), + alignment: Alignment.center, + child: Text( + text, + style: const TextStyle( + color: Colors.white, + fontSize: 16, + ), + ), + ), + ); + } + @override Widget build(BuildContext context) { + final screenWidth = MediaQuery.of(context).size.width; + return Scaffold( appBar: AppBar( iconTheme: const IconThemeData( @@ -52,63 +105,51 @@ class _ForgotPasswordPageState extends State { elevation: 0, ), backgroundColor: const Color.fromRGBO(75, 173, 193, 1.0), - body: SingleChildScrollView( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - // icon lock - Container( - margin: const EdgeInsets.only( - top: 20, - bottom: 5, - left: 20, - right: 20, + body: Align( + alignment: Alignment.topCenter, + child: Padding( + padding: const EdgeInsets.symmetric(horizontal: 20), + child: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + const SizedBox(height: 135), + Icon( + Icons.email_outlined, + size: screenWidth * 0.3, + color: Colors.white, ), - width: 200, // --> skaliert das LOGO - child: Image.asset('assets/bilder/open_lock.png', - color: const Color.fromARGB(255, 41, 51, 76)), - ), - const SizedBox(height: 70), - const Padding( - padding: EdgeInsets.symmetric(horizontal: 20), - child: Text( - 'Enter your Email and we will send you a password reset link', + const SizedBox(height: 20), + const Text( + 'Forgot Password', + style: TextStyle( + color: Colors.white, + fontSize: 28, + fontWeight: FontWeight.bold, + ), + ), + const SizedBox(height: 10), + const Text( + 'Enter your email address below to receive a password reset link.', textAlign: TextAlign.center, - style: TextStyle(fontSize: 20), + style: TextStyle( + color: Colors.white70, + fontSize: 16, + ), ), - ), - const SizedBox(height: 20), - Padding( - padding: const EdgeInsets.symmetric(horizontal: 30), - child: TextField( + const SizedBox(height: 20), + buildTextField( controller: _emailController, - decoration: InputDecoration( - enabledBorder: const OutlineInputBorder( - borderSide: - BorderSide(color: Color.fromRGBO(75, 173, 193, 1.0)), - ), - focusedBorder: const OutlineInputBorder( - borderSide: - BorderSide(color: Color.fromARGB(255, 41, 51, 76)), - ), - fillColor: const Color.fromARGB(214, 216, 231, 234), - filled: true, - hintText: 'Email', - hintStyle: TextStyle(color: Colors.grey[600]), - ), + hintText: 'Email', + obscureText: false, ), - ), - const SizedBox(height: 20), - MaterialButton( - height: 40, - onPressed: passwordReset, - color: const Color.fromARGB(255, 41, 51, 76), - child: const Text( - 'Reset Password', - style: TextStyle(color: Colors.white), + const SizedBox(height: 20), + buildButton( + text: 'Reset Password', + onTap: passwordReset, ), - ), - ], + ], + ), ), ), ); From 44ad03f1a23052309dcc340923ba42080174f126 Mon Sep 17 00:00:00 2001 From: sweier2 Date: Mon, 17 Jun 2024 18:09:58 +0200 Subject: [PATCH 4/4] Login optisch fertig --- lib/Screens/LogIn/forgot_pw_page.dart | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/Screens/LogIn/forgot_pw_page.dart b/lib/Screens/LogIn/forgot_pw_page.dart index 53ffa0b..491890f 100644 --- a/lib/Screens/LogIn/forgot_pw_page.dart +++ b/lib/Screens/LogIn/forgot_pw_page.dart @@ -1,3 +1,5 @@ +// ignore_for_file: use_build_context_synchronously + import 'package:firebase_auth/firebase_auth.dart'; import 'package:flutter/material.dart';