import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:firebase_storage/firebase_storage.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'; 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/event_model.dart'; import 'package:prosappco/src/models/scores_model.dart'; import 'package:prosappco/src/models/user_model.dart'; import 'package:prosappco/src/screens/chat.dart'; import 'package:url_launcher/url_launcher.dart'; import 'package:community_material_icon/community_material_icon.dart'; class CitaScreen extends StatefulWidget { final Event evento; const CitaScreen({super.key, required this.evento}); @override State createState() => _CitaScreenState(); } class _CitaScreenState extends State { final uid = AuthenticationRepository.instance.getCurrentUserUid(); UserModel? user; @override String nombre = ''; Reference? ref_photo; ScoresModel? scoresModel; final phoneNumber = '+573022548060'; Future _openMap(double lat, double lng) async { final Uri _url = Uri.parse('https://www.google.com/maps/search/?api=1&query=$lat,$lng'); if (!await launchUrl(_url)) { print('hola'); throw Exception('Could not launch $_url'); } } Future _sendWhatsapp() async { final whatsappUrl = 'https://wa.me/$phoneNumber?text=${Uri.parse('Hola! me contactaste por Prossapp')}'; if (!await launch(whatsappUrl)) { throw Exception('Could not launch $whatsappUrl'); } } @override void initState() { super.initState(); if (scoresModel == null) { if (uid != widget.evento.userId) { ScoresModel.scoreTo(widget.evento.userId, false, false).then( (ScoresModel s) => setState(() { scoresModel = s; }), ); } else { ScoresModel.scoreTo(widget.evento.professionalId, true, false).then( (ScoresModel s) => setState(() { scoresModel = s; }), ); } } } @override Widget build(BuildContext context) { if (nombre == '') { if (uid != widget.evento.userId) { UserModel.getUser(widget.evento.userId).then((value) { setState(() { nombre = value.name; ref_photo = value.photo; }); }); } else { UserModel.getUser(widget.evento.professionalId).then((value) { setState(() { nombre = value.name; ref_photo = value.photo; }); }); } } return Scaffold( appBar: PopAppbar( onPressed: () { Navigator.pop(context); }, label: 'Servicio'), body: Column( children: [ Expanded( child: Column( children: [ ListTile( leading: ReferencePhoto( ref: ref_photo, size: 50, sizeCircle: 50, sizeIcon: 35, ), title: RichText( text: TextSpan( children: [ TextSpan( text: '$nombre, ', style: const TextStyle( color: Colors.black, fontWeight: FontWeight.bold, fontSize: 16, ), ), TextSpan( text: '${DateFormat('dd MMM', 'es').format(DateTime.parse(widget.evento.day))} ${widget.evento.range1Hour1}', style: const TextStyle( color: Colors.grey, fontSize: 16, ), ), ], ), ), subtitle: Row( children: [ RatingBar.builder( initialRating: scoresModel?.average ?? 0, minRating: 1, direction: Axis.horizontal, allowHalfRating: true, itemCount: 5, itemSize: 25, maxRating: 5, itemPadding: const EdgeInsets.symmetric(horizontal: 0), itemBuilder: (context, _) => const Icon( Icons.star, color: Color(0xFF2BA4EC), ), onRatingUpdate: (rating) {}, ignoreGestures: true, ), const SizedBox(width: 5), Text( '(${scoresModel?.total.toString()}) ${scoresModel?.average.toString()}'), ], ), ), Container( margin: const EdgeInsets.only( left: 40, right: 40, top: 20, bottom: 20), padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 15), decoration: BoxDecoration( color: const Color(0xFFD6F4FF), borderRadius: BorderRadius.circular(20), boxShadow: [ BoxShadow( color: Colors.grey.withOpacity(0.5), spreadRadius: 1, blurRadius: 5, offset: const Offset(1, 3), ), ], ), child: Row( children: [ const Icon( Icons.error_outline, size: 27, color: Colors.black54, ), const SizedBox(width: 15), widget.evento.ubicacion != 'sitio' ? const Text( 'Servicio a domicilio.', style: TextStyle(color: Colors.black, fontSize: 14), ) : const Text( 'Servicio en su sitio / consultorio', style: TextStyle(color: Colors.black, fontSize: 14), ), ], ), ), Text( textAlign: TextAlign.center, '" ${widget.evento.description} "', style: const TextStyle( color: Colors.grey, fontStyle: FontStyle.italic), ), const Padding( padding: EdgeInsets.symmetric(vertical: 20), child: Text( 'Medios de comunicación con el usuario.', style: TextStyle(color: Color(0xFF2BA4EC)), ), ), Row( children: [ const Expanded(child: SizedBox()), ElevatedButton( onPressed: () => launch("tel:+573163225944"), style: ElevatedButton.styleFrom( foregroundColor: const Color(0xFF2BA4EC), backgroundColor: Colors.white, shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(50), side: const BorderSide( color: Color(0xFF2BA4EC), width: 2, ), ), ), child: const Padding( padding: EdgeInsets.symmetric(vertical: 18, horizontal: 0), child: Icon( Icons.phone_android, size: 30, color: Color(0xFF2BA4EC), ), ), ), 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')); Navigator.push( context, CupertinoPageRoute( builder: (BuildContext context) { return ChatScreen(evento: widget.evento); }, ), ); }, style: ElevatedButton.styleFrom( foregroundColor: const Color(0xFF2BA4EC), backgroundColor: Colors.white, shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(50), side: const BorderSide( color: Color(0xFF2BA4EC), width: 2, ), ), ), child: const Padding( padding: EdgeInsets.symmetric(vertical: 18, horizontal: 0), child: Icon( Icons.message, size: 30, color: Color(0xFF2BA4EC), ), ), ), const SizedBox(width: 20), ElevatedButton( onPressed: () { _sendWhatsapp(); }, style: ElevatedButton.styleFrom( foregroundColor: const Color(0xFF2BA4EC), backgroundColor: Colors.white, shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(50), side: const BorderSide( color: Color(0xFF2BA4EC), width: 2, ), ), ), child: const Padding( padding: EdgeInsets.symmetric(vertical: 18, horizontal: 0), child: Icon( CommunityMaterialIcons.whatsapp, size: 30, color: Color(0xFF2BA4EC), ), ), ), const Expanded(child: SizedBox()), ], ), widget.evento.ubicacion == 'sitio' ? const SizedBox() : Padding( padding: const EdgeInsets.only(top: 40), child: Row( mainAxisAlignment: MainAxisAlignment.center, children: [ ElevatedButton( onPressed: () { _openMap(widget.evento.latitud!, widget.evento.longitud!); }, style: ElevatedButton.styleFrom( foregroundColor: const Color(0xFF2BA4EC), backgroundColor: const Color(0xFF2BA4EC), shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(50), side: const BorderSide( color: Color(0xFF2BA4EC), width: 2, ), ), ), child: const Padding( padding: EdgeInsets.symmetric( vertical: 18, horizontal: 0), child: Icon( Icons.near_me, size: 30, color: Color(0xFFFFFFFF), ), ), ), const SizedBox(width: 20), SizedBox( width: 200, child: Text('${widget.evento.address}')) ], ), ), ], ), ), widget.evento.status == 'pendiendo' ? Padding( padding: const EdgeInsets.only(bottom: 30), child: Column( children: [ Padding( padding: const EdgeInsets.only(bottom: 20), child: ElevatedButton( onPressed: () { FirebaseFirestore.instance .collection("services") .doc('${widget.evento.id}') .update({"status": "aprobado"}).then((value) { Navigator.pushReplacementNamed( context, '/solicitud'); }); }, style: ElevatedButton.styleFrom( backgroundColor: const Color(0xFF2BA4EC), shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(50), ), elevation: 0, minimumSize: const Size(230, 60), ), child: const Text( 'Aceptar', style: TextStyle( color: Colors.white, fontWeight: FontWeight.bold, fontSize: 18, ), ), ), ), ElevatedButton( onPressed: () { FirebaseFirestore.instance .collection("services") .doc('${widget.evento.id}') .update({"status": "denegado"}).then((value) { Navigator.pushReplacementNamed( context, '/solicitud'); }); }, style: ElevatedButton.styleFrom( backgroundColor: const Color(0xFFEC2B2B), shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(50), ), elevation: 0, minimumSize: const Size(230, 60), ), child: const Text( 'Cancelar servicio', style: TextStyle( color: Colors.white, fontWeight: FontWeight.bold, fontSize: 18, ), ), ), ], ), ) : const SizedBox(), ], ), ); } }