se añadio un modelo y el menu de modo profesional

This commit is contained in:
Juan Felipe Duarte
2023-04-18 16:03:01 -05:00
parent 85c927918e
commit 6b09ce2f3a
10 changed files with 777 additions and 294 deletions
+44
View File
@@ -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);
}
}
}