lista de servicios
This commit is contained in:
+2
-6
@@ -30,12 +30,8 @@ class MainApp extends StatelessWidget {
|
|||||||
create: (context) => Injector.appInstance.get<ProfessionalBloc>(),
|
create: (context) => Injector.appInstance.get<ProfessionalBloc>(),
|
||||||
),
|
),
|
||||||
BlocProvider<ProfessionalProfileBloc>(
|
BlocProvider<ProfessionalProfileBloc>(
|
||||||
create: (context) =>
|
create: (context) => Injector.appInstance.get<ProfessionalProfileBloc>(),
|
||||||
Injector.appInstance.get<ProfessionalProfileBloc>(),
|
)
|
||||||
),
|
|
||||||
BlocProvider<ServiceBloc>(
|
|
||||||
create: (context) => Injector.appInstance.get<ServiceBloc>(),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
child: BlocBuilder<MyUserBloc, MyUserState>(
|
child: BlocBuilder<MyUserBloc, MyUserState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
|
|||||||
@@ -4,21 +4,31 @@ import 'package:cloud_firestore/cloud_firestore.dart';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
|
import 'package:professional_repository/professional_repository.dart';
|
||||||
|
|
||||||
import 'package:service_repository/service_repository.dart';
|
import 'package:service_repository/service_repository.dart';
|
||||||
|
import 'package:user_repository/user_repository.dart';
|
||||||
|
|
||||||
part 'service_event.dart';
|
part 'service_event.dart';
|
||||||
part 'service_state.dart';
|
part 'service_state.dart';
|
||||||
|
|
||||||
class ServiceBloc extends Bloc<ServiceEvent, ServiceState> {
|
class ServiceBloc extends Bloc<ServiceEvent, ServiceState> {
|
||||||
final FirebaseServiceRepository _serviceRepository;
|
final FirebaseServiceRepository _serviceRepository;
|
||||||
|
final UserRepository _userRepository;
|
||||||
|
final FirebaseProfessionalRepository _professionalRepository;
|
||||||
|
|
||||||
ServiceBloc({required FirebaseServiceRepository serviceRepository})
|
ServiceBloc({
|
||||||
: _serviceRepository = serviceRepository,
|
required FirebaseServiceRepository serviceRepository,
|
||||||
|
required UserRepository userRepository,
|
||||||
|
required FirebaseProfessionalRepository professionRepository,
|
||||||
|
}) : _serviceRepository = serviceRepository,
|
||||||
|
_userRepository = userRepository,
|
||||||
|
_professionalRepository = professionRepository,
|
||||||
super(CreateServiceInitial()) {
|
super(CreateServiceInitial()) {
|
||||||
on<CreateService>(_onCreateService);
|
on<CreateService>(_onCreateService);
|
||||||
on<LoadService>(_onLoadService);
|
on<LoadService>(_onLoadService);
|
||||||
on<UpdateServiceStatus>(_onUpdateServiceStatus);
|
on<UpdateServiceStatus>(_onUpdateServiceStatus);
|
||||||
|
on<LoadServicesForUser>(_onLoadServicesForUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onCreateService(CreateService event, Emitter<ServiceState> emit) async {
|
void _onCreateService(CreateService event, Emitter<ServiceState> emit) async {
|
||||||
@@ -66,6 +76,40 @@ class ServiceBloc extends Bloc<ServiceEvent, ServiceState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _onLoadServicesForUser(
|
||||||
|
LoadServicesForUser event, Emitter<ServiceState> emit) async {
|
||||||
|
try {
|
||||||
|
final servicesStream =
|
||||||
|
_serviceRepository.getServicesForUser(event.userId);
|
||||||
|
|
||||||
|
await for (var services in servicesStream) {
|
||||||
|
final professionalIds = services.map((e) => e.professionalId);
|
||||||
|
final List<MyUser> users =
|
||||||
|
await _userRepository.getUsersFromIds(professionalIds);
|
||||||
|
|
||||||
|
final usersDir = {for (var e in users) e.id: e};
|
||||||
|
|
||||||
|
final List<ProfessionalEntity> professionsList =
|
||||||
|
await _professionalRepository
|
||||||
|
.getProfessionsFromIds(professionalIds);
|
||||||
|
|
||||||
|
final professionsDir = {for (var e in professionsList) e.id: e};
|
||||||
|
|
||||||
|
final servicesInfo = services.map((e) {
|
||||||
|
return ServiceInfoUI(
|
||||||
|
service: e,
|
||||||
|
user: usersDir[e.professionalId]!,
|
||||||
|
professional: professionsDir[e.professionalId]!);
|
||||||
|
}).toList();
|
||||||
|
|
||||||
|
emit(ServicesForUserLoaded(servicesInfo));
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
log(e.toString());
|
||||||
|
emit(CreateServiceFailure());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void _onUpdateServiceStatus(
|
void _onUpdateServiceStatus(
|
||||||
UpdateServiceStatus event, Emitter<ServiceState> emit) async {
|
UpdateServiceStatus event, Emitter<ServiceState> emit) async {
|
||||||
try {
|
try {
|
||||||
@@ -79,3 +123,12 @@ class ServiceBloc extends Bloc<ServiceEvent, ServiceState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class ServiceInfoUI {
|
||||||
|
final ServiceEntity service;
|
||||||
|
final MyUser user;
|
||||||
|
final ProfessionalEntity professional;
|
||||||
|
|
||||||
|
ServiceInfoUI(
|
||||||
|
{required this.service, required this.user, required this.professional});
|
||||||
|
}
|
||||||
|
|||||||
@@ -26,6 +26,15 @@ class UpdateServiceStatus extends ServiceEvent {
|
|||||||
List<Object> get props => [serviceId, newStatus];
|
List<Object> get props => [serviceId, newStatus];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class LoadServicesForUser extends ServiceEvent {
|
||||||
|
final String userId;
|
||||||
|
|
||||||
|
const LoadServicesForUser(this.userId);
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [userId];
|
||||||
|
}
|
||||||
|
|
||||||
class CreateService extends ServiceEvent {
|
class CreateService extends ServiceEvent {
|
||||||
final String professionalId;
|
final String professionalId;
|
||||||
final bool? professionalScored;
|
final bool? professionalScored;
|
||||||
|
|||||||
@@ -16,6 +16,15 @@ class ServiceLoaded extends ServiceState {
|
|||||||
List<Object> get props => [service];
|
List<Object> get props => [service];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class ServicesForUserLoaded extends ServiceState {
|
||||||
|
final List<ServiceInfoUI> services;
|
||||||
|
|
||||||
|
const ServicesForUserLoaded(this.services);
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [services];
|
||||||
|
}
|
||||||
|
|
||||||
class CreateServiceInitial extends ServiceState {}
|
class CreateServiceInitial extends ServiceState {}
|
||||||
|
|
||||||
class CreateServiceFailure extends ServiceState {}
|
class CreateServiceFailure extends ServiceState {}
|
||||||
|
|||||||
@@ -73,7 +73,12 @@ class AppDI {
|
|||||||
injector.get<FirebaseProfessionalRepository>()),
|
injector.get<FirebaseProfessionalRepository>()),
|
||||||
);
|
);
|
||||||
|
|
||||||
injector.registerSingleton<ServiceBloc>(() => ServiceBloc(
|
injector.registerDependency<ServiceBloc>(
|
||||||
serviceRepository: injector.get<FirebaseServiceRepository>()));
|
() => ServiceBloc(
|
||||||
|
serviceRepository: injector.get<FirebaseServiceRepository>(),
|
||||||
|
userRepository: injector.get<UserRepository>(),
|
||||||
|
professionRepository: injector.get<FirebaseProfessionalRepository>(),
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
|
import 'package:firebase_auth/firebase_auth.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:injector/injector.dart';
|
||||||
|
import 'package:prosappco/blocs/service_bloc/service_bloc.dart';
|
||||||
|
|
||||||
class UserServiceListScreen extends StatefulWidget {
|
class UserServiceListScreen extends StatefulWidget {
|
||||||
const UserServiceListScreen({super.key});
|
const UserServiceListScreen({super.key});
|
||||||
@@ -8,20 +12,61 @@ class UserServiceListScreen extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _UserServiceListScreenState extends State<UserServiceListScreen> {
|
class _UserServiceListScreenState extends State<UserServiceListScreen> {
|
||||||
|
late final ServiceBloc serviceBloc;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
|
||||||
|
serviceBloc = Injector.appInstance.get<ServiceBloc>();
|
||||||
|
|
||||||
|
serviceBloc
|
||||||
|
.add(LoadServicesForUser(FirebaseAuth.instance.currentUser!.uid));
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return BlocProvider<ServiceBloc>(
|
||||||
|
create: (context) => serviceBloc,
|
||||||
|
child: Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: const Text('Mis Servicios'),
|
title: const Text('Mis Servicios'),
|
||||||
),
|
),
|
||||||
body: ListView.builder(
|
body: BlocBuilder<ServiceBloc, ServiceState>(
|
||||||
itemCount: 10,
|
builder: (context, serviceState) {
|
||||||
itemBuilder: (_, __) {
|
if (serviceState is ServicesForUserLoaded) {
|
||||||
|
return serviceState.services.isEmpty
|
||||||
|
? const Center(
|
||||||
|
child: Text('No tienes servicios'),
|
||||||
|
)
|
||||||
|
: ListView.builder(
|
||||||
|
itemCount: serviceState.services.length,
|
||||||
|
itemBuilder: (_, index) {
|
||||||
|
final serviceInfo = serviceState.services[index];
|
||||||
|
final user = serviceInfo.user;
|
||||||
|
final professional = serviceInfo.professional;
|
||||||
|
final service = serviceInfo.service;
|
||||||
|
|
||||||
return ListTile(
|
return ListTile(
|
||||||
onTap: () {},
|
onTap: () {},
|
||||||
title: Text('Servicio ${__ + 1}'),
|
title: Column(
|
||||||
|
children: [
|
||||||
|
Text(user.name ?? ''),
|
||||||
|
Text(professional.identification),
|
||||||
|
Text(service.address),
|
||||||
|
],
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}),
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return const Center(
|
||||||
|
child: CircularProgressIndicator(),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,9 @@ class _UserServiceScreenState extends State<UserServiceScreen> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return BlocProvider<ServiceBloc>(
|
||||||
|
create: (context) => Injector.appInstance.get<ServiceBloc>(),
|
||||||
|
child: Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: const Text('Servicio'),
|
title: const Text('Servicio'),
|
||||||
),
|
),
|
||||||
@@ -51,8 +53,7 @@ class _UserServiceScreenState extends State<UserServiceScreen> {
|
|||||||
final service = state.service;
|
final service = state.service;
|
||||||
return FutureBuilder(
|
return FutureBuilder(
|
||||||
future: _getUserAndProfessionalInfo(service),
|
future: _getUserAndProfessionalInfo(service),
|
||||||
builder: (BuildContext context,
|
builder: (BuildContext context, AsyncSnapshot<List<dynamic>> snapshot) {
|
||||||
AsyncSnapshot<List<dynamic>> snapshot) {
|
|
||||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||||
return const Center(child: CircularProgressIndicator());
|
return const Center(child: CircularProgressIndicator());
|
||||||
} else {
|
} else {
|
||||||
@@ -153,9 +154,11 @@ class _UserServiceScreenState extends State<UserServiceScreen> {
|
|||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
formatCurrency(int.tryParse(service.rate) ?? 0),
|
formatCurrency(
|
||||||
|
int.tryParse(service.rate) ?? 0),
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
fontWeight: FontWeight.w600, fontSize: 25),
|
fontWeight: FontWeight.w600,
|
||||||
|
fontSize: 25),
|
||||||
),
|
),
|
||||||
const Text('Tarifa de consulta'),
|
const Text('Tarifa de consulta'),
|
||||||
const SizedBox(height: 15),
|
const SizedBox(height: 15),
|
||||||
@@ -184,8 +187,8 @@ class _UserServiceScreenState extends State<UserServiceScreen> {
|
|||||||
Visibility(
|
Visibility(
|
||||||
visible: professionalInfo
|
visible: professionalInfo
|
||||||
.paymentMethods.nequi,
|
.paymentMethods.nequi,
|
||||||
child:
|
child: const Chip(
|
||||||
const Chip(label: Text('Nequi')),
|
label: Text('Nequi')),
|
||||||
),
|
),
|
||||||
Visibility(
|
Visibility(
|
||||||
visible: professionalInfo
|
visible: professionalInfo
|
||||||
@@ -224,8 +227,10 @@ class _UserServiceScreenState extends State<UserServiceScreen> {
|
|||||||
),
|
),
|
||||||
service.description.isEmpty
|
service.description.isEmpty
|
||||||
? const SizedBox()
|
? const SizedBox()
|
||||||
: SizedBox(
|
: Container(
|
||||||
width: MediaQuery.of(context).size.width * 0.8,
|
alignment: Alignment.center,
|
||||||
|
width:
|
||||||
|
MediaQuery.of(context).size.width * 0.8,
|
||||||
child: Text(
|
child: Text(
|
||||||
'"${service.description.trim()}"',
|
'"${service.description.trim()}"',
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
@@ -254,6 +259,7 @@ class _UserServiceScreenState extends State<UserServiceScreen> {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -366,14 +372,12 @@ class _UserServiceScreenState extends State<UserServiceScreen> {
|
|||||||
return '\$${formatter.format(number)}';
|
return '\$${formatter.format(number)}';
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List<dynamic>> _getUserAndProfessionalInfo(
|
Future<List<dynamic>> _getUserAndProfessionalInfo(ServiceEntity service) async {
|
||||||
ServiceEntity service) async {
|
|
||||||
final userRepo = FirebaseUserRepository(FirebaseAuth.instance);
|
final userRepo = FirebaseUserRepository(FirebaseAuth.instance);
|
||||||
final userInfo = await userRepo.getMyUser(service.professionalId);
|
final userInfo = await userRepo.getMyUser(service.professionalId);
|
||||||
|
|
||||||
final professionalRepo = FirebaseProfessionalRepository();
|
final professionalRepo = FirebaseProfessionalRepository();
|
||||||
final professionalInfo =
|
final professionalInfo = await professionalRepo.getProInfo(service.professionalId);
|
||||||
await professionalRepo.getProInfo(service.professionalId);
|
|
||||||
|
|
||||||
return [userInfo, professionalInfo];
|
return [userInfo, professionalInfo];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
class UserServicesScreen extends StatelessWidget {
|
|
||||||
const UserServicesScreen({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Scaffold(
|
|
||||||
appBar: AppBar(
|
|
||||||
title: const Text('Mis servicios'),
|
|
||||||
),
|
|
||||||
body: const Center(
|
|
||||||
child: Text('Servicios'),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+17
@@ -189,4 +189,21 @@ class FirebaseProfessionalRepository {
|
|||||||
rethrow;
|
rethrow;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<List<ProfessionalEntity>> getProfessionsFromIds(
|
||||||
|
Iterable<String> ids) async {
|
||||||
|
try {
|
||||||
|
// Realizar una consulta única para obtener la información de todos los usuarios
|
||||||
|
final querySnapshot = await professionalCollection
|
||||||
|
.where(FieldPath.documentId, whereIn: ids)
|
||||||
|
.get();
|
||||||
|
|
||||||
|
return querySnapshot.docs
|
||||||
|
.map((e) => ProfessionalEntity.fromDocument(e.data()))
|
||||||
|
.toList();
|
||||||
|
} catch (e) {
|
||||||
|
log('getProfessionsFromIds ${e.toString()}');
|
||||||
|
rethrow;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,13 @@ class FirebaseServiceRepository {
|
|||||||
return docRef.id;
|
return docRef.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> updateServiceStatus(
|
||||||
|
String serviceId, ServiceStatus newStatus) async {
|
||||||
|
await serviceCollection
|
||||||
|
.doc(serviceId)
|
||||||
|
.update({'status': enumToIntService(newStatus)});
|
||||||
|
}
|
||||||
|
|
||||||
Stream<ServiceEntity> getService(String serviceId) {
|
Stream<ServiceEntity> getService(String serviceId) {
|
||||||
return serviceCollection.doc(serviceId).snapshots().map((snapshot) {
|
return serviceCollection.doc(serviceId).snapshots().map((snapshot) {
|
||||||
if (snapshot.exists) {
|
if (snapshot.exists) {
|
||||||
@@ -21,10 +28,12 @@ class FirebaseServiceRepository {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> updateServiceStatus(
|
Stream<List<ServiceEntity>> getServicesForUser(String userId) {
|
||||||
String serviceId, ServiceStatus newStatus) async {
|
return serviceCollection
|
||||||
await serviceCollection
|
.where('user_id', isEqualTo: userId)
|
||||||
.doc(serviceId)
|
.snapshots()
|
||||||
.update({'status': enumToIntService(newStatus)});
|
.map((querySnapshot) => querySnapshot.docs
|
||||||
|
.map((doc) => ServiceEntity.fromDocument(doc.data()))
|
||||||
|
.toList());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -403,4 +403,20 @@ class FirebaseUserRepository implements UserRepository {
|
|||||||
rethrow;
|
rethrow;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<List<MyUser>> getUsersFromIds(Iterable<String> ids) async {
|
||||||
|
try {
|
||||||
|
// Realizar una consulta única para obtener la información de todos los usuarios
|
||||||
|
final querySnapshot =
|
||||||
|
await usersCollection.where(FieldPath.documentId, whereIn: ids).get();
|
||||||
|
|
||||||
|
return querySnapshot.docs
|
||||||
|
.map((e) => MyUser.fromEntity(MyUserEntity.fromDocument(e.data())))
|
||||||
|
.toList();
|
||||||
|
} catch (e) {
|
||||||
|
log('getUsersFromIds ${e.toString()}');
|
||||||
|
rethrow;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,6 +45,8 @@ abstract class UserRepository {
|
|||||||
Future<void> createUser(MyUser myUser);
|
Future<void> createUser(MyUser myUser);
|
||||||
|
|
||||||
Future<List<MyUser>> getUsersProfessionalActive();
|
Future<List<MyUser>> getUsersProfessionalActive();
|
||||||
|
|
||||||
|
Future<List<MyUser>> getUsersFromIds(Iterable<String> ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
enum UpdatePassworErros { credentialsWrong, userNotFound, unknown }
|
enum UpdatePassworErros { credentialsWrong, userNotFound, unknown }
|
||||||
|
|||||||
Reference in New Issue
Block a user