chat primera face

This commit is contained in:
Juan Felipe Duarte
2023-05-03 17:07:26 -05:00
parent f1571e6374
commit 1a0e33328e
16 changed files with 785 additions and 95 deletions
+37
View File
@@ -0,0 +1,37 @@
import 'package:cloud_firestore/cloud_firestore.dart';
class ChatModel {
List<MessageModel> messages;
ChatModel({required this.messages});
static ChatModel fromDocumentSnapshot(
DocumentSnapshot<Map<String, dynamic>> snapshot) {
try {
List<MessageModel> messages = [];
List<dynamic> messagesData = snapshot.get('message') ?? [];
for (var data in messagesData) {
messages.add(MessageModel(
user: data['user'] ?? '',
content: data['content'] ?? '',
timestamp: (data['timestamp'] as Timestamp).toDate(),
));
}
return ChatModel(messages: messages);
} catch (e) {
print('error $e');
return ChatModel(messages: []);
}
}
}
class MessageModel {
String user;
String content;
DateTime timestamp;
MessageModel(
{required this.user, required this.content, required this.timestamp});
}
+32 -2
View File
@@ -16,6 +16,7 @@ class EventoService {
String address,
double latitude,
double longitude,
String status,
) async {
try {
DateTime ahora = DateTime.now();
@@ -33,6 +34,7 @@ class EventoService {
'address': address,
'latitude': latitude,
'longitude': longitude,
'status': status,
'Timestamp': ahora
}).then((value) {
FirebaseFirestore.instance.collection('users').doc(uid).update({
@@ -72,17 +74,18 @@ Future<List<Event>> getByProId(String day) async {
}
}
Future<List<Event>> getByProIdAll() async {
Future<List<Event>> getByProIdAll(String state1, String state2) async {
try {
var snapshot = await FirebaseFirestore.instance
.collection('services')
.where('professional_id', isEqualTo: uid)
.get();
.where('status', whereIn: [state1, state2]).get();
List<Event> eventos = [];
for (var element in snapshot.docs) {
final event = Event.fromJson(element.data());
event.scoresModel = await ScoresModel.scoreTo(event.userId, false, false);
event.id = element.id;
eventos.add(event);
}
print('eventos $eventos');
@@ -94,6 +97,7 @@ Future<List<Event>> getByProIdAll() async {
}
class Event {
String? id;
String title;
String? description;
String day;
@@ -105,9 +109,11 @@ class Event {
String? address;
double? longitud;
double? latitud;
String status;
ScoresModel? scoresModel;
Event({
this.id,
required this.title,
this.description,
required this.day,
@@ -119,10 +125,12 @@ class Event {
this.address,
this.longitud,
this.latitud,
this.status = 'pendiente',
});
factory Event.fromJson(Map<String, dynamic> json) {
return Event(
id: json['id'] ?? '',
title: json['title'],
description: json['description'],
day: json['day'],
@@ -134,6 +142,7 @@ class Event {
address: json['address'] ?? '',
longitud: json['longitude'] ?? 0,
latitud: json['latitude'] ?? 0,
status: json['status'],
);
}
@@ -170,4 +179,25 @@ class Event {
return [];
}
}
static Future<List<Event>> getEventsAllByIdStatus(
String uid, String state) async {
try {
var snapshot = await FirebaseFirestore.instance
.collection('services')
.where('professional_id', isEqualTo: uid)
.where('status', isEqualTo: state)
.get();
List<Event> eventos = [];
for (var element in snapshot.docs) {
eventos.add(Event.fromJson(element.data()));
}
print('eventos $eventos');
return eventos;
} catch (e) {
print('Error getByProId $e');
return [];
}
}
}
+33
View File
@@ -0,0 +1,33 @@
import 'package:cloud_firestore/cloud_firestore.dart';
class SettingModel {
final bool domicilios;
SettingModel(this.domicilios);
static Future<SettingModel> fromJson(Map<String, dynamic> json) async {
try {
if (json == null) return SettingModel(false);
return SettingModel(json['habilitado']);
} catch (e) {
print('Error settings: $e');
return SettingModel(false);
}
}
static Future<SettingModel> getDomiciliosSettings() async {
try {
final DocumentSnapshot<Map<String, dynamic>> snapshot =
await FirebaseFirestore.instance
.collection('settings')
.doc('domicilios')
.get();
final Map<String, dynamic>? data = snapshot.data();
return fromJson(data!);
} catch (e) {
print('Error getting settings: $e');
return SettingModel(false);
}
}
}