after rediense
This commit is contained in:
@@ -7,14 +7,18 @@ class MyUserEntity extends Equatable {
|
||||
final String? name;
|
||||
final String? nickname;
|
||||
final String? picture;
|
||||
final String? birthday;
|
||||
final String? gender;
|
||||
|
||||
const MyUserEntity({
|
||||
required this.id,
|
||||
this.email,
|
||||
this.phone,
|
||||
this.name,
|
||||
this.nickname,
|
||||
this.picture,
|
||||
required this.email,
|
||||
required this.phone,
|
||||
required this.name,
|
||||
required this.nickname,
|
||||
required this.picture,
|
||||
required this.birthday,
|
||||
required this.gender,
|
||||
});
|
||||
|
||||
Map<String, Object?> toDocument() {
|
||||
@@ -25,6 +29,8 @@ class MyUserEntity extends Equatable {
|
||||
'name': name,
|
||||
'nickname': name?.trim().toLowerCase(),
|
||||
'picture': picture,
|
||||
'birthday': birthday,
|
||||
'gender': gender,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -36,11 +42,14 @@ class MyUserEntity extends Equatable {
|
||||
name: doc['name'] as String?,
|
||||
nickname: doc['nickname'] as String?,
|
||||
picture: doc['picture'] as String?,
|
||||
birthday: doc['birthday'] as String?,
|
||||
gender: doc['gender'] as String?,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [id, email, phone, name, nickname, picture];
|
||||
List<Object?> get props =>
|
||||
[id, email, phone, name, nickname, picture, birthday, gender];
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
@@ -51,6 +60,8 @@ class MyUserEntity extends Equatable {
|
||||
name: $name
|
||||
nickname: $nickname
|
||||
picture: $picture
|
||||
birthday: $birthday
|
||||
gender: $gender
|
||||
}''';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@ class MyUser extends Equatable {
|
||||
final String? name;
|
||||
final String? nickname;
|
||||
final String? picture;
|
||||
final String? birthday;
|
||||
final String? gender;
|
||||
|
||||
const MyUser({
|
||||
required this.id,
|
||||
@@ -17,8 +19,16 @@ class MyUser extends Equatable {
|
||||
this.name,
|
||||
this.nickname,
|
||||
this.picture,
|
||||
this.birthday,
|
||||
this.gender,
|
||||
});
|
||||
|
||||
get drawerLabel => email != null && email!.isNotEmpty
|
||||
? email!
|
||||
: phone != null && phone!.isNotEmpty
|
||||
? phone!
|
||||
: "N/A";
|
||||
|
||||
/// Empty user which represents an unauthenticated user.
|
||||
static const empty = MyUser(
|
||||
id: '',
|
||||
@@ -27,6 +37,8 @@ class MyUser extends Equatable {
|
||||
name: '',
|
||||
nickname: '',
|
||||
picture: '',
|
||||
birthday: '',
|
||||
gender: '',
|
||||
);
|
||||
|
||||
/// Modify MyUser parameters
|
||||
@@ -37,6 +49,8 @@ class MyUser extends Equatable {
|
||||
String? name,
|
||||
String? nickname,
|
||||
String? picture,
|
||||
String? birthday,
|
||||
String? gender,
|
||||
}) {
|
||||
return MyUser(
|
||||
id: id ?? this.id,
|
||||
@@ -45,6 +59,8 @@ class MyUser extends Equatable {
|
||||
name: name ?? this.name,
|
||||
nickname: nickname ?? this.nickname,
|
||||
picture: picture ?? this.picture,
|
||||
birthday: birthday ?? this.birthday,
|
||||
gender: gender ?? this.gender,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -62,6 +78,8 @@ class MyUser extends Equatable {
|
||||
name: name,
|
||||
nickname: nickname,
|
||||
picture: picture,
|
||||
birthday: birthday,
|
||||
gender: gender,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -73,9 +91,12 @@ class MyUser extends Equatable {
|
||||
name: entity.name,
|
||||
nickname: entity.nickname,
|
||||
picture: entity.picture,
|
||||
birthday: entity.birthday,
|
||||
gender: entity.gender,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [id, email, phone, name, nickname, picture];
|
||||
List<Object?> get props =>
|
||||
[id, email, phone, name, nickname, picture, birthday, gender];
|
||||
}
|
||||
|
||||
@@ -218,25 +218,12 @@ class FirebaseUserRepository implements UserRepository {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> updateUserInfo(
|
||||
String userId, String? picture, Map<String, dynamic> data) async {
|
||||
Future<void> updateUserInfo(MyUser myUser) async {
|
||||
try {
|
||||
if (picture != null) {
|
||||
File imageFile = File(picture);
|
||||
Reference firebaseStoreRef =
|
||||
FirebaseStorage.instance.ref().child('$userId/PP/${userId}_lead');
|
||||
|
||||
await firebaseStoreRef.putFile(
|
||||
imageFile,
|
||||
);
|
||||
|
||||
String url = await firebaseStoreRef.getDownloadURL();
|
||||
await usersCollection.doc(userId).update({'picture': url});
|
||||
}
|
||||
|
||||
await usersCollection.doc(userId).update(data);
|
||||
|
||||
await updateFromFirebase(userId);
|
||||
await usersCollection
|
||||
.doc(myUser.id)
|
||||
.update(myUser.toEntity().toDocument());
|
||||
await updateFromFirebase(myUser.id);
|
||||
} catch (e) {
|
||||
log(e.toString());
|
||||
rethrow;
|
||||
@@ -249,11 +236,8 @@ class FirebaseUserRepository implements UserRepository {
|
||||
File imageFile = File(file);
|
||||
Reference firebaseStoreRef =
|
||||
FirebaseStorage.instance.ref().child('$userId/PP/${userId}_lead');
|
||||
await firebaseStoreRef.putFile(
|
||||
imageFile,
|
||||
);
|
||||
await firebaseStoreRef.putFile(imageFile);
|
||||
String url = await firebaseStoreRef.getDownloadURL();
|
||||
await usersCollection.doc(userId).update({'picture': url});
|
||||
return url;
|
||||
} catch (e) {
|
||||
log(e.toString());
|
||||
|
||||
@@ -22,8 +22,7 @@ abstract class UserRepository {
|
||||
|
||||
Future<MyUser?> getMyUser(String myUserId);
|
||||
|
||||
Future<void> updateUserInfo(
|
||||
String userId, String picture, Map<String, dynamic> data);
|
||||
Future<void> updateUserInfo(MyUser myUser);
|
||||
|
||||
Future<String> uploadPicture(String file, String userId);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user