prosapp changes

This commit is contained in:
Juan Felipe Duarte
2023-06-23 21:55:10 -05:00
parent 90ec1293ea
commit e994230631
14 changed files with 292 additions and 173 deletions
-21
View File
@@ -8,7 +8,6 @@ import 'package:prosappco/src/components/photo_view.dart';
import 'package:prosappco/src/models/scores_model.dart';
import 'package:prosappco/src/models/user_model.dart';
import 'package:prosappco/src/screens/configuracion.dart';
import 'package:prosappco/src/screens/local_notification.dart';
import 'package:prosappco/src/screens/messages_user.dart';
import 'package:prosappco/src/screens/professional_profile_web.dart';
import 'package:prosappco/src/screens/profile.dart';
@@ -233,26 +232,6 @@ class _DrawerMenuState extends State<DrawerMenu> {
style: TextStyle(fontSize: 15),
),
),
ListTile(
onTap: () {
Navigator.push(
context,
CupertinoPageRoute(
builder: (BuildContext context) {
return const LocalNotificationScreen();
},
),
);
},
leading: const Icon(
Icons.notification_add_outlined,
color: Colors.black,
),
title: const Text(
'Notificación',
style: TextStyle(fontSize: 15),
),
),
Builder(builder: (BuildContext context) {
return ListTile(
onTap: () {
+153 -71
View File
@@ -1,3 +1,5 @@
import 'dart:convert';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
@@ -10,6 +12,7 @@ import 'package:prosappco/src/models/event_model.dart';
import 'package:prosappco/src/models/user_model.dart';
import 'package:prosappco/src/screens/professional.dart';
import 'package:prosappco/src/screens/professional_info.dart';
import 'package:http/http.dart' as http;
class ChatScreen extends StatefulWidget {
final String? eventoId;
@@ -26,6 +29,40 @@ class _ChatScreenState extends State<ChatScreen> {
Professional? professional;
bool pro = false;
Future<void> sendPushNotification(String token) async {
try {
http.Response response = await http.post(
Uri.parse('https://fcm.googleapis.com/fcm/send'),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
'Authorization':
'key=AAAAORdR-xU:APA91bF_wblg86jHAC-uexrXPHavYRlk5wge1Gf46m56V4J2D2L37Cp_hf46JZUzpvsWPSpqc5ewHelKI9LTifUG_s2mciMI6e5VLKo7E1R8btbNo7iaM9do2ctoyHKUm1atlZBdKaN2',
},
body: jsonEncode(
<String, dynamic>{
'notification': <String, dynamic>{
'body': 'Tienes un nuevo mensaje',
'title': 'Nuevo mensaje',
},
'priority': 'high',
'data': <String, dynamic>{
'click_action': 'FLUTTER_NOTIFICATION_CLICK',
'id': '1',
'status': 'done'
},
'to': token,
},
),
);
print(token);
print(response);
response;
} catch (e) {
print('error al enviar notificacion $e');
}
}
@override
void initState() {
super.initState();
@@ -141,7 +178,7 @@ class _ChatScreenState extends State<ChatScreen> {
filled: true,
fillColor: Colors.grey[200],
),
onFieldSubmitted: (value) {
onFieldSubmitted: (value) async {
String muestra = _textController.text.trim();
if (muestra.isNotEmpty) {
final nuevoMensaje = MessageModel(
@@ -163,8 +200,28 @@ class _ChatScreenState extends State<ChatScreen> {
'message': FieldValue.arrayUnion([nuevoMensajeMap])
});
if (user?.token != '') {
final mensajesQuerySnapshot =
await FirebaseFirestore.instance
.collection('chats')
.doc(widget.eventoId)
.get();
final mensajes =
mensajesQuerySnapshot.data()?['message'];
if (mensajes != null && mensajes.isNotEmpty) {
final ultimoMensaje = mensajes.last;
final ultimoMensajeUser = ultimoMensaje['user'];
if (ultimoMensajeUser == uid) {
// El último mensaje fue enviado por ti, no se envía la notificación
} else {
sendPushNotification(user!.token!);
}
} else {
sendPushNotification(user!.token!);
}
}
_textController.clear();
} else {}
}
},
),
),
@@ -192,8 +249,29 @@ class _ChatScreenState extends State<ChatScreen> {
'message': FieldValue.arrayUnion([nuevoMensajeMap])
});
if (user?.token != '') {
final mensajesQuerySnapshot = await FirebaseFirestore
.instance
.collection('chats')
.doc(widget.eventoId)
.get();
final mensajes =
mensajesQuerySnapshot.data()?['message'];
if (mensajes != null && mensajes.isNotEmpty) {
final ultimoMensaje = mensajes.last;
final ultimoMensajeUser = ultimoMensaje['user'];
if (ultimoMensajeUser == uid) {
// El último mensaje fue enviado por ti, no se envía la notificación
} else {
sendPushNotification(user!.token!);
}
} else {
sendPushNotification(user!.token!);
}
}
_textController.clear();
} else {}
}
},
child: Container(
height: 50,
@@ -233,81 +311,85 @@ class _ChatScreenState extends State<ChatScreen> {
final data = snapshot.data!;
final chat = ChatModel.fromDocumentSnapshot(data);
return Column(children: [
...chat.messages.map(
(e) => uid != e.user
? ListTile(
title: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
margin: const EdgeInsets.only(right: 60),
padding: const EdgeInsets.symmetric(
vertical: 10, horizontal: 16),
decoration: BoxDecoration(
color: Colors.grey.shade200,
borderRadius: const BorderRadius.only(
topRight: Radius.circular(20),
bottomLeft: Radius.circular(20),
bottomRight: Radius.circular(20),
return Column(
children: [
...chat.messages.map(
(e) => uid != e.user
? ListTile(
title: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
margin: const EdgeInsets.only(right: 60),
padding: const EdgeInsets.symmetric(
vertical: 10, horizontal: 16),
decoration: BoxDecoration(
color: Colors.grey.shade200,
borderRadius: const BorderRadius.only(
topRight: Radius.circular(20),
bottomLeft: Radius.circular(20),
bottomRight: Radius.circular(20),
),
),
child: Text(
e.content,
style: const TextStyle(fontSize: 16),
),
),
child: Text(
e.content,
style: const TextStyle(fontSize: 16),
),
),
const SizedBox(width: 5),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 10),
child: Text(
DateFormat('h:mm a').format(e.timestamp),
style: const TextStyle(
color: Colors.grey, fontSize: 12),
),
),
],
),
)
: ListTile(
title: Column(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Container(
margin: const EdgeInsets.only(left: 60),
padding: const EdgeInsets.symmetric(
vertical: 10,
horizontal: 16,
),
decoration: const BoxDecoration(
color: Color(0xFFD5EFFF),
borderRadius: BorderRadius.only(
topLeft: Radius.circular(20),
bottomLeft: Radius.circular(20),
bottomRight: Radius.circular(20),
const SizedBox(width: 5),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 10),
child: Text(
DateFormat('h:mm a').format(e.timestamp),
style: const TextStyle(
color: Colors.grey, fontSize: 12),
),
),
child: Text(
e.content,
style: const TextStyle(fontSize: 16),
],
),
)
: ListTile(
title: Column(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Container(
margin: const EdgeInsets.only(left: 60),
padding: const EdgeInsets.symmetric(
vertical: 10,
horizontal: 16,
),
decoration: const BoxDecoration(
color: Color(0xFFD5EFFF),
borderRadius: BorderRadius.only(
topLeft: Radius.circular(20),
bottomLeft: Radius.circular(20),
bottomRight: Radius.circular(20),
),
),
child: Text(
e.content,
style: const TextStyle(fontSize: 16),
),
),
),
const SizedBox(width: 5),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 10),
child: Text(
DateFormat('h:mm a').format(e.timestamp),
style: const TextStyle(
color: Colors.grey, fontSize: 12),
const SizedBox(width: 5),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 10),
child: Text(
DateFormat('h:mm a').format(e.timestamp),
style: const TextStyle(
color: Colors.grey,
fontSize: 12,
),
),
),
),
],
],
),
),
),
)
]);
)
],
);
},
);
}
-73
View File
@@ -1,73 +0,0 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_dialogs/flutter_dialogs.dart';
import 'package:prosappco/src/components/pop_appbar.dart';
import 'package:prosappco/src/services/local_notifications.dart';
class LocalNotificationScreen extends StatelessWidget {
const LocalNotificationScreen({Key? key}) : super(key: key);
void showCustomDialog(BuildContext context, String title, String content) {
showPlatformDialog(
context: context,
builder: (_) => BasicDialogAlert(
title: Text(title),
content: Text(content),
actions: <Widget>[
BasicDialogAction(
onPressed: () {
Navigator.pop(context);
},
title: const Text('Cerrar'),
),
],
),
);
}
@override
Widget build(BuildContext context) {
if (kIsWeb) {
return Scaffold(
appBar: PopAppbar(
onPressed: () {
Navigator.pop(context);
},
label: 'Notificaciones',
),
body: Center(
child: ElevatedButton(
onPressed: () {
showCustomDialog(
context,
'Nueva notificación!',
'Esta es una notificación de Flutter',
);
},
child: const Text('Lanzar notificación'),
),
),
);
} else {
return Scaffold(
appBar: PopAppbar(
onPressed: () {
Navigator.pop(context);
},
label: 'Notificaciones',
),
body: Center(
child: ElevatedButton(
onPressed: () {
showNotification(
'Nueva notificación!',
'Esta es una notificación de prosapp!',
);
},
child: const Text('Lanzar notificación'),
),
),
);
}
}
}
+2 -2
View File
@@ -69,10 +69,10 @@ class _MessagesScreenState extends State<MessagesScreen> {
size: 55,
sizeCircle: 60,
),
trailing: Column(
trailing: const Column(
children: [
SizedBox(height: 8),
const Icon(
Icon(
Icons.keyboard_arrow_right,
color: Colors.black,
),
@@ -257,10 +257,7 @@ class _ProfessionalProfileWebScreenState
.child('cedula')
.child(random);
final metaData = SettableMetadata(contentType: 'image/jpeg');
// final metaDataImg = SettableMetadata(contentType: 'image/jpeg');
// final metaDataPdf = SettableMetadata(contentType: 'application/pdf');
// final metaDataWord = SettableMetadata(contentType: 'application/msword');
final metaData = SettableMetadata(contentType: 'application/pdf');
final UploadTask uploadTask = ref.putData(imageCedulaBytes!, metaData);
@@ -293,7 +290,7 @@ class _ProfessionalProfileWebScreenState
.child('certificado_profesional')
.child(random);
final metaData = SettableMetadata(contentType: 'image/jpeg');
final metaData = SettableMetadata(contentType: 'application/pdf');
final UploadTask uploadTask =
ref.putData(imageCertificadoBytes!, metaData);
+9
View File
@@ -276,6 +276,15 @@ class _ProfileScreenState extends State<ProfileScreen> {
print('e');
}
try {
await FirebaseFirestore.instance
.collection('users')
.doc(uid)
.update({'email': newEmail});
} catch (e) {
print('e');
}
try {
if (imagen_to_upload == null) {
return;
-1
View File
@@ -1,5 +1,4 @@
import 'dart:convert';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:firebase_storage/firebase_storage.dart';