pro info
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
library professional_repository;
|
||||
|
||||
export 'src/models/models.dart';
|
||||
export 'src/entities/entities.dart';
|
||||
export 'src/repositories/firebase_professional_repository.dart';
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:professional_repository/professional_repository.dart';
|
||||
import 'package:professional_repository/src/models/location_preferences.dart';
|
||||
|
||||
class ProfessionalEntity extends Equatable {
|
||||
final String id;
|
||||
final String identification;
|
||||
final String address;
|
||||
final String aditionalAddress;
|
||||
final String profession;
|
||||
final String rate;
|
||||
final String location;
|
||||
final LocationPreferences locationPreferences;
|
||||
final String bannerPicture;
|
||||
final String identificationPicture;
|
||||
final String certificatePicture;
|
||||
final String latitude;
|
||||
@@ -21,9 +24,11 @@ class ProfessionalEntity extends Equatable {
|
||||
required this.id,
|
||||
required this.identification,
|
||||
required this.address,
|
||||
required this.aditionalAddress,
|
||||
required this.profession,
|
||||
required this.rate,
|
||||
required this.location,
|
||||
required this.locationPreferences,
|
||||
required this.bannerPicture,
|
||||
required this.identificationPicture,
|
||||
required this.certificatePicture,
|
||||
required this.latitude,
|
||||
@@ -39,9 +44,11 @@ class ProfessionalEntity extends Equatable {
|
||||
id: doc['id'] as String,
|
||||
identification: doc['identification'] as String,
|
||||
address: doc['address'] as String,
|
||||
aditionalAddress: doc['aditional_address'] as String,
|
||||
profession: doc['profession'] as String,
|
||||
rate: doc['rate'] as String,
|
||||
location: doc['location'] as String,
|
||||
locationPreferences: intToEnum(doc['location_preferences'] as int),
|
||||
bannerPicture: doc['banner_picture'] as String,
|
||||
identificationPicture: doc['identification_picture'] as String,
|
||||
certificatePicture: doc['certificate_picture'] as String,
|
||||
latitude: doc['latitude'] as String,
|
||||
@@ -54,14 +61,16 @@ class ProfessionalEntity extends Equatable {
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
Map<String, dynamic> toDocument() {
|
||||
return {
|
||||
'id': id,
|
||||
'identification': identification,
|
||||
'address': address,
|
||||
'aditional_address': aditionalAddress,
|
||||
'profession': profession,
|
||||
'rate': rate,
|
||||
'location': location,
|
||||
'location_preferences': enumToInt(locationPreferences),
|
||||
'banner_picture': bannerPicture,
|
||||
'identification_picture': identificationPicture,
|
||||
'certificate_picture': certificatePicture,
|
||||
'latitude': latitude,
|
||||
@@ -78,9 +87,11 @@ class ProfessionalEntity extends Equatable {
|
||||
id,
|
||||
identification,
|
||||
address,
|
||||
aditionalAddress,
|
||||
profession,
|
||||
rate,
|
||||
location,
|
||||
locationPreferences,
|
||||
bannerPicture,
|
||||
identificationPicture,
|
||||
certificatePicture,
|
||||
latitude,
|
||||
@@ -97,9 +108,11 @@ class ProfessionalEntity extends Equatable {
|
||||
id: $id,
|
||||
identification: $identification,
|
||||
address: $address,
|
||||
aditional_address: $aditionalAddress,
|
||||
profession: $profession,
|
||||
rate: $rate,
|
||||
location: $location,
|
||||
location_preferences: $locationPreferences,
|
||||
bannerPicture: $bannerPicture,
|
||||
identificationPicture: $identificationPicture,
|
||||
certificatePicture: $certificatePicture,
|
||||
latitude: $latitude,
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
export 'location_preferences.dart';
|
||||
|
||||
enum LocationPreferences { office, delivery, both }
|
||||
|
||||
int enumToInt(LocationPreferences state) {
|
||||
return state.index;
|
||||
}
|
||||
|
||||
LocationPreferences intToEnum(int value) {
|
||||
return LocationPreferences.values[value];
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export 'location_preferences.dart';
|
||||
+76
-6
@@ -1,33 +1,103 @@
|
||||
import 'dart:async';
|
||||
import 'dart:developer';
|
||||
import 'dart:io';
|
||||
import 'package:firebase_auth/firebase_auth.dart';
|
||||
|
||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||
import 'package:professional_repository/professional_repository.dart';
|
||||
import 'package:firebase_storage/firebase_storage.dart';
|
||||
|
||||
class FirebaseProfessionalRepository {
|
||||
bool isProModeActive = false;
|
||||
final professionalCollection =
|
||||
FirebaseFirestore.instance.collection('professional_info');
|
||||
final StreamController<bool> _userStreamController =
|
||||
|
||||
ProfessionalEntity? _proInfo;
|
||||
final StreamController<ProfessionalEntity?> _proInfoBroadcast =
|
||||
StreamController<ProfessionalEntity?>.broadcast();
|
||||
|
||||
bool isProModeActive = false;
|
||||
|
||||
final StreamController<bool> _isProModeActiveBroadcast =
|
||||
StreamController.broadcast();
|
||||
|
||||
FirebaseProfessionalRepository() {
|
||||
_userStreamController.add(isProModeActive);
|
||||
_isProModeActiveBroadcast.add(isProModeActive);
|
||||
|
||||
FirebaseAuth.instance.userChanges().listen((user) async {
|
||||
if (user != null) {
|
||||
await updateFromFirebase2(
|
||||
userId: user.uid,
|
||||
);
|
||||
} else {
|
||||
_proInfo = null;
|
||||
_proInfoBroadcast.add(null);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ProfessionalEntity? lastProInfo() {
|
||||
return _proInfo;
|
||||
}
|
||||
|
||||
Stream<ProfessionalEntity?> streamProInfo() {
|
||||
return _proInfoBroadcast.stream;
|
||||
}
|
||||
|
||||
Future<void> updateFromFirebase2({
|
||||
required String userId,
|
||||
}) async {
|
||||
try {
|
||||
final proInfo = await getProInfo(userId);
|
||||
_proInfo = proInfo;
|
||||
_proInfoBroadcast.add(proInfo);
|
||||
} catch (e) {
|
||||
log('xd -- Error updating from firebase ${e.toString()}');
|
||||
_proInfo = null;
|
||||
_proInfoBroadcast.add(null);
|
||||
}
|
||||
}
|
||||
|
||||
Future<ProfessionalEntity?> getProInfo(String myUserId) async {
|
||||
try {
|
||||
return professionalCollection.doc(myUserId).get().then((value) {
|
||||
final valueData = value.data();
|
||||
if (valueData == null || valueData.isEmpty || !value.exists) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return ProfessionalEntity.fromDocument(valueData);
|
||||
});
|
||||
} catch (e) {
|
||||
log(e.toString());
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
Stream<bool> sreamIsProModeActive() {
|
||||
return _userStreamController.stream;
|
||||
return _isProModeActiveBroadcast.stream;
|
||||
}
|
||||
|
||||
switchProMode() async {
|
||||
isProModeActive = !isProModeActive;
|
||||
_userStreamController.add(isProModeActive);
|
||||
_isProModeActiveBroadcast.add(isProModeActive);
|
||||
}
|
||||
|
||||
Future<void> saveProfessionalInfo(ProfessionalEntity entity) async {
|
||||
await professionalCollection.doc(entity.id).set(entity.toJson());
|
||||
await professionalCollection.doc(entity.id).set(entity.toDocument());
|
||||
}
|
||||
|
||||
Future<String> uploadBannerPicture(String file, String userId) async {
|
||||
try {
|
||||
File imageFile = File(file);
|
||||
Reference firebaseStoreRef =
|
||||
FirebaseStorage.instance.ref().child('$userId/BN/${userId}_banner');
|
||||
await firebaseStoreRef.putFile(imageFile);
|
||||
String url = await firebaseStoreRef.getDownloadURL();
|
||||
return url;
|
||||
} catch (e) {
|
||||
log(e.toString());
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
Future<String> uploadPdfCedula(String file, String userId) async {
|
||||
|
||||
@@ -89,6 +89,30 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.3.1"
|
||||
firebase_auth:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: firebase_auth
|
||||
sha256: "17b841e1b000c3441b8ffceca88f468e078d0443db9643e77541bdfb7a3fd16b"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "4.17.8"
|
||||
firebase_auth_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: firebase_auth_platform_interface
|
||||
sha256: f294ceef40409a36c819a14280ca864fe487b44033e5276443377c66cb448310
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "7.1.8"
|
||||
firebase_auth_web:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: firebase_auth_web
|
||||
sha256: "1f231da900fe7ff9f2974f8adcbdb3363c410c24725978afa5dc33e1e7e62e06"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "5.9.8"
|
||||
firebase_core:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
||||
@@ -17,6 +17,7 @@ dependencies:
|
||||
firebase_storage: ^11.6.5
|
||||
firebase_core: ^2.25.4
|
||||
intl: ^0.18.1
|
||||
firebase_auth: ^4.17.8
|
||||
|
||||
dev_dependencies:
|
||||
flutter_lints: ^2.0.0
|
||||
|
||||
@@ -6,6 +6,7 @@ abstract class UserRepository {
|
||||
Future<MyUser?> lastUser();
|
||||
|
||||
Stream<MyUser?> streamUser();
|
||||
|
||||
Stream<bool> isAuthenticated();
|
||||
|
||||
Future<void> signIn(String email, String password);
|
||||
|
||||
Reference in New Issue
Block a user