From 34c60af6883be1ed79d8d0e808f198e367aad5f8 Mon Sep 17 00:00:00 2001 From: Felipe Date: Fri, 12 Apr 2024 12:12:32 -0500 Subject: [PATCH] fix pantalla servicio --- .../service/professional_service_screen.dart | 330 ++++++++++++---- lib/screens/service/user_service_screen.dart | 369 +++++++++++++----- 2 files changed, 514 insertions(+), 185 deletions(-) diff --git a/lib/screens/service/professional_service_screen.dart b/lib/screens/service/professional_service_screen.dart index ad08b3a..ed65892 100644 --- a/lib/screens/service/professional_service_screen.dart +++ b/lib/screens/service/professional_service_screen.dart @@ -1,3 +1,4 @@ +import 'package:community_material_icon/community_material_icon.dart'; import 'package:firebase_auth/firebase_auth.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; @@ -9,6 +10,7 @@ import 'package:prosappco/blocs/service_bloc/service_bloc.dart'; import 'package:prosappco/components/general_secondary_button.dart'; import 'package:service_repository/service_repository.dart'; import 'package:setting_repository/setting_repository.dart'; +import 'package:url_launcher/url_launcher.dart'; import 'package:user_repository/user_repository.dart'; class ProfessionalServiceScreen extends StatefulWidget { @@ -166,25 +168,27 @@ class _ProfessionalServiceScreenState extends State { ], ), ), - ListTile( - leading: const Icon(Icons.near_me), - title: Text( - service.address, - style: TextStyle( - fontSize: 15, - color: Colors.grey[600], - ), - ), - subtitle: service.aditionalAddress.isEmpty - ? null - : Text( - service.aditionalAddress, - style: TextStyle( - fontSize: 15, - color: Colors.grey[600], - ), - ), - ), + customMapButton(service), + + // ListTile( + // leading: const Icon(Icons.near_me), + // title: Text( + // service.address, + // style: TextStyle( + // fontSize: 15, + // color: Colors.grey[600], + // ), + // ), + // subtitle: service.aditionalAddress.isEmpty + // ? null + // : Text( + // service.aditionalAddress, + // style: TextStyle( + // fontSize: 15, + // color: Colors.grey[600], + // ), + // ), + // ), service.description.isEmpty ? const SizedBox() : Container( @@ -201,7 +205,9 @@ class _ProfessionalServiceScreenState extends State { ), ), ), - const SizedBox(height: 65), + const SizedBox(height: 20), + customActionButtons(service, userInfo), + const SizedBox(height: 60), customMessageStatus(service), const SizedBox(height: 20), ], @@ -236,37 +242,207 @@ class _ProfessionalServiceScreenState extends State { ); } - Widget customMessageStatus(ServiceEntity service) { - if (service.status == ServiceStatus.acepted) { - return Stack( - alignment: AlignmentDirectional.topCenter, - clipBehavior: Clip.none, + Widget customActionButtons(ServiceEntity service, MyUser user) { + if (service.status == ServiceStatus.acepted || + service.status == ServiceStatus.active) { + return Wrap( + alignment: WrapAlignment.center, + spacing: 15, children: [ - Card( - color: Colors.green.shade50, - child: const Padding( - padding: EdgeInsets.fromLTRB(32, 56, 32, 32), - child: Text( - 'Aceptado', - style: TextStyle(fontSize: 32, color: Colors.green), + Visibility( + visible: user.phone == null ? false : true, + child: ElevatedButton( + onPressed: () => launch("tel:${user.phone}"), + style: ElevatedButton.styleFrom( + foregroundColor: const Color(0xFF2BA4EC), + backgroundColor: Colors.white, + shape: const CircleBorder( + side: BorderSide( + color: Color(0xFF2BA4EC), + width: 2, + ), + ), + ), + child: const Padding( + padding: EdgeInsets.symmetric(vertical: 20, horizontal: 0), + child: Icon( + Icons.phone_android, + size: 30, + color: Color(0xFF2BA4EC), + ), ), ), ), - Positioned( - top: -40, - child: Container( - padding: const EdgeInsets.all(16), - decoration: BoxDecoration( - color: Colors.white, - border: Border.all(color: Colors.green.shade50, width: 4), - shape: BoxShape.circle, + ElevatedButton( + onPressed: () {}, + style: ElevatedButton.styleFrom( + foregroundColor: const Color(0xFF2BA4EC), + backgroundColor: Colors.white, + shape: const CircleBorder( + side: BorderSide( + color: Color(0xFF2BA4EC), + width: 2, + ), ), - child: const Icon(Icons.check, color: Colors.green, size: 48), ), - ) + child: const Padding( + padding: EdgeInsets.symmetric(vertical: 20, horizontal: 0), + child: Icon( + Icons.message, + size: 30, + color: Color(0xFF2BA4EC), + ), + ), + ), + Visibility( + visible: user.phone == null ? false : true, + child: ElevatedButton( + onPressed: () async { + final whatsappUrl = + 'https://wa.me/${user.phone}?text=${Uri.parse('Hola! me contactaste por Prossapp')}'; + if (!await launch(whatsappUrl)) { + throw Exception('Could not launch $whatsappUrl'); + } + }, + style: ElevatedButton.styleFrom( + foregroundColor: const Color(0xFF2BA4EC), + backgroundColor: Colors.white, + shape: const CircleBorder( + side: BorderSide( + color: Color(0xFF2BA4EC), + width: 2, + ), + ), + ), + child: const Padding( + padding: EdgeInsets.symmetric(vertical: 20, horizontal: 0), + child: Icon( + CommunityMaterialIcons.whatsapp, + size: 30, + color: Color(0xFF2BA4EC), + ), + ), + ), + ), ], ); } + + return const SizedBox(); + } + + Widget customMapButton(ServiceEntity service) { + if ((service.status == ServiceStatus.acepted || + service.status == ServiceStatus.pending || + service.status == ServiceStatus.active) && + service.location == ServiceLocationPreferences.delivery) { + return Padding( + padding: const EdgeInsets.only( + top: 8, + bottom: 25, + ), + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + ElevatedButton( + onPressed: () async { + final Uri url = Uri.parse( + 'https://www.google.com/maps/search/?api=1&query=${service.latitude},${service.longitude}'); + + if (!await launchUrl(url)) { + throw Exception('Could not launch $url'); + } + }, + style: ElevatedButton.styleFrom( + foregroundColor: const Color(0xFF2BA4EC), + backgroundColor: const Color(0xFF2BA4EC), + shape: const CircleBorder( + side: BorderSide( + color: Color(0xFF2BA4EC), + width: 2, + ), + ), + ), + child: const Padding( + padding: EdgeInsets.symmetric( + vertical: 20, + horizontal: 0, + ), + child: Icon( + Icons.near_me, + size: 30, + color: Colors.white, + ), + ), + ), + const SizedBox(width: 15), + SizedBox( + width: 230, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + service.address, + maxLines: 3, + textAlign: TextAlign.start, + style: const TextStyle( + fontSize: 15, + //center + ), + ), + service.aditionalAddress.isEmpty + ? Container() + : Text( + service.aditionalAddress, + textAlign: TextAlign.start, + maxLines: 3, + style: const TextStyle( + fontSize: 15, + color: Colors.black54, + ), + ), + ], + ), + ), + ], + ), + ); + } + + return const SizedBox(); + } + + Widget customMessageStatus(ServiceEntity service) { + // if (service.status == ServiceStatus.acepted) { + // return Stack( + // alignment: AlignmentDirectional.topCenter, + // clipBehavior: Clip.none, + // children: [ + // Card( + // color: Colors.green.shade50, + // child: const Padding( + // padding: EdgeInsets.fromLTRB(32, 56, 32, 32), + // child: Text( + // 'Aceptado', + // style: TextStyle(fontSize: 32, color: Colors.green), + // ), + // ), + // ), + // Positioned( + // top: -40, + // child: Container( + // padding: const EdgeInsets.all(16), + // decoration: BoxDecoration( + // color: Colors.white, + // border: Border.all(color: Colors.green.shade50, width: 4), + // shape: BoxShape.circle, + // ), + // child: const Icon(Icons.check, color: Colors.green, size: 48), + // ), + // ) + // ], + // ); + // } if (service.status == ServiceStatus.cancelled) { return Stack( alignment: AlignmentDirectional.topCenter, @@ -330,40 +506,40 @@ class _ProfessionalServiceScreenState extends State { ); } - if (service.status == ServiceStatus.active) { - return Stack( - alignment: AlignmentDirectional.topCenter, - clipBehavior: Clip.none, - children: [ - Card( - color: Colors.green.shade50, - child: const Padding( - padding: EdgeInsets.fromLTRB(32, 56, 32, 32), - child: Text( - 'En proceso...', - style: TextStyle(fontSize: 32, color: Colors.green), - ), - ), - ), - Positioned( - top: -40, - child: Container( - padding: const EdgeInsets.all(16), - decoration: BoxDecoration( - color: Colors.white, - border: Border.all(color: Colors.green.shade50, width: 4), - shape: BoxShape.circle, - ), - child: const Icon( - Icons.access_time_rounded, - color: Colors.green, - size: 48, - ), - ), - ) - ], - ); - } + // if (service.status == ServiceStatus.active) { + // return Stack( + // alignment: AlignmentDirectional.topCenter, + // clipBehavior: Clip.none, + // children: [ + // Card( + // color: Colors.green.shade50, + // child: const Padding( + // padding: EdgeInsets.fromLTRB(32, 56, 32, 32), + // child: Text( + // 'En proceso...', + // style: TextStyle(fontSize: 32, color: Colors.green), + // ), + // ), + // ), + // Positioned( + // top: -40, + // child: Container( + // padding: const EdgeInsets.all(16), + // decoration: BoxDecoration( + // color: Colors.white, + // border: Border.all(color: Colors.green.shade50, width: 4), + // shape: BoxShape.circle, + // ), + // child: const Icon( + // Icons.access_time_rounded, + // color: Colors.green, + // size: 48, + // ), + // ), + // ) + // ], + // ); + // } if (service.status == ServiceStatus.completed) { return Stack( alignment: AlignmentDirectional.topCenter, @@ -389,7 +565,7 @@ class _ProfessionalServiceScreenState extends State { shape: BoxShape.circle, ), child: const Icon( - Icons.star, + Icons.check_rounded, color: Colors.green, size: 48, ), diff --git a/lib/screens/service/user_service_screen.dart b/lib/screens/service/user_service_screen.dart index 18dd0e5..d000188 100644 --- a/lib/screens/service/user_service_screen.dart +++ b/lib/screens/service/user_service_screen.dart @@ -1,3 +1,4 @@ +import 'package:community_material_icon/community_material_icon.dart'; import 'package:firebase_auth/firebase_auth.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; @@ -9,6 +10,7 @@ import 'package:prosappco/blocs/service_bloc/service_bloc.dart'; import 'package:prosappco/components/general_secondary_button.dart'; import 'package:service_repository/service_repository.dart'; import 'package:setting_repository/setting_repository.dart'; +import 'package:url_launcher/url_launcher.dart'; import 'package:user_repository/user_repository.dart'; class UserServiceScreen extends StatefulWidget { @@ -233,25 +235,29 @@ class _UserServiceScreenState extends State { ], ), ), - ListTile( - leading: const Icon(Icons.near_me), - title: Text( - service.address, - style: TextStyle( - fontSize: 15, - color: Colors.grey[600], - ), - ), - subtitle: service.aditionalAddress.isEmpty - ? null - : Text( - service.aditionalAddress, - style: TextStyle( - fontSize: 15, - color: Colors.grey[600], - ), - ), - ), + + customMapButton(service), + + + // ListTile( + // leading: const Icon(Icons.near_me), + // title: Text( + // service.address, + // style: TextStyle( + // fontSize: 15, + // color: Colors.grey[600], + // ), + // ), + // subtitle: service.aditionalAddress.isEmpty + // ? null + // : Text( + // service.aditionalAddress, + // style: TextStyle( + // fontSize: 15, + // color: Colors.grey[600], + // ), + // ), + // ), service.description.isEmpty ? const SizedBox() : Container( @@ -268,7 +274,9 @@ class _UserServiceScreenState extends State { ), ), ), - const SizedBox(height: 55), + const SizedBox(height: 20), + customActionButtons(service, userInfo), + const SizedBox(height: 60), customMessageStatus(service), const SizedBox(height: 20), ], @@ -303,6 +311,175 @@ class _UserServiceScreenState extends State { ); } + Widget customMapButton(ServiceEntity service) { + if ((service.status == ServiceStatus.acepted || + service.status == ServiceStatus.active) && + service.location == ServiceLocationPreferences.office) { + return Padding( + padding: const EdgeInsets.only( + top: 8, + bottom: 25, + ), + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + ElevatedButton( + onPressed: () async { + final Uri url = Uri.parse( + 'https://www.google.com/maps/search/?api=1&query=${service.latitude},${service.longitude}'); + + if (!await launchUrl(url)) { + throw Exception('Could not launch $url'); + } + }, + style: ElevatedButton.styleFrom( + foregroundColor: const Color(0xFF2BA4EC), + backgroundColor: const Color(0xFF2BA4EC), + shape: const CircleBorder( + side: BorderSide( + color: Color(0xFF2BA4EC), + width: 2, + ), + ), + ), + child: const Padding( + padding: EdgeInsets.symmetric( + vertical: 20, + horizontal: 0, + ), + child: Icon( + Icons.near_me, + size: 30, + color: Colors.white, + ), + ), + ), + const SizedBox(width: 15), + SizedBox( + width: 230, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + service.address, + maxLines: 3, + textAlign: TextAlign.start, + style: const TextStyle( + fontSize: 15, + //center + ), + ), + service.aditionalAddress.isEmpty + ? Container() + : Text( + service.aditionalAddress, + textAlign: TextAlign.start, + maxLines: 3, + style: const TextStyle( + fontSize: 15, + color: Colors.black54, + ), + ), + ], + ), + ), + ], + ), + ); + } + + return const SizedBox(); + } + + Widget customActionButtons(ServiceEntity service, MyUser user) { + if (service.status == ServiceStatus.acepted || + service.status == ServiceStatus.active) { + return Wrap( + alignment: WrapAlignment.center, + spacing: 15, + children: [ + Visibility( + visible: user.phone == null ? false : true, + child: ElevatedButton( + onPressed: () => launch("tel:${user.phone}"), + style: ElevatedButton.styleFrom( + foregroundColor: const Color(0xFF2BA4EC), + backgroundColor: Colors.white, + shape: const CircleBorder( + side: BorderSide( + color: Color(0xFF2BA4EC), + width: 2, + ), + ), + ), + child: const Padding( + padding: EdgeInsets.symmetric(vertical: 20, horizontal: 0), + child: Icon( + Icons.phone_android, + size: 30, + color: Color(0xFF2BA4EC), + ), + ), + ), + ), + ElevatedButton( + onPressed: () {}, + style: ElevatedButton.styleFrom( + foregroundColor: const Color(0xFF2BA4EC), + backgroundColor: Colors.white, + shape: const CircleBorder( + side: BorderSide( + color: Color(0xFF2BA4EC), + width: 2, + ), + ), + ), + child: const Padding( + padding: EdgeInsets.symmetric(vertical: 20, horizontal: 0), + child: Icon( + Icons.message, + size: 30, + color: Color(0xFF2BA4EC), + ), + ), + ), + Visibility( + visible: user.phone == null ? false : true, + child: ElevatedButton( + onPressed: () async { + final whatsappUrl = + 'https://wa.me/${user.phone}?text=${Uri.parse('Hola! me contactaste por Prossapp')}'; + if (!await launch(whatsappUrl)) { + throw Exception('Could not launch $whatsappUrl'); + } + }, + style: ElevatedButton.styleFrom( + foregroundColor: const Color(0xFF2BA4EC), + backgroundColor: Colors.white, + shape: const CircleBorder( + side: BorderSide( + color: Color(0xFF2BA4EC), + width: 2, + ), + ), + ), + child: const Padding( + padding: EdgeInsets.symmetric(vertical: 20, horizontal: 0), + child: Icon( + CommunityMaterialIcons.whatsapp, + size: 30, + color: Color(0xFF2BA4EC), + ), + ), + ), + ), + ], + ); + } + + return const SizedBox(); + } + Widget customMessageStatus(ServiceEntity service) { if (service.status == ServiceStatus.pending) { return Stack( @@ -335,36 +512,36 @@ class _UserServiceScreenState extends State { ], ); } - if (service.status == ServiceStatus.acepted) { - return Stack( - alignment: AlignmentDirectional.topCenter, - clipBehavior: Clip.none, - children: [ - Card( - color: Colors.green.shade50, - child: const Padding( - padding: EdgeInsets.fromLTRB(32, 56, 32, 32), - child: Text( - 'Aceptado', - style: TextStyle(fontSize: 32, color: Colors.green), - ), - ), - ), - Positioned( - top: -40, - child: Container( - padding: const EdgeInsets.all(16), - decoration: BoxDecoration( - color: Colors.white, - border: Border.all(color: Colors.green.shade50, width: 4), - shape: BoxShape.circle, - ), - child: const Icon(Icons.check, color: Colors.green, size: 48), - ), - ) - ], - ); - } + // if (service.status == ServiceStatus.acepted) { + // return Stack( + // alignment: AlignmentDirectional.topCenter, + // clipBehavior: Clip.none, + // children: [ + // Card( + // color: Colors.green.shade50, + // child: const Padding( + // padding: EdgeInsets.fromLTRB(32, 56, 32, 32), + // child: Text( + // 'Aceptado', + // style: TextStyle(fontSize: 32, color: Colors.green), + // ), + // ), + // ), + // Positioned( + // top: -40, + // child: Container( + // padding: const EdgeInsets.all(16), + // decoration: BoxDecoration( + // color: Colors.white, + // border: Border.all(color: Colors.green.shade50, width: 4), + // shape: BoxShape.circle, + // ), + // child: const Icon(Icons.check, color: Colors.green, size: 48), + // ), + // ) + // ], + // ); + // } if (service.status == ServiceStatus.cancelled) { return Stack( alignment: AlignmentDirectional.topCenter, @@ -428,40 +605,40 @@ class _UserServiceScreenState extends State { ); } - if (service.status == ServiceStatus.active) { - return Stack( - alignment: AlignmentDirectional.topCenter, - clipBehavior: Clip.none, - children: [ - Card( - color: Colors.green.shade50, - child: const Padding( - padding: EdgeInsets.fromLTRB(32, 56, 32, 32), - child: Text( - 'En proceso...', - style: TextStyle(fontSize: 32, color: Colors.green), - ), - ), - ), - Positioned( - top: -40, - child: Container( - padding: const EdgeInsets.all(16), - decoration: BoxDecoration( - color: Colors.white, - border: Border.all(color: Colors.green.shade50, width: 4), - shape: BoxShape.circle, - ), - child: const Icon( - Icons.access_time_rounded, - color: Colors.green, - size: 48, - ), - ), - ) - ], - ); - } + // if (service.status == ServiceStatus.active) { + // return Stack( + // alignment: AlignmentDirectional.topCenter, + // clipBehavior: Clip.none, + // children: [ + // Card( + // color: Colors.green.shade50, + // child: const Padding( + // padding: EdgeInsets.fromLTRB(32, 56, 32, 32), + // child: Text( + // 'En proceso...', + // style: TextStyle(fontSize: 32, color: Colors.green), + // ), + // ), + // ), + // Positioned( + // top: -40, + // child: Container( + // padding: const EdgeInsets.all(16), + // decoration: BoxDecoration( + // color: Colors.white, + // border: Border.all(color: Colors.green.shade50, width: 4), + // shape: BoxShape.circle, + // ), + // child: const Icon( + // Icons.access_time_rounded, + // color: Colors.green, + // size: 48, + // ), + // ), + // ) + // ], + // ); + // } if (service.status == ServiceStatus.completed) { return Stack( alignment: AlignmentDirectional.topCenter, @@ -514,30 +691,6 @@ class _UserServiceScreenState extends State { }, ); } - // if (service.status == ServiceStatus.acepted) { - // return GeneralSecondaryButton( - // label: 'Iniciar servicio', - // onPressed: () { - // final currentState = context.read().state; - // if (currentState is ServiceLoaded) { - // context.read().add( - // UpdateServiceStatus(widget.serviceId, ServiceStatus.active)); - // } - // }, - // ); - // } - - // if (service.status == ServiceStatus.active) { - // return GeneralSecondaryButton( - // label: 'Terminar servicio', - // onPressed: () { - // final currentState = context.read().state; - // if (currentState is ServiceLoaded) { - // context.read().add(UpdateServiceStatus( - // widget.serviceId, ServiceStatus.completed)); - // } - // }); - // } return GeneralSecondaryButton( label: 'Volver',