form pro - sin imagenes
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:user_repository/src/models/models.dart';
|
||||
|
||||
class MyUserEntity extends Equatable {
|
||||
final String id;
|
||||
@@ -10,6 +11,7 @@ class MyUserEntity extends Equatable {
|
||||
final String? picture;
|
||||
final String? birthday;
|
||||
final String? gender;
|
||||
final ProState proState;
|
||||
|
||||
const MyUserEntity({
|
||||
required this.id,
|
||||
@@ -21,6 +23,7 @@ class MyUserEntity extends Equatable {
|
||||
required this.picture,
|
||||
required this.birthday,
|
||||
required this.gender,
|
||||
required this.proState,
|
||||
});
|
||||
|
||||
Map<String, Object?> toDocument() {
|
||||
@@ -34,6 +37,7 @@ class MyUserEntity extends Equatable {
|
||||
'picture': picture,
|
||||
'birthday': birthday,
|
||||
'gender': gender,
|
||||
'professional_state': enumToInt(proState),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -48,6 +52,7 @@ class MyUserEntity extends Equatable {
|
||||
picture: doc['picture'] as String?,
|
||||
birthday: doc['birthday'] as String?,
|
||||
gender: doc['gender'] as String?,
|
||||
proState: intToEnum(doc['professional_state'] as int),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -66,7 +71,8 @@ class MyUserEntity extends Equatable {
|
||||
city: $city
|
||||
picture: $picture
|
||||
birthday: $birthday
|
||||
gender: $gender
|
||||
gender: $gender,
|
||||
proState: ${proState.name}
|
||||
}''';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
export 'my_user.dart';
|
||||
export 'my_user.dart';
|
||||
export 'pro_state.dart';
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
|
||||
import '../entities/entities.dart';
|
||||
import 'package:user_repository/user_repository.dart';
|
||||
|
||||
class MyUser extends Equatable {
|
||||
final String id;
|
||||
@@ -12,6 +11,7 @@ class MyUser extends Equatable {
|
||||
final String? picture;
|
||||
final String? birthday;
|
||||
final String? gender;
|
||||
final ProState proState;
|
||||
|
||||
const MyUser({
|
||||
required this.id,
|
||||
@@ -23,6 +23,7 @@ class MyUser extends Equatable {
|
||||
this.picture,
|
||||
this.birthday,
|
||||
this.gender,
|
||||
required this.proState,
|
||||
});
|
||||
|
||||
get drawerLabel => email != null && email!.isNotEmpty
|
||||
@@ -42,6 +43,7 @@ class MyUser extends Equatable {
|
||||
picture: '',
|
||||
birthday: '',
|
||||
gender: '',
|
||||
proState: ProState.inactive,
|
||||
);
|
||||
|
||||
/// Modify MyUser parameters
|
||||
@@ -55,6 +57,7 @@ class MyUser extends Equatable {
|
||||
String? picture,
|
||||
String? birthday,
|
||||
String? gender,
|
||||
ProState? proState,
|
||||
}) {
|
||||
return MyUser(
|
||||
id: id ?? this.id,
|
||||
@@ -66,6 +69,7 @@ class MyUser extends Equatable {
|
||||
picture: picture ?? this.picture,
|
||||
birthday: birthday ?? this.birthday,
|
||||
gender: gender ?? this.gender,
|
||||
proState: proState ?? this.proState,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -86,6 +90,7 @@ class MyUser extends Equatable {
|
||||
picture: picture,
|
||||
birthday: birthday,
|
||||
gender: gender,
|
||||
proState: proState,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -100,6 +105,7 @@ class MyUser extends Equatable {
|
||||
picture: entity.picture,
|
||||
birthday: entity.birthday,
|
||||
gender: entity.gender,
|
||||
proState: entity.proState,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -114,5 +120,6 @@ class MyUser extends Equatable {
|
||||
picture,
|
||||
birthday,
|
||||
gender,
|
||||
proState,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
export 'pro_state.dart';
|
||||
|
||||
enum ProState { inactive, pending, active, denied }
|
||||
|
||||
int enumToInt(ProState state) {
|
||||
return state.index;
|
||||
}
|
||||
|
||||
ProState intToEnum(int value) {
|
||||
return ProState.values[value];
|
||||
}
|
||||
@@ -5,11 +5,13 @@ import 'dart:io';
|
||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||
import 'package:firebase_auth/firebase_auth.dart';
|
||||
import 'package:firebase_storage/firebase_storage.dart';
|
||||
import 'package:user_repository/src/models/my_user.dart';
|
||||
import 'package:user_repository/src/models/models.dart';
|
||||
import '../entities/entities.dart';
|
||||
import 'user_repo.dart';
|
||||
|
||||
class FirebaseUserRepository implements UserRepository {
|
||||
MyUser? _lastUser;
|
||||
|
||||
final FirebaseAuth _firebaseAuth;
|
||||
final usersCollection = FirebaseFirestore.instance.collection('users');
|
||||
final StreamController<MyUser?> _userStreamController =
|
||||
@@ -28,11 +30,27 @@ class FirebaseUserRepository implements UserRepository {
|
||||
nickname: user.displayName?.trim().toLowerCase(),
|
||||
);
|
||||
} else {
|
||||
_lastUser = null;
|
||||
_userStreamController.add(null);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Future<MyUser?> lastUser() async {
|
||||
return _lastUser;
|
||||
}
|
||||
|
||||
Future<void> refreshUser() async {
|
||||
final user = _firebaseAuth.currentUser;
|
||||
if (user != null) {
|
||||
await updateFromFirebase(user.uid);
|
||||
} else {
|
||||
_lastUser = null;
|
||||
_userStreamController.add(null);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> updateFromFirebase(String userId) async {
|
||||
return updateFromFirebase2(userId: userId);
|
||||
}
|
||||
@@ -56,12 +74,15 @@ class FirebaseUserRepository implements UserRepository {
|
||||
phone: phone,
|
||||
picture: picture,
|
||||
nickname: name?.trim().toLowerCase(),
|
||||
proState: ProState.inactive,
|
||||
));
|
||||
myUser = await getMyUser(userId);
|
||||
}
|
||||
_lastUser = myUser;
|
||||
_userStreamController.add(myUser);
|
||||
} catch (e) {
|
||||
log('xd -- Error updating from firebase ${e.toString()}');
|
||||
_lastUser = null;
|
||||
_userStreamController.add(null);
|
||||
}
|
||||
}
|
||||
@@ -131,6 +152,7 @@ class FirebaseUserRepository implements UserRepository {
|
||||
await setUserData(MyUser(
|
||||
id: credentials.user?.uid ?? '',
|
||||
phone: credentials.user?.phoneNumber ?? '',
|
||||
proState: ProState.inactive,
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@ import 'package:firebase_auth/firebase_auth.dart';
|
||||
import '../../user_repository.dart';
|
||||
|
||||
abstract class UserRepository {
|
||||
Future<MyUser?> lastUser();
|
||||
|
||||
Stream<MyUser?> streamUser();
|
||||
Stream<bool> isAuthenticated();
|
||||
|
||||
@@ -22,12 +24,9 @@ abstract class UserRepository {
|
||||
Future<bool> verifyOTP(String code);
|
||||
|
||||
Future<void> addPhoneAuthCredential(String password, String phoneNumber,
|
||||
{
|
||||
required Future<void> Function(FirebaseAuthException) verificationFailed,
|
||||
{required Future<void> Function(FirebaseAuthException) verificationFailed,
|
||||
required Future<void> Function(String) codeSent,
|
||||
required Future<void> Function(String) codeAutoRetrievalTimeout
|
||||
|
||||
});
|
||||
required Future<void> Function(String) codeAutoRetrievalTimeout});
|
||||
|
||||
Future<bool> linkWithOTP(
|
||||
String phoneNumber, String verificationId, String code);
|
||||
|
||||
Reference in New Issue
Block a user