puntaje pro y cliente

This commit is contained in:
Juan Felipe Duarte
2023-04-26 17:26:31 -05:00
parent c1747a45b9
commit ad40b16933
7 changed files with 41 additions and 101 deletions
+7 -9
View File
@@ -1,6 +1,5 @@
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_storage/firebase_storage.dart';
import 'package:prosappco/src/models/score_model.dart';
import 'package:prosappco/src/screens/professional.dart';
class UserModel {
@@ -8,13 +7,13 @@ class UserModel {
final String city;
final String? state;
final Reference? photo;
final ScoreModel? score;
UserModel(this.name, this.city, this.state, this.photo, this.score);
UserModel(this.name, this.city, this.state, this.photo);
static Future<UserModel> fromJson(Map<String, dynamic>? json) async {
static Future<UserModel> fromJson(
Map<String, dynamic>? json, String uid) async {
try {
if (json == null) return UserModel('', '', null, null, null);
if (json == null) return UserModel('', '', null, null);
String? avatar = json['photo'];
return UserModel(
@@ -22,11 +21,10 @@ class UserModel {
json['city'],
json['estado'],
avatar != null ? storage.ref().child(avatar) : null,
await ScoreModel.fromJson(json['puntuacion'], false),
);
} catch (e) {
print('XD user $e');
return UserModel('', '', null, null, null);
return UserModel('', '', null, null);
}
}
@@ -35,10 +33,10 @@ class UserModel {
final snapshot =
await FirebaseFirestore.instance.collection('users').doc(uid).get();
final Map<String, dynamic>? data = snapshot.data();
return fromJson(data);
return fromJson(data, uid);
} catch (e) {
print('Error getting user: $e');
return UserModel('', '', null, null, null);
return UserModel('', '', null, null);
}
}
}