From 2facd1b1d865283117d43c97c10500d8d31a02f6 Mon Sep 17 00:00:00 2001 From: Felipe Date: Thu, 18 Apr 2024 08:37:09 -0500 Subject: [PATCH] scored true --- lib/blocs/service_bloc/service_bloc.dart | 13 ++ lib/blocs/service_bloc/service_event.dart | 18 ++ lib/blocs/service_bloc/service_state.dart | 3 +- lib/screens/score/score_screen.dart | 111 +++++----- .../service/professional_service_screen.dart | 193 ++++++++++-------- lib/screens/service/user_service_screen.dart | 66 +++++- .../firebase_service_repository.dart | 23 +++ 7 files changed, 289 insertions(+), 138 deletions(-) diff --git a/lib/blocs/service_bloc/service_bloc.dart b/lib/blocs/service_bloc/service_bloc.dart index 9526450..05660e3 100644 --- a/lib/blocs/service_bloc/service_bloc.dart +++ b/lib/blocs/service_bloc/service_bloc.dart @@ -33,6 +33,7 @@ class ServiceBloc extends Bloc { on(_onLoadServicesHistoryForUser); on( _onLoadServicesHistoryForProfessional); + on(_onUpdateProfessionalScored); } void _onCreateService(CreateService event, Emitter emit) async { @@ -235,6 +236,18 @@ class ServiceBloc extends Bloc { emit(CreateServiceFailure()); } } + + void _onUpdateProfessionalScored( + UpdateProfessionalScored event, Emitter emit) async { + try { + emit(CreateServiceLoading()); + await _serviceRepository.setProfessionalScored(event.serviceId); + emit(ProfessionalScoredUpdated()); + } catch (e) { + log(e.toString()); + emit(CreateServiceFailure()); + } + } } class ServiceInfoUI { diff --git a/lib/blocs/service_bloc/service_event.dart b/lib/blocs/service_bloc/service_event.dart index a314626..5efe9e8 100644 --- a/lib/blocs/service_bloc/service_event.dart +++ b/lib/blocs/service_bloc/service_event.dart @@ -62,6 +62,24 @@ class LoadServicesHistoryForUser extends ServiceEvent { List get props => [userId]; } +class LoadServicesByDay extends ServiceEvent { + final String day; + + const LoadServicesByDay(this.day); + + @override + List get props => [day]; +} + +class UpdateProfessionalScored extends ServiceEvent { + final String serviceId; + + const UpdateProfessionalScored(this.serviceId); + + @override + List get props => [serviceId]; +} + class CreateService extends ServiceEvent { final String professionalId; final bool? professionalScored; diff --git a/lib/blocs/service_bloc/service_state.dart b/lib/blocs/service_bloc/service_state.dart index 92d9179..1e8cd71 100644 --- a/lib/blocs/service_bloc/service_state.dart +++ b/lib/blocs/service_bloc/service_state.dart @@ -16,7 +16,6 @@ class ServiceLoaded extends ServiceState { List get props => [service]; } - class ServicesForUserLoaded extends ServiceState { final List services; @@ -49,3 +48,5 @@ class ServiceStatusUpdated extends ServiceState { @override List get props => [newStatus]; } + +class ProfessionalScoredUpdated extends ServiceState {} diff --git a/lib/screens/score/score_screen.dart b/lib/screens/score/score_screen.dart index d4177f4..c9e610e 100644 --- a/lib/screens/score/score_screen.dart +++ b/lib/screens/score/score_screen.dart @@ -4,7 +4,9 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_rating_bar/flutter_rating_bar.dart'; +import 'package:injector/injector.dart'; import 'package:prosappco/blocs/score_bloc/score_bloc.dart'; +import 'package:prosappco/blocs/service_bloc/service_bloc.dart'; import 'package:score_repository/score_repository.dart'; import 'package:service_repository/service_repository.dart'; import 'package:user_repository/user_repository.dart'; @@ -102,7 +104,7 @@ class _ScoreScreenState extends State { ), const SizedBox(height: 10), const Text( - 'Calificación', + 'Califica el servicio', style: TextStyle(fontSize: 20, fontWeight: FontWeight.w600), ), const SizedBox(height: 10), @@ -155,54 +157,67 @@ class _ScoreScreenState extends State { height: 1, thickness: 0.5, ), - Padding( - padding: const EdgeInsets.symmetric( - vertical: 10, - horizontal: 15, - ), - child: FilledButton( - onPressed: () { - final CommentEntity comment = widget.service.userId == - FirebaseAuth.instance.currentUser!.uid - ? CommentEntity( - serviceId: widget.service.id!, - authorId: FirebaseAuth.instance.currentUser!.uid, - isFromUser: true, - score: _rating, - destinationId: widget.service.professionalId, - content: commentController.text, - createdAt: Timestamp.now(), - ) - : CommentEntity( - serviceId: widget.service.id!, - authorId: FirebaseAuth.instance.currentUser!.uid, - isFromUser: false, - score: _rating, - destinationId: widget.service.userId, - content: commentController.text, - createdAt: Timestamp.now(), - ); - - BlocProvider.of(context) - .add(SendScoreEvent(comment: comment)); - }, - style: FilledButton.styleFrom( - backgroundColor: Theme.of(context).colorScheme.primary, - padding: const EdgeInsets.symmetric(vertical: 15), - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(10), - ), + BlocProvider( + create: (context) => Injector.appInstance.get(), + child: Padding( + padding: const EdgeInsets.symmetric( + vertical: 10, + horizontal: 15, ), - child: Container( - alignment: Alignment.center, - width: double.infinity, - child: const Text( - 'Enviar calificación', - style: TextStyle( - color: Colors.white, - fontSize: 18, - ), - ), + child: BlocBuilder( + builder: (context, state) { + return FilledButton( + onPressed: () { + final CommentEntity comment = widget.service.userId == + FirebaseAuth.instance.currentUser!.uid + ? CommentEntity( + serviceId: widget.service.id!, + authorId: FirebaseAuth.instance.currentUser!.uid, + isFromUser: true, + score: _rating, + destinationId: widget.service.professionalId, + content: commentController.text.trim(), + createdAt: Timestamp.now(), + ) + : CommentEntity( + serviceId: widget.service.id!, + authorId: FirebaseAuth.instance.currentUser!.uid, + isFromUser: false, + score: _rating, + destinationId: widget.service.userId, + content: commentController.text.trim(), + createdAt: Timestamp.now(), + ); + + BlocProvider.of(context) + .add(SendScoreEvent(comment: comment)); + + context + .read() + .add(UpdateProfessionalScored(widget.service.id!)); + + Navigator.pop(context); + }, + style: FilledButton.styleFrom( + backgroundColor: Theme.of(context).colorScheme.primary, + padding: const EdgeInsets.symmetric(vertical: 15), + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(10), + ), + ), + child: Container( + alignment: Alignment.center, + width: double.infinity, + child: const Text( + 'Enviar calificación', + style: TextStyle( + color: Colors.white, + fontSize: 18, + ), + ), + ), + ); + }, ), ), ), diff --git a/lib/screens/service/professional_service_screen.dart b/lib/screens/service/professional_service_screen.dart index 2c7a813..ff025c8 100644 --- a/lib/screens/service/professional_service_screen.dart +++ b/lib/screens/service/professional_service_screen.dart @@ -517,96 +517,119 @@ class _ProfessionalServiceScreenState extends State { ); } - if (service.status == ServiceStatus.completed) { - if (service.userScored) { - 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( - 'Completado', - 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_rounded, - color: Colors.green, - size: 48, - ), - ), - ) - ], - ); - } else { - return Stack( - alignment: AlignmentDirectional.topCenter, - clipBehavior: Clip.none, - children: [ - Card( - color: Colors.green.shade50, - child: Padding( - padding: const EdgeInsets.fromLTRB(32, 56, 32, 32), - child: Column( - children: [ - const Text( - 'Completado', - style: TextStyle(fontSize: 32, color: Colors.green), - ), - const SizedBox(height: 16), - const Text( - 'Califica el servicio', - style: TextStyle(fontSize: 28, color: Colors.green), - ), - FilledButton( - onPressed: () { - Navigator.push( - context, - CupertinoPageRoute( - builder: (context) => ScoreScreen( - service: service, - ), + if (service.status == ServiceStatus.completed && + service.userScored == false) { + return Stack( + alignment: AlignmentDirectional.topCenter, + clipBehavior: Clip.none, + children: [ + Card( + color: Colors.green.shade50, + child: Padding( + padding: const EdgeInsets.fromLTRB(32, 56, 32, 32), + child: Column( + children: [ + const Text( + 'Completado', + style: TextStyle(fontSize: 32, color: Colors.green), + ), + const Text( + 'Califica el servicio', + style: TextStyle(fontSize: 20, color: Colors.green), + ), + const SizedBox(height: 15), + FilledButton( + onPressed: () { + Navigator.push( + context, + CupertinoPageRoute( + builder: (context) => ScoreScreen( + service: service, ), - ); - }, - child: const Text('Calificar'), + ), + ); + }, + style: FilledButton.styleFrom( + backgroundColor: Theme.of(context).colorScheme.primary, + padding: const EdgeInsets.symmetric(vertical: 15), + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(10), + ), ), - ], - ), + child: Container( + alignment: Alignment.center, + width: MediaQuery.of(context).size.width * 0.4, + child: const Text( + 'Calificar', + style: TextStyle( + color: Colors.white, + fontSize: 18, + ), + ), + ), + ), + ], ), ), - 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.star, - color: Colors.green, - size: 48, - ), + ), + 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.star, + color: Colors.green, + size: 48, + ), + ), + ) + ], + ); + } + + if (service.status == ServiceStatus.completed && + service.userScored == true) { + 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: Column( + children: [ + Text( + 'Completado', + 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.star, + color: Colors.green, + size: 48, + ), + ), + ) + ], + ); } return const SizedBox(); diff --git a/lib/screens/service/user_service_screen.dart b/lib/screens/service/user_service_screen.dart index a093ca1..577971d 100644 --- a/lib/screens/service/user_service_screen.dart +++ b/lib/screens/service/user_service_screen.dart @@ -647,7 +647,8 @@ class _UserServiceScreenState extends State { // ], // ); // } - if (service.status == ServiceStatus.completed) { + if (service.status == ServiceStatus.completed && + service.professionalScored == false) { return Stack( alignment: AlignmentDirectional.topCenter, clipBehavior: Clip.none, @@ -662,11 +663,11 @@ class _UserServiceScreenState extends State { 'Completado', style: TextStyle(fontSize: 32, color: Colors.green), ), - const SizedBox(height: 16), const Text( 'Califica el servicio', - style: TextStyle(fontSize: 28, color: Colors.green), + style: TextStyle(fontSize: 20, color: Colors.green), ), + const SizedBox(height: 15), FilledButton( onPressed: () { Navigator.push( @@ -678,7 +679,64 @@ class _UserServiceScreenState extends State { ), ); }, - child: const Text('Calificar'), + style: FilledButton.styleFrom( + backgroundColor: Theme.of(context).colorScheme.primary, + padding: const EdgeInsets.symmetric(vertical: 15), + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(10), + ), + ), + child: Container( + alignment: Alignment.center, + width: MediaQuery.of(context).size.width * 0.4, + child: const Text( + 'Calificar', + style: TextStyle( + color: Colors.white, + fontSize: 18, + ), + ), + ), + ), + ], + ), + ), + ), + 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.star, + color: Colors.green, + size: 48, + ), + ), + ) + ], + ); + } + + if (service.status == ServiceStatus.completed && + service.professionalScored == true) { + 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: Column( + children: [ + Text( + 'Completado', + style: TextStyle(fontSize: 32, color: Colors.green), ), ], ), diff --git a/packages/service_repository/lib/src/repositories/firebase_service_repository.dart b/packages/service_repository/lib/src/repositories/firebase_service_repository.dart index 7c84433..21da88d 100644 --- a/packages/service_repository/lib/src/repositories/firebase_service_repository.dart +++ b/packages/service_repository/lib/src/repositories/firebase_service_repository.dart @@ -68,6 +68,29 @@ class FirebaseServiceRepository { .map((doc) => ServiceEntity.fromDocument(doc.data(), doc.id)) .toList()); } + + // actualizar professionalScored a true + + Future setProfessionalScored(String serviceId) { + return serviceCollection + .doc(serviceId) + .update({'professional_scored': true}); + } + + Future setUserScored(String serviceId) { + return serviceCollection.doc(serviceId).update({'user_scored': true}); + } + + // TODO: NEW + Stream> getServicesByDay(String day) { + return serviceCollection + .where('day', isEqualTo: day) + .where('status', whereIn: [0, 1, 2, 3]) + .snapshots() + .map((querySnapshot) => querySnapshot.docs + .map((doc) => ServiceEntity.fromDocument(doc.data(), doc.id)) + .toList()); + } }