This commit is contained in:
Juan Felipe Duarte
2023-06-05 16:10:43 -05:00
parent d32404d0f4
commit b1dcbfa767
3 changed files with 5 additions and 15 deletions
+4 -6
View File
@@ -10,15 +10,14 @@ class UserModel {
final Reference? photo; final Reference? photo;
final int? tarifa; final int? tarifa;
final String? phoneNumber; final String? phoneNumber;
final String? token;
UserModel(this.name, this.city, this.profession, this.state, this.photo, UserModel(this.name, this.city, this.profession, this.state, this.photo,
this.tarifa, this.phoneNumber, this.token); this.tarifa, this.phoneNumber);
static Future<UserModel> fromJson( static Future<UserModel> fromJson(
Map<String, dynamic>? json, String uid) async { Map<String, dynamic>? json, String uid) async {
try { try {
if (json == null) return UserModel('', '', '', null, null, 0, '', ''); if (json == null) return UserModel('', '', '', null, null, 0, '');
String? avatar = json['photo']; String? avatar = json['photo'];
return UserModel( return UserModel(
@@ -29,11 +28,10 @@ class UserModel {
avatar != null ? storage.ref().child(avatar) : null, avatar != null ? storage.ref().child(avatar) : null,
json['tarifa'] ?? 0, json['tarifa'] ?? 0,
json['phoneNumber'], json['phoneNumber'],
json['token'],
); );
} catch (e) { } catch (e) {
print('XD user $e'); print('XD user $e');
return UserModel('', '', '', null, null, 0, '', ''); return UserModel('', '', '', null, null, 0, '');
} }
} }
@@ -45,7 +43,7 @@ class UserModel {
return fromJson(data, uid); return fromJson(data, uid);
} catch (e) { } catch (e) {
print('Error getting user: $e'); print('Error getting user: $e');
return UserModel('', '', '', null, null, 0, '', ''); return UserModel('', '', '', null, null, 0, '');
} }
} }
} }
-9
View File
@@ -141,18 +141,9 @@ class _ServiceScreenState extends State<ServiceScreen> {
@override @override
void initState() { void initState() {
super.initState(); super.initState();
final String token = '50002';
final userRef = FirebaseFirestore.instance.collection('users').doc(uid); final userRef = FirebaseFirestore.instance.collection('users').doc(uid);
userRef.get().then((docSnapshot) {
if (docSnapshot.exists) {
userRef.update({'token': token});
} else {
userRef.set({'token': token}, SetOptions(merge: true));
}
});
if (user == null) { if (user == null) {
UserModel.getUser(uid.toString()).then( UserModel.getUser(uid.toString()).then(
(UserModel s) => setState(() => user = s), (UserModel s) => setState(() => user = s),
+1
View File
@@ -63,6 +63,7 @@ dependencies:
firebase_messaging: ^14.5.0 firebase_messaging: ^14.5.0
flutter_local_notifications: ^14.0.0+1 flutter_local_notifications: ^14.0.0+1
responsive_builder: ^0.7.0 responsive_builder: ^0.7.0
universal_html: ^2.2.3
dev_dependencies: dev_dependencies:
flutter_test: flutter_test: