From 37b66650025ca71cf21be06871539377a8027aad Mon Sep 17 00:00:00 2001 From: Felipe Date: Thu, 22 Feb 2024 11:56:41 -0500 Subject: [PATCH] copywith y nickname --- lib/app.dart | 2 -- lib/blocs/sign_up_bloc/sign_up_bloc.dart | 2 +- lib/blocs/sign_up_bloc/sign_up_event.dart | 5 ++-- .../authentication/sign_up_screen.dart | 4 +-- .../lib/src/entities/my_user_entity.dart | 12 ++++++++- .../lib/src/models/my_user.dart | 25 ++++++++++++++++--- .../firebase_user_repository.dart | 10 +++++--- .../lib/src/repositories/user_repo.dart | 3 ++- 8 files changed, 46 insertions(+), 17 deletions(-) diff --git a/lib/app.dart b/lib/app.dart index 5b3e67d..03ca4ba 100644 --- a/lib/app.dart +++ b/lib/app.dart @@ -4,8 +4,6 @@ import 'package:injector/injector.dart'; import 'package:prosappco/blocs/authentication_bloc/authentication_bloc.dart'; import 'package:prosappco/blocs/my_user_bloc/my_user_bloc.dart'; import 'package:prosappco/blocs/profile_bloc/profile_bloc.dart'; -import 'package:prosappco/blocs/sign_up_bloc/sign_up_bloc.dart'; -import 'package:prosappco/blocs/sing_in_bloc/sign_in_bloc.dart'; import 'app_view.dart'; diff --git a/lib/blocs/sign_up_bloc/sign_up_bloc.dart b/lib/blocs/sign_up_bloc/sign_up_bloc.dart index 60c21e4..f2e9b1e 100644 --- a/lib/blocs/sign_up_bloc/sign_up_bloc.dart +++ b/lib/blocs/sign_up_bloc/sign_up_bloc.dart @@ -18,7 +18,7 @@ class SignUpBloc extends Bloc { SignUpRequired event, Emitter emit) async { emit(SignUpProcess()); try { - MyUser user = await _userRepository.signUp(event.email, event.password); + MyUser user = await _userRepository.signUp(event.user, event.password); await _userRepository.setUserData(user); emit(SignUpSuccess()); } catch (e) { diff --git a/lib/blocs/sign_up_bloc/sign_up_event.dart b/lib/blocs/sign_up_bloc/sign_up_event.dart index 19f4089..9243ab3 100644 --- a/lib/blocs/sign_up_bloc/sign_up_event.dart +++ b/lib/blocs/sign_up_bloc/sign_up_event.dart @@ -8,9 +8,8 @@ abstract class SignUpEvent extends Equatable { } class SignUpRequired extends SignUpEvent { - final String email; + final MyUser user; final String password; - const SignUpRequired({required this.email, required this.password}); - // const SignUpRequired(this.email, this.password); + const SignUpRequired(this.user, this.password); } diff --git a/lib/screens/authentication/sign_up_screen.dart b/lib/screens/authentication/sign_up_screen.dart index de8dd81..06605cd 100644 --- a/lib/screens/authentication/sign_up_screen.dart +++ b/lib/screens/authentication/sign_up_screen.dart @@ -227,9 +227,7 @@ class _SignUpScreenState extends State { setState(() { context.read().add(SignUpRequired( - email: emailController.text, - password: passwordController.text, - )); + myUser, passwordController.text)); }); } }, diff --git a/packages/user_repository/lib/src/entities/my_user_entity.dart b/packages/user_repository/lib/src/entities/my_user_entity.dart index fd35f67..255a58b 100644 --- a/packages/user_repository/lib/src/entities/my_user_entity.dart +++ b/packages/user_repository/lib/src/entities/my_user_entity.dart @@ -3,13 +3,17 @@ import 'package:equatable/equatable.dart'; class MyUserEntity extends Equatable { final String id; final String? email; + final String? phone; final String? name; + final String? nickname; final String? picture; const MyUserEntity({ required this.id, this.email, + this.phone, this.name, + this.nickname, this.picture, }); @@ -17,7 +21,9 @@ class MyUserEntity extends Equatable { return { 'id': id, 'email': email, + 'phone': phone, 'name': name, + 'nickname': name?.trim().toLowerCase(), 'picture': picture, }; } @@ -26,20 +32,24 @@ class MyUserEntity extends Equatable { return MyUserEntity( id: doc['id'] as String, email: doc['email'] as String?, + phone: doc['phone'] as String?, name: doc['name'] as String?, + nickname: doc['nickname'] as String?, picture: doc['picture'] as String?, ); } @override - List get props => [id, email, name, picture]; + List get props => [id, email, phone, name, nickname, picture]; @override String toString() { return '''UserEntity { id: $id email: $email + phone: $phone name: $name + nickname: $nickname picture: $picture }'''; } diff --git a/packages/user_repository/lib/src/models/my_user.dart b/packages/user_repository/lib/src/models/my_user.dart index fb0c5e2..53b3f0b 100644 --- a/packages/user_repository/lib/src/models/my_user.dart +++ b/packages/user_repository/lib/src/models/my_user.dart @@ -5,30 +5,45 @@ import '../entities/entities.dart'; class MyUser extends Equatable { final String id; final String? email; + final String? phone; final String? name; + final String? nickname; final String? picture; - MyUser({ + const MyUser({ required this.id, this.email, + this.phone, this.name, + this.nickname, this.picture, }); /// Empty user which represents an unauthenticated user. - static final empty = MyUser(id: '', email: '', name: '', picture: ''); + static const empty = MyUser( + id: '', + email: '', + phone: '', + name: '', + nickname: '', + picture: '', + ); /// Modify MyUser parameters MyUser copyWith({ String? id, String? email, + String? phone, String? name, + String? nickname, String? picture, }) { return MyUser( id: id ?? this.id, email: email ?? this.email, + phone: phone ?? this.phone, name: name ?? this.name, + nickname: nickname ?? this.nickname, picture: picture ?? this.picture, ); } @@ -43,7 +58,9 @@ class MyUser extends Equatable { return MyUserEntity( id: id, email: email, + phone: phone, name: name, + nickname: nickname, picture: picture, ); } @@ -52,11 +69,13 @@ class MyUser extends Equatable { return MyUser( id: entity.id, email: entity.email, + phone: entity.phone, name: entity.name, + nickname: entity.nickname, picture: entity.picture, ); } @override - List get props => [id, email, name, picture]; + List get props => [id, email, phone, name, nickname, picture]; } diff --git a/packages/user_repository/lib/src/repositories/firebase_user_repository.dart b/packages/user_repository/lib/src/repositories/firebase_user_repository.dart index 72f51f0..068a261 100644 --- a/packages/user_repository/lib/src/repositories/firebase_user_repository.dart +++ b/packages/user_repository/lib/src/repositories/firebase_user_repository.dart @@ -53,14 +53,16 @@ class FirebaseUserRepository implements UserRepository { // Sign up @override - Future signUp(String email, String password) async { + Future signUp(MyUser myUser, String password) async { try { UserCredential user = await _firebaseAuth.createUserWithEmailAndPassword( - email: email, + email: myUser.email!, password: password, ); - return await getMyUser(user.user!.uid); + myUser = myUser.copyWith(id: user.user!.uid); + + return myUser; } catch (e) { log(e.toString()); rethrow; @@ -212,7 +214,9 @@ class FirebaseUserRepository implements UserRepository { await usersCollection.doc(userId).set({ 'id': userId, 'name': '', + 'nickname': '', 'email': '', + 'phone': '', 'picture': '', }); } catch (e) { diff --git a/packages/user_repository/lib/src/repositories/user_repo.dart b/packages/user_repository/lib/src/repositories/user_repo.dart index 6b388b3..fba7e52 100644 --- a/packages/user_repository/lib/src/repositories/user_repo.dart +++ b/packages/user_repository/lib/src/repositories/user_repo.dart @@ -9,7 +9,8 @@ abstract class UserRepository { Future logOut(); - Future signUp(String email, String password); + // Future signUp(String name, String email, String password); + Future signUp(MyUser myUser, String password); Future signInWithPhoneNumber(String phoneNumber);