import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:firebase_storage/firebase_storage.dart'; import 'package:prosappco/src/screens/professional.dart'; class UserModel { final String name; final String city; final String? profession; final String? state; final Reference? photo; final int? tarifa; UserModel(this.name, this.city, this.profession, this.state, this.photo, this.tarifa); static Future fromJson( Map? json, String uid) async { try { if (json == null) return UserModel('', '', '', null, null, 0); String? avatar = json['photo']; return UserModel( json['name'], json['city'], json['profesion'], json['estado'], avatar != null ? storage.ref().child(avatar) : null, json['tarifa'] ?? 0); } catch (e) { print('XD user $e'); return UserModel('', '', '', null, null, 0); } } static Future getUser(String uid) async { try { final snapshot = await FirebaseFirestore.instance.collection('users').doc(uid).get(); final Map? data = snapshot.data(); return fromJson(data, uid); } catch (e) { print('Error getting user: $e'); return UserModel('', '', '', null, null, 0); } } }