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/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';
+1 -1
View File
@@ -18,7 +18,7 @@ class SignUpBloc extends Bloc<SignUpEvent, SignUpState> {
SignUpRequired event, Emitter<SignUpState> 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) {
+2 -3
View File
@@ -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);
}
@@ -227,9 +227,7 @@ class _SignUpScreenState extends State<SignUpScreen> {
setState(() {
context.read<SignUpBloc>().add(SignUpRequired(
email: emailController.text,
password: passwordController.text,
));
myUser, passwordController.text));
});
}
},
@@ -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<Object?> get props => [id, email, name, picture];
List<Object?> 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
}''';
}
@@ -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<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
@override
Future<MyUser> signUp(String email, String password) async {
Future<MyUser> 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) {
@@ -9,7 +9,8 @@ abstract class UserRepository {
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);