se añadio un modelo y el menu de modo profesional
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
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 {
|
||||
final String name;
|
||||
final String city;
|
||||
final String? state;
|
||||
final Reference? photo;
|
||||
final ScoreModel? score;
|
||||
|
||||
UserModel(this.name, this.city, this.state, this.photo, this.score);
|
||||
|
||||
static Future<UserModel> fromJson(Map<String, dynamic>? json) async {
|
||||
try {
|
||||
if (json == null) return UserModel('', '', null, null, null);
|
||||
|
||||
String? avatar = json['photo'];
|
||||
return UserModel(
|
||||
json['name'],
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
static Future<UserModel> getUser(String uid) async {
|
||||
try {
|
||||
final snapshot =
|
||||
await FirebaseFirestore.instance.collection('users').doc(uid).get();
|
||||
final Map<String, dynamic>? data = snapshot.data();
|
||||
return fromJson(data);
|
||||
} catch (e) {
|
||||
print('Error getting user: $e');
|
||||
return UserModel('', '', null, null, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user