fix chat
This commit is contained in:
@@ -28,19 +28,19 @@ class ChatModel {
|
||||
messages.add(MessageModel(
|
||||
user: data['user'] ?? '',
|
||||
content: data['content'] ?? '',
|
||||
timestamp: (data['timestamp'] as Timestamp).toDate(),
|
||||
timestamp: (data['timestamp'] ?? '' as Timestamp).toDate(),
|
||||
));
|
||||
}
|
||||
|
||||
return ChatModel(
|
||||
messages: messages,
|
||||
professional_id: snapshot.get('professional_id'),
|
||||
user_id: snapshot.get('user_id'),
|
||||
professional_id: snapshot.get('professional_id') ?? '',
|
||||
user_id: snapshot.get('user_id') ?? '',
|
||||
user: fillUserModel
|
||||
? await UserModel.getUser(snapshot.get('user_id'))
|
||||
? await UserModel.getUser(snapshot.get('user_id') ?? '')
|
||||
: null,
|
||||
professional: fillUserModel
|
||||
? await UserModel.getUser(snapshot.get('professional_id'))
|
||||
? await UserModel.getUser(snapshot.get('professional_id') ?? '')
|
||||
: null,
|
||||
id: snapshot.id);
|
||||
} catch (e) {
|
||||
|
||||
@@ -58,12 +58,14 @@ Future<List<Event>> getByProId(String day) async {
|
||||
.collection('services')
|
||||
.where('professional_id', isEqualTo: uid)
|
||||
.where('day', isEqualTo: day.toString())
|
||||
.where('status', isEqualTo: 'aprobado')
|
||||
.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');
|
||||
|
||||
+36
-16
@@ -236,23 +236,43 @@ class _CitaScreenState extends State<CitaScreen> {
|
||||
const SizedBox(width: 20),
|
||||
ElevatedButton(
|
||||
onPressed: () async {
|
||||
await FirebaseFirestore.instance
|
||||
.collection('chats')
|
||||
.doc(widget.evento.id)
|
||||
.set({
|
||||
'professional_id': widget.evento.professionalId,
|
||||
'user_id': widget.evento.userId
|
||||
}, SetOptions(merge: true)).catchError((error) =>
|
||||
print('Error al crear el documento: $error'));
|
||||
if (widget.evento.status != 'pendiente') {
|
||||
await FirebaseFirestore.instance
|
||||
.collection('chats')
|
||||
.doc(widget.evento.id)
|
||||
.set({
|
||||
'professional_id': widget.evento.professionalId,
|
||||
'user_id': widget.evento.userId,
|
||||
'message': [],
|
||||
}, SetOptions(merge: true)).catchError((error) =>
|
||||
print('Error al crear el documento: $error'));
|
||||
|
||||
Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (BuildContext context) {
|
||||
return ChatScreen(eventoId: widget.evento.id);
|
||||
},
|
||||
),
|
||||
);
|
||||
Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (BuildContext context) {
|
||||
return ChatScreen(eventoId: widget.evento.id);
|
||||
},
|
||||
),
|
||||
);
|
||||
} else {
|
||||
final snackBar = SnackBar(
|
||||
backgroundColor: Colors.blue,
|
||||
content: const Text(
|
||||
'Primero acepta la solicitud',
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
elevation: 8.0,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(10.0),
|
||||
),
|
||||
);
|
||||
|
||||
ScaffoldMessenger.of(context).showSnackBar(snackBar);
|
||||
}
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
foregroundColor: const Color(0xFF2BA4EC),
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
import 'package:community_material_icon/community_material_icon.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:prosappco/src/authentication/authentication_repository.dart';
|
||||
import 'package:prosappco/src/components/photo_view.dart';
|
||||
import 'package:prosappco/src/components/pop_appbar.dart';
|
||||
import 'package:prosappco/src/models/chat_model.dart';
|
||||
import 'package:prosappco/src/models/event_model.dart';
|
||||
import 'package:prosappco/src/models/user_model.dart';
|
||||
import 'package:prosappco/src/screens/chat.dart';
|
||||
|
||||
class MessagesScreen extends StatefulWidget {
|
||||
@@ -55,52 +53,47 @@ class _MessagesScreenState extends State<MessagesScreen> {
|
||||
child: ListView.builder(
|
||||
itemCount: list.length,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
final user = list[index].user;
|
||||
final lastMsg = list[index].messages.last;
|
||||
|
||||
return ListTile(
|
||||
title: Text(
|
||||
(user?.name ?? ''),
|
||||
),
|
||||
subtitle: Text(
|
||||
'" ${lastMsg.content} "',
|
||||
style: const TextStyle(fontStyle: FontStyle.italic),
|
||||
),
|
||||
leading: ReferencePhoto(
|
||||
ref: user?.photo,
|
||||
size: 55,
|
||||
sizeCircle: 60,
|
||||
),
|
||||
trailing: Column(
|
||||
children: [
|
||||
SizedBox(height: 8),
|
||||
const Icon(
|
||||
Icons.keyboard_arrow_right,
|
||||
color: Colors.black,
|
||||
),
|
||||
Text(
|
||||
lastMsg.timestamp.day >= DateTime.now().day
|
||||
? DateFormat('h:mm a').format(lastMsg.timestamp)
|
||||
: DateFormat('dd/MM/yyyy', 'es')
|
||||
.format(lastMsg.timestamp),
|
||||
style:
|
||||
const TextStyle(color: Colors.grey, fontSize: 12),
|
||||
)
|
||||
],
|
||||
),
|
||||
onTap: () {
|
||||
Event.getEventById(list[index].id).then((value) {
|
||||
Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (BuildContext context) {
|
||||
return ChatScreen(eventoId: list[index].id);
|
||||
},
|
||||
if (list[index].messages.isNotEmpty) {
|
||||
final user = list[index].user;
|
||||
final lastMsg = list[index].messages.last;
|
||||
return ListTile(
|
||||
title: Text(
|
||||
(user?.name ?? ''),
|
||||
),
|
||||
subtitle: Text(
|
||||
'" ${lastMsg.content} "',
|
||||
style: const TextStyle(fontStyle: FontStyle.italic),
|
||||
),
|
||||
leading: ReferencePhoto(
|
||||
ref: user?.photo,
|
||||
size: 55,
|
||||
sizeCircle: 60,
|
||||
),
|
||||
trailing: Column(
|
||||
children: [
|
||||
SizedBox(height: 8),
|
||||
const Icon(
|
||||
Icons.keyboard_arrow_right,
|
||||
color: Colors.black,
|
||||
),
|
||||
);
|
||||
});
|
||||
},
|
||||
);
|
||||
],
|
||||
),
|
||||
onTap: () {
|
||||
Event.getEventById(list[index].id).then((value) {
|
||||
Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (BuildContext context) {
|
||||
return ChatScreen(eventoId: list[index].id);
|
||||
},
|
||||
),
|
||||
);
|
||||
});
|
||||
},
|
||||
);
|
||||
} else {
|
||||
return const SizedBox();
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
@@ -54,52 +54,55 @@ class _MessagesUserScreenState extends State<MessagesUserScreen> {
|
||||
child: ListView.builder(
|
||||
itemCount: list.length,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
final pro = list[index].professional;
|
||||
final lastMsg = list[index].messages.last;
|
||||
|
||||
return ListTile(
|
||||
title: Text(
|
||||
(pro?.name ?? ''),
|
||||
),
|
||||
subtitle: Text(
|
||||
'" ${lastMsg.content} "',
|
||||
style: const TextStyle(fontStyle: FontStyle.italic),
|
||||
),
|
||||
leading: ReferencePhoto(
|
||||
ref: pro?.photo,
|
||||
size: 55,
|
||||
sizeCircle: 60,
|
||||
),
|
||||
trailing: Column(
|
||||
children: [
|
||||
SizedBox(height: 8),
|
||||
const Icon(
|
||||
Icons.keyboard_arrow_right,
|
||||
color: Colors.black,
|
||||
),
|
||||
Text(
|
||||
lastMsg.timestamp.day >= DateTime.now().day
|
||||
? DateFormat('h:mm a').format(lastMsg.timestamp)
|
||||
: DateFormat('dd/MM/yyyy', 'es')
|
||||
.format(lastMsg.timestamp),
|
||||
style:
|
||||
const TextStyle(color: Colors.grey, fontSize: 12),
|
||||
)
|
||||
],
|
||||
),
|
||||
onTap: () {
|
||||
Event.getEventById(list[index].id).then((value) {
|
||||
Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (BuildContext context) {
|
||||
return ChatScreen(eventoId: list[index].id);
|
||||
},
|
||||
if (list[index].messages.isNotEmpty) {
|
||||
final pro = list[index].professional;
|
||||
final lastMsg = list[index].messages.last;
|
||||
return ListTile(
|
||||
title: Text(
|
||||
(pro?.name ?? ''),
|
||||
),
|
||||
subtitle: Text(
|
||||
'" ${lastMsg.content} "',
|
||||
style: const TextStyle(fontStyle: FontStyle.italic),
|
||||
),
|
||||
leading: ReferencePhoto(
|
||||
ref: pro?.photo,
|
||||
size: 55,
|
||||
sizeCircle: 60,
|
||||
),
|
||||
trailing: Column(
|
||||
children: [
|
||||
SizedBox(height: 8),
|
||||
const Icon(
|
||||
Icons.keyboard_arrow_right,
|
||||
color: Colors.black,
|
||||
),
|
||||
);
|
||||
});
|
||||
},
|
||||
);
|
||||
Text(
|
||||
lastMsg.timestamp.day >= DateTime.now().day
|
||||
? DateFormat('h:mm a').format(lastMsg.timestamp)
|
||||
: DateFormat('dd/MM/yyyy', 'es')
|
||||
.format(lastMsg.timestamp),
|
||||
style:
|
||||
const TextStyle(color: Colors.grey, fontSize: 12),
|
||||
)
|
||||
],
|
||||
),
|
||||
onTap: () {
|
||||
Event.getEventById(list[index].id).then((value) {
|
||||
Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (BuildContext context) {
|
||||
return ChatScreen(eventoId: list[index].id);
|
||||
},
|
||||
),
|
||||
);
|
||||
});
|
||||
},
|
||||
);
|
||||
} else {
|
||||
return const SizedBox();
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
@@ -5,7 +5,6 @@ import 'package:intl/intl.dart';
|
||||
import 'package:prosappco/src/components/drawer_professional.dart';
|
||||
import 'package:prosappco/src/components/pop_appbar.dart';
|
||||
import 'package:prosappco/src/models/event_model.dart';
|
||||
import 'package:prosappco/src/screens/cita.dart';
|
||||
|
||||
class MyServicesProScreen extends StatefulWidget {
|
||||
MyServicesProScreen({super.key});
|
||||
@@ -75,14 +74,16 @@ class _MyServicesProScreenState extends State<MyServicesProScreen> {
|
||||
? Colors.blue[100]
|
||||
: Colors.red[100],
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (BuildContext context) {
|
||||
return CitaScreen(evento: event);
|
||||
},
|
||||
),
|
||||
);
|
||||
print(event.id);
|
||||
|
||||
// Navigator.push(
|
||||
// context,
|
||||
// CupertinoPageRoute(
|
||||
// builder: (BuildContext context) {
|
||||
// return CitaScreen(evento: event);
|
||||
// },
|
||||
// ),
|
||||
// );
|
||||
},
|
||||
leading: event.status == 'aprobado'
|
||||
? const Icon(
|
||||
|
||||
@@ -409,6 +409,8 @@ class _ServiceScreenState extends State<ServiceScreen> {
|
||||
_profesionalController.text =
|
||||
profesional.name.toString();
|
||||
|
||||
professionalId = profesional.id;
|
||||
|
||||
professionalUbicacion =
|
||||
profesional.ubicacion;
|
||||
|
||||
@@ -440,8 +442,6 @@ class _ServiceScreenState extends State<ServiceScreen> {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
professionalId = profesional.id;
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -579,7 +579,7 @@ class _ServiceScreenState extends State<ServiceScreen> {
|
||||
: professionalLongitude,
|
||||
'pendiente')
|
||||
.then((value) {
|
||||
Navigator.push(
|
||||
Navigator.pushReplacement(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (BuildContext context) {
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_rating_bar/flutter_rating_bar.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
@@ -7,6 +10,9 @@ import 'package:prosappco/src/components/pop_appbar.dart';
|
||||
import 'package:prosappco/src/models/event_model.dart';
|
||||
import 'package:prosappco/src/models/scores_model.dart';
|
||||
import 'package:prosappco/src/models/user_model.dart';
|
||||
import 'package:prosappco/src/screens/profile.dart';
|
||||
import 'package:prosappco/src/screens/profile_pro.dart';
|
||||
import 'package:prosappco/src/screens/service.dart';
|
||||
|
||||
class ServiceAfterScreen extends StatefulWidget {
|
||||
var eventoId;
|
||||
@@ -47,8 +53,18 @@ class _ServiceAfterScreenState extends State<ServiceAfterScreen> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar:
|
||||
PopAppbar(onPressed: () => Navigator.pop(context), label: 'Servicio'),
|
||||
appBar: PopAppbar(
|
||||
onPressed: () {
|
||||
Navigator.pushReplacement(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (BuildContext context) {
|
||||
return const ServiceScreen();
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
label: 'Servicio'),
|
||||
body: Column(
|
||||
children: [
|
||||
ListTile(
|
||||
|
||||
Reference in New Issue
Block a user