numero de solicitudes
This commit is contained in:
@@ -37,6 +37,8 @@ class ServiceBloc extends Bloc<ServiceEvent, ServiceState> {
|
|||||||
_onLoadPendingServicesForProfessional);
|
_onLoadPendingServicesForProfessional);
|
||||||
on<UpdateProfessionalScored>(_onUpdateProfessionalScored);
|
on<UpdateProfessionalScored>(_onUpdateProfessionalScored);
|
||||||
on<UpdateUserScored>(_onUpdateUserScored);
|
on<UpdateUserScored>(_onUpdateUserScored);
|
||||||
|
on<CountPendingServicesForProfessional>(
|
||||||
|
_onCountPendingServicesForProfessional);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onCreateService(CreateService event, Emitter<ServiceState> emit) async {
|
void _onCreateService(CreateService event, Emitter<ServiceState> emit) async {
|
||||||
@@ -297,6 +299,22 @@ class ServiceBloc extends Bloc<ServiceEvent, ServiceState> {
|
|||||||
emit(CreateServiceFailure());
|
emit(CreateServiceFailure());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _onCountPendingServicesForProfessional(
|
||||||
|
CountPendingServicesForProfessional event,
|
||||||
|
Emitter<ServiceState> emit) async {
|
||||||
|
try {
|
||||||
|
final count = await _serviceRepository
|
||||||
|
.countPendingServicesForProfessional(event.professionalId);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
emit(PendingServicesCountedLoaded(count));
|
||||||
|
} catch (e) {
|
||||||
|
log(e.toString());
|
||||||
|
emit(CreateServiceFailure());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class ServiceInfoUI {
|
class ServiceInfoUI {
|
||||||
|
|||||||
@@ -98,6 +98,15 @@ class UpdateUserScored extends ServiceEvent {
|
|||||||
List<Object> get props => [serviceId];
|
List<Object> get props => [serviceId];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class CountPendingServicesForProfessional extends ServiceEvent {
|
||||||
|
final String professionalId;
|
||||||
|
|
||||||
|
const CountPendingServicesForProfessional(this.professionalId);
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [professionalId];
|
||||||
|
}
|
||||||
|
|
||||||
class CreateService extends ServiceEvent {
|
class CreateService extends ServiceEvent {
|
||||||
final String professionalId;
|
final String professionalId;
|
||||||
final bool? professionalScored;
|
final bool? professionalScored;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
part of 'service_bloc.dart';
|
part of 'service_bloc.dart';
|
||||||
|
|
||||||
abstract class ServiceState extends Equatable {
|
class ServiceState extends Equatable {
|
||||||
const ServiceState();
|
const ServiceState();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -49,4 +49,13 @@ class ServiceStatusUpdated extends ServiceState {
|
|||||||
List<Object> get props => [newStatus];
|
List<Object> get props => [newStatus];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class PendingServicesCountedLoaded extends ServiceState {
|
||||||
|
final int count;
|
||||||
|
|
||||||
|
const PendingServicesCountedLoaded(this.count);
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [count];
|
||||||
|
}
|
||||||
|
|
||||||
class ScoredUpdated extends ServiceState {}
|
class ScoredUpdated extends ServiceState {}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import 'dart:developer';
|
import 'dart:developer';
|
||||||
|
|
||||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||||
|
import 'package:firebase_auth/firebase_auth.dart';
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
@@ -10,6 +11,7 @@ import 'package:injector/injector.dart';
|
|||||||
import 'package:prosappco/blocs/my_user_bloc/my_user_bloc.dart';
|
import 'package:prosappco/blocs/my_user_bloc/my_user_bloc.dart';
|
||||||
import 'package:prosappco/blocs/professional_bloc/professional_bloc.dart';
|
import 'package:prosappco/blocs/professional_bloc/professional_bloc.dart';
|
||||||
import 'package:prosappco/blocs/score_bloc/score_bloc.dart';
|
import 'package:prosappco/blocs/score_bloc/score_bloc.dart';
|
||||||
|
import 'package:prosappco/blocs/service_bloc/service_bloc.dart';
|
||||||
import 'package:prosappco/components/drawer_reputation.dart';
|
import 'package:prosappco/components/drawer_reputation.dart';
|
||||||
import 'package:prosappco/components/general_drawer_header.dart';
|
import 'package:prosappco/components/general_drawer_header.dart';
|
||||||
import 'package:prosappco/components/general_drawer_item.dart';
|
import 'package:prosappco/components/general_drawer_item.dart';
|
||||||
@@ -31,6 +33,7 @@ import 'package:prosappco/screens/professional/professional_services_screen.dart
|
|||||||
import 'package:prosappco/screens/profile/profile_screen.dart';
|
import 'package:prosappco/screens/profile/profile_screen.dart';
|
||||||
import 'package:prosappco/screens/user/user_history_services_screen.dart';
|
import 'package:prosappco/screens/user/user_history_services_screen.dart';
|
||||||
import 'package:prosappco/screens/web/web_view_screen.dart';
|
import 'package:prosappco/screens/web/web_view_screen.dart';
|
||||||
|
import 'package:service_repository/service_repository.dart';
|
||||||
import 'package:url_launcher/url_launcher.dart';
|
import 'package:url_launcher/url_launcher.dart';
|
||||||
import 'package:user_repository/user_repository.dart';
|
import 'package:user_repository/user_repository.dart';
|
||||||
|
|
||||||
@@ -200,15 +203,53 @@ class GeneralDrawer extends StatelessWidget {
|
|||||||
color: const Color(0xFF2BA4EC),
|
color: const Color(0xFF2BA4EC),
|
||||||
child: ListTile(
|
child: ListTile(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
shouldProModeActive(
|
Navigator.pop(context);
|
||||||
context, professionalState)
|
|
||||||
? Navigator.pop(context)
|
|
||||||
: Navigator.pop(context);
|
|
||||||
},
|
},
|
||||||
trailing: const Icon(
|
trailing: shouldProModeActive(
|
||||||
Icons.keyboard_arrow_right,
|
context, professionalState)
|
||||||
color: Colors.white,
|
? FutureBuilder(
|
||||||
),
|
builder: (context,
|
||||||
|
AsyncSnapshot<int> snapshot) {
|
||||||
|
if (!snapshot.hasData ||
|
||||||
|
snapshot.data! < 1) {
|
||||||
|
return const SizedBox();
|
||||||
|
}
|
||||||
|
final int notificationCount =
|
||||||
|
snapshot.data!;
|
||||||
|
return Container(
|
||||||
|
padding: const EdgeInsets.symmetric(
|
||||||
|
horizontal: 8,
|
||||||
|
vertical: 2,
|
||||||
|
),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.red,
|
||||||
|
borderRadius:
|
||||||
|
BorderRadius.circular(12),
|
||||||
|
),
|
||||||
|
child: Text(
|
||||||
|
notificationCount > 9
|
||||||
|
? '+9'
|
||||||
|
: notificationCount
|
||||||
|
.toString(),
|
||||||
|
style: const TextStyle(
|
||||||
|
color: Colors.white,
|
||||||
|
fontSize: 14,
|
||||||
|
fontWeight: FontWeight.w500,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
future: Injector.appInstance
|
||||||
|
.get<FirebaseServiceRepository>()
|
||||||
|
.countPendingServicesForProfessional(
|
||||||
|
FirebaseAuth
|
||||||
|
.instance.currentUser!.uid),
|
||||||
|
)
|
||||||
|
: const Icon(
|
||||||
|
Icons.keyboard_arrow_right,
|
||||||
|
color: Colors.white,
|
||||||
|
size: 25,
|
||||||
|
),
|
||||||
title: Text(
|
title: Text(
|
||||||
shouldProModeActive(
|
shouldProModeActive(
|
||||||
context, professionalState)
|
context, professionalState)
|
||||||
@@ -257,8 +298,7 @@ class GeneralDrawer extends StatelessWidget {
|
|||||||
title: Row(
|
title: Row(
|
||||||
children: [
|
children: [
|
||||||
RatingBar.builder(
|
RatingBar.builder(
|
||||||
// initialRating: calculoRating(average),
|
initialRating: calculoRating(average),
|
||||||
initialRating: 3,
|
|
||||||
minRating: 1,
|
minRating: 1,
|
||||||
direction: Axis.horizontal,
|
direction: Axis.horizontal,
|
||||||
allowHalfRating: true,
|
allowHalfRating: true,
|
||||||
@@ -340,81 +380,131 @@ class GeneralDrawer extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
buttonOfState(BuildContext context, ProfessionalState state) {
|
buttonOfState(BuildContext context, ProfessionalState state) {
|
||||||
return ElevatedButton(
|
return Stack(
|
||||||
onPressed: () {
|
children: [
|
||||||
final myUserState = context.read<MyUserBloc>().state;
|
SizedBox(
|
||||||
if (myUserState.status == MyUserStatus.success) {
|
width: MediaQuery.of(context).size.width * 0.7,
|
||||||
final user = myUserState.user!;
|
child: ElevatedButton(
|
||||||
|
onPressed: () {
|
||||||
|
final myUserState = context.read<MyUserBloc>().state;
|
||||||
|
if (myUserState.status == MyUserStatus.success) {
|
||||||
|
final user = myUserState.user!;
|
||||||
|
|
||||||
if (user.name != null &&
|
if (user.name != null &&
|
||||||
user.email != null &&
|
user.email != null &&
|
||||||
user.city != null &&
|
user.city != null &&
|
||||||
user.phone != null) {
|
user.phone != null) {
|
||||||
switch (user.proState) {
|
switch (user.proState) {
|
||||||
case ProState.active:
|
case ProState.active:
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
|
|
||||||
context
|
context
|
||||||
.read<ProfessionalBloc>()
|
.read<ProfessionalBloc>()
|
||||||
.add(const SwitchProModeEvent());
|
.add(const SwitchProModeEvent());
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case ProState.inactive:
|
case ProState.inactive:
|
||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
CupertinoPageRoute(
|
CupertinoPageRoute(
|
||||||
builder: (context) => const ProfessionalFormScreen(),
|
builder: (context) => const ProfessionalFormScreen(),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case ProState.pending:
|
case ProState.pending:
|
||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
CupertinoPageRoute(
|
CupertinoPageRoute(
|
||||||
builder: (context) => const ProfessionalPendingScreen(),
|
builder: (context) =>
|
||||||
),
|
const ProfessionalPendingScreen(),
|
||||||
);
|
),
|
||||||
break;
|
);
|
||||||
case ProState.denied:
|
break;
|
||||||
Navigator.push(
|
case ProState.denied:
|
||||||
context,
|
Navigator.push(
|
||||||
CupertinoPageRoute(
|
context,
|
||||||
builder: (context) => const ProfessionalDeniedScreen(),
|
CupertinoPageRoute(
|
||||||
),
|
builder: (context) =>
|
||||||
);
|
const ProfessionalDeniedScreen(),
|
||||||
break;
|
),
|
||||||
}
|
);
|
||||||
} else {
|
break;
|
||||||
ScaffoldMessenger.of(context).clearSnackBars();
|
}
|
||||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
|
} else {
|
||||||
content: Text('Por favor, completa tu perfil'),
|
ScaffoldMessenger.of(context).clearSnackBars();
|
||||||
));
|
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
|
||||||
|
content: Text('Por favor, completa tu perfil'),
|
||||||
|
));
|
||||||
|
|
||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
CupertinoPageRoute(
|
CupertinoPageRoute(
|
||||||
builder: (context) => const ProfileScreen(),
|
builder: (context) => const ProfileScreen(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {}
|
||||||
|
},
|
||||||
|
style: FilledButton.styleFrom(
|
||||||
|
backgroundColor: Theme.of(context).colorScheme.primary,
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 15),
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(10),
|
||||||
),
|
),
|
||||||
);
|
|
||||||
}
|
|
||||||
} else {}
|
|
||||||
},
|
|
||||||
style: FilledButton.styleFrom(
|
|
||||||
backgroundColor: Theme.of(context).colorScheme.primary,
|
|
||||||
padding: const EdgeInsets.symmetric(vertical: 15),
|
|
||||||
shape: RoundedRectangleBorder(
|
|
||||||
borderRadius: BorderRadius.circular(10),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
child: (state is LoadedModeProState)
|
|
||||||
? Text(
|
|
||||||
state.isProModeActive ? 'Modo cliente' : 'Modo profesional',
|
|
||||||
style: const TextStyle(color: Colors.white, fontSize: 18),
|
|
||||||
)
|
|
||||||
: const Text(
|
|
||||||
'Modo profesional',
|
|
||||||
style: TextStyle(color: Colors.white, fontSize: 18),
|
|
||||||
),
|
),
|
||||||
|
child: (state is LoadedModeProState)
|
||||||
|
? Text(
|
||||||
|
state.isProModeActive ? 'Modo cliente' : 'Modo profesional',
|
||||||
|
style: const TextStyle(color: Colors.white, fontSize: 18),
|
||||||
|
)
|
||||||
|
: const Text(
|
||||||
|
'Modo profesional',
|
||||||
|
style: TextStyle(color: Colors.white, fontSize: 18),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
(state is LoadedModeProState)
|
||||||
|
? Visibility(
|
||||||
|
visible: !state.isProModeActive,
|
||||||
|
child: Positioned(
|
||||||
|
top: 0,
|
||||||
|
right: 0,
|
||||||
|
child: FutureBuilder(
|
||||||
|
builder: (context, AsyncSnapshot<int> snapshot) {
|
||||||
|
if (!snapshot.hasData || snapshot.data! < 1) {
|
||||||
|
return const SizedBox();
|
||||||
|
}
|
||||||
|
final int notificationCount = snapshot.data!;
|
||||||
|
return Container(
|
||||||
|
padding: const EdgeInsets.symmetric(
|
||||||
|
horizontal: 8,
|
||||||
|
vertical: 2,
|
||||||
|
),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.red,
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
),
|
||||||
|
child: Text(
|
||||||
|
notificationCount > 9
|
||||||
|
? '+9'
|
||||||
|
: notificationCount.toString(),
|
||||||
|
style: const TextStyle(
|
||||||
|
color: Colors.white,
|
||||||
|
fontSize: 14,
|
||||||
|
fontWeight: FontWeight.w500,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
future: Injector.appInstance
|
||||||
|
.get<FirebaseServiceRepository>()
|
||||||
|
.countPendingServicesForProfessional(
|
||||||
|
FirebaseAuth.instance.currentUser!.uid),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: const SizedBox(),
|
||||||
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -91,8 +91,16 @@ class FirebaseServiceRepository {
|
|||||||
.toList());
|
.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
// actualizar professionalScored a true
|
Future<int> countPendingServicesForProfessional(String professionalId) async {
|
||||||
|
QuerySnapshot<Map<String, dynamic>> query = await serviceCollection
|
||||||
|
.where('professional_id', isEqualTo: professionalId)
|
||||||
|
.where('status', isEqualTo: 0)
|
||||||
|
.get();
|
||||||
|
|
||||||
|
return query.size;
|
||||||
|
}
|
||||||
|
|
||||||
|
// actualizar professionalScored a true
|
||||||
Future<void> setProfessionalScored(String serviceId) {
|
Future<void> setProfessionalScored(String serviceId) {
|
||||||
return serviceCollection
|
return serviceCollection
|
||||||
.doc(serviceId)
|
.doc(serviceId)
|
||||||
|
|||||||
Reference in New Issue
Block a user