copywith y nickname

This commit is contained in:
Felipe
2024-02-22 11:56:41 -05:00
parent 113937df56
commit 37b6665002
8 changed files with 46 additions and 17 deletions
-2
View File
@@ -4,8 +4,6 @@ import 'package:injector/injector.dart';
import 'package:prosappco/blocs/authentication_bloc/authentication_bloc.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/my_user_bloc/my_user_bloc.dart';
import 'package:prosappco/blocs/profile_bloc/profile_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'; import 'app_view.dart';
+1 -1
View File
@@ -18,7 +18,7 @@ class SignUpBloc extends Bloc<SignUpEvent, SignUpState> {
SignUpRequired event, Emitter<SignUpState> emit) async { SignUpRequired event, Emitter<SignUpState> emit) async {
emit(SignUpProcess()); emit(SignUpProcess());
try { try {
MyUser user = await _userRepository.signUp(event.email, event.password); MyUser user = await _userRepository.signUp(event.user, event.password);
await _userRepository.setUserData(user); await _userRepository.setUserData(user);
emit(SignUpSuccess()); emit(SignUpSuccess());
} catch (e) { } catch (e) {
+2 -3
View File
@@ -8,9 +8,8 @@ abstract class SignUpEvent extends Equatable {
} }
class SignUpRequired extends SignUpEvent { class SignUpRequired extends SignUpEvent {
final String email; final MyUser user;
final String password; final String password;
const SignUpRequired({required this.email, required this.password}); const SignUpRequired(this.user, this.password);
// const SignUpRequired(this.email, this.password);
} }
@@ -227,9 +227,7 @@ class _SignUpScreenState extends State<SignUpScreen> {
setState(() { setState(() {
context.read<SignUpBloc>().add(SignUpRequired( context.read<SignUpBloc>().add(SignUpRequired(
email: emailController.text, myUser, passwordController.text));
password: passwordController.text,
));
}); });
} }
}, },
@@ -3,13 +3,17 @@ import 'package:equatable/equatable.dart';
class MyUserEntity extends Equatable { class MyUserEntity extends Equatable {
final String id; final String id;
final String? email; final String? email;
final String? phone;
final String? name; final String? name;
final String? nickname;
final String? picture; final String? picture;
const MyUserEntity({ const MyUserEntity({
required this.id, required this.id,
this.email, this.email,
this.phone,
this.name, this.name,
this.nickname,
this.picture, this.picture,
}); });
@@ -17,7 +21,9 @@ class MyUserEntity extends Equatable {
return { return {
'id': id, 'id': id,
'email': email, 'email': email,
'phone': phone,
'name': name, 'name': name,
'nickname': name?.trim().toLowerCase(),
'picture': picture, 'picture': picture,
}; };
} }
@@ -26,20 +32,24 @@ class MyUserEntity extends Equatable {
return MyUserEntity( return MyUserEntity(
id: doc['id'] as String, id: doc['id'] as String,
email: doc['email'] as String?, email: doc['email'] as String?,
phone: doc['phone'] as String?,
name: doc['name'] as String?, name: doc['name'] as String?,
nickname: doc['nickname'] as String?,
picture: doc['picture'] as String?, picture: doc['picture'] as String?,
); );
} }
@override @override
List<Object?> get props => [id, email, name, picture]; List<Object?> get props => [id, email, phone, name, nickname, picture];
@override @override
String toString() { String toString() {
return '''UserEntity { return '''UserEntity {
id: $id id: $id
email: $email email: $email
phone: $phone
name: $name name: $name
nickname: $nickname
picture: $picture picture: $picture
}'''; }''';
} }
@@ -5,30 +5,45 @@ import '../entities/entities.dart';
class MyUser extends Equatable { class MyUser extends Equatable {
final String id; final String id;
final String? email; final String? email;
final String? phone;
final String? name; final String? name;
final String? nickname;
final String? picture; final String? picture;
MyUser({ const MyUser({
required this.id, required this.id,
this.email, this.email,
this.phone,
this.name, this.name,
this.nickname,
this.picture, this.picture,
}); });
/// Empty user which represents an unauthenticated user. /// 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 /// Modify MyUser parameters
MyUser copyWith({ MyUser copyWith({
String? id, String? id,
String? email, String? email,
String? phone,
String? name, String? name,
String? nickname,
String? picture, String? picture,
}) { }) {
return MyUser( return MyUser(
id: id ?? this.id, id: id ?? this.id,
email: email ?? this.email, email: email ?? this.email,
phone: phone ?? this.phone,
name: name ?? this.name, name: name ?? this.name,
nickname: nickname ?? this.nickname,
picture: picture ?? this.picture, picture: picture ?? this.picture,
); );
} }
@@ -43,7 +58,9 @@ class MyUser extends Equatable {
return MyUserEntity( return MyUserEntity(
id: id, id: id,
email: email, email: email,
phone: phone,
name: name, name: name,
nickname: nickname,
picture: picture, picture: picture,
); );
} }
@@ -52,11 +69,13 @@ class MyUser extends Equatable {
return MyUser( return MyUser(
id: entity.id, id: entity.id,
email: entity.email, email: entity.email,
phone: entity.phone,
name: entity.name, name: entity.name,
nickname: entity.nickname,
picture: entity.picture, picture: entity.picture,
); );
} }
@override @override
List<Object?> get props => [id, email, name, picture]; List<Object?> get props => [id, email, phone, name, nickname, picture];
} }
@@ -53,14 +53,16 @@ class FirebaseUserRepository implements UserRepository {
// Sign up // Sign up
@override @override
Future<MyUser> signUp(String email, String password) async { Future<MyUser> signUp(MyUser myUser, String password) async {
try { try {
UserCredential user = await _firebaseAuth.createUserWithEmailAndPassword( UserCredential user = await _firebaseAuth.createUserWithEmailAndPassword(
email: email, email: myUser.email!,
password: password, password: password,
); );
return await getMyUser(user.user!.uid); myUser = myUser.copyWith(id: user.user!.uid);
return myUser;
} catch (e) { } catch (e) {
log(e.toString()); log(e.toString());
rethrow; rethrow;
@@ -212,7 +214,9 @@ class FirebaseUserRepository implements UserRepository {
await usersCollection.doc(userId).set({ await usersCollection.doc(userId).set({
'id': userId, 'id': userId,
'name': '', 'name': '',
'nickname': '',
'email': '', 'email': '',
'phone': '',
'picture': '', 'picture': '',
}); });
} catch (e) { } catch (e) {
@@ -9,7 +9,8 @@ abstract class UserRepository {
Future<void> logOut(); Future<void> logOut();
Future<MyUser> signUp(String email, String password); // Future<MyUser> signUp(String name, String email, String password);
Future<MyUser> signUp(MyUser myUser, String password);
Future<void> signInWithPhoneNumber(String phoneNumber); Future<void> signInWithPhoneNumber(String phoneNumber);