botones etc

This commit is contained in:
Felipe
2024-05-27 10:47:41 -05:00
parent bec1aaef21
commit a678167bc5
4 changed files with 840 additions and 530 deletions
@@ -329,7 +329,8 @@ class _ProfessionalServiceScreenState extends State<ProfessionalServiceScreen> {
service.range1Hour2.minute, service.range1Hour2.minute,
); );
if (service.status == ServiceStatus.acepted || service.status == ServiceStatus.active) { if (service.status == ServiceStatus.acepted ||
service.status == ServiceStatus.active) {
if (now.isAfter(serviceDateTime)) { if (now.isAfter(serviceDateTime)) {
return const SizedBox(); return const SizedBox();
} else { } else {
@@ -754,35 +755,6 @@ class _ProfessionalServiceScreenState extends State<ProfessionalServiceScreen> {
service.range1Hour2.minute, service.range1Hour2.minute,
); );
if (service.status == ServiceStatus.pending) {
return Column(
children: [
GeneralSecondaryButton(
label: 'Rechazar servicio',
color: Theme.of(context).colorScheme.error,
onPressed: () {
final currentState = context.read<ServiceBloc>().state;
if (currentState is ServiceLoaded) {
context.read<ServiceBloc>().add(UpdateServiceStatus(
widget.serviceId, ServiceStatus.denied));
}
},
),
const SizedBox(height: 10),
GeneralSecondaryButton(
label: 'Aceptar servicio',
onPressed: () {
final currentState = context.read<ServiceBloc>().state;
if (currentState is ServiceLoaded) {
context.read<ServiceBloc>().add(UpdateServiceStatus(
widget.serviceId, ServiceStatus.acepted));
}
},
),
],
);
}
if (now.isAfter(serviceDateTime)) { if (now.isAfter(serviceDateTime)) {
return GeneralSecondaryButton( return GeneralSecondaryButton(
label: 'Volver', label: 'Volver',
@@ -791,30 +763,73 @@ class _ProfessionalServiceScreenState extends State<ProfessionalServiceScreen> {
}, },
); );
} else { } else {
if (service.status == ServiceStatus.acepted) { if (service.status == ServiceStatus.pending) {
return GeneralSecondaryButton( return Column(
label: 'Iniciar servicio', children: [
onPressed: () { GeneralSecondaryButton(
final currentState = context.read<ServiceBloc>().state; label: 'Rechazar servicio',
if (currentState is ServiceLoaded) { color: Theme.of(context).colorScheme.error,
context.read<ServiceBloc>().add( onPressed: () {
UpdateServiceStatus(widget.serviceId, ServiceStatus.active)); final currentState = context.read<ServiceBloc>().state;
} if (currentState is ServiceLoaded) {
}, context.read<ServiceBloc>().add(UpdateServiceStatus(
widget.serviceId, ServiceStatus.denied));
}
},
),
const SizedBox(height: 10),
GeneralSecondaryButton(
label: 'Aceptar servicio',
onPressed: () {
final currentState = context.read<ServiceBloc>().state;
if (currentState is ServiceLoaded) {
context.read<ServiceBloc>().add(UpdateServiceStatus(
widget.serviceId, ServiceStatus.acepted));
}
},
),
],
); );
} }
}
if (service.status == ServiceStatus.active) { if (service.status == ServiceStatus.acepted) {
return GeneralSecondaryButton( if (serviceDateTime.difference(now).inHours > 1) {
label: 'Terminar servicio', return GeneralSecondaryButton(
onPressed: () { label: 'Cancelar servicio',
final currentState = context.read<ServiceBloc>().state; color: Theme.of(context).colorScheme.error,
if (currentState is ServiceLoaded) { onPressed: () {
context.read<ServiceBloc>().add(UpdateServiceStatus( final currentState = context.read<ServiceBloc>().state;
widget.serviceId, ServiceStatus.completed)); if (currentState is ServiceLoaded) {
} context.read<ServiceBloc>().add(UpdateServiceStatus(
}); widget.serviceId, ServiceStatus.cancelled));
}
},
);
} else {
return GeneralSecondaryButton(
label: 'Iniciar servicio',
onPressed: () {
final currentState = context.read<ServiceBloc>().state;
if (currentState is ServiceLoaded) {
context.read<ServiceBloc>().add(UpdateServiceStatus(
widget.serviceId, ServiceStatus.active));
}
},
);
}
}
if (service.status == ServiceStatus.active) {
return GeneralSecondaryButton(
label: 'Terminar servicio',
onPressed: () {
final currentState = context.read<ServiceBloc>().state;
if (currentState is ServiceLoaded) {
context.read<ServiceBloc>().add(UpdateServiceStatus(
widget.serviceId, ServiceStatus.completed));
}
});
}
} }
return GeneralSecondaryButton( return GeneralSecondaryButton(
+87 -58
View File
@@ -1,3 +1,5 @@
import 'dart:async';
import 'package:firebase_auth/firebase_auth.dart'; import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@@ -6,6 +8,7 @@ import 'package:injector/injector.dart';
import 'package:intl/intl.dart'; import 'package:intl/intl.dart';
import 'package:professional_repository/professional_repository.dart'; import 'package:professional_repository/professional_repository.dart';
import 'package:prosappco/blocs/service_bloc/service_bloc.dart'; import 'package:prosappco/blocs/service_bloc/service_bloc.dart';
import 'package:prosappco/components/general_secondary_button.dart';
import 'package:prosappco/local_notifications/local_notifications.dart'; import 'package:prosappco/local_notifications/local_notifications.dart';
import 'package:service_repository/service_repository.dart'; import 'package:service_repository/service_repository.dart';
import 'package:setting_repository/setting_repository.dart'; import 'package:setting_repository/setting_repository.dart';
@@ -22,12 +25,20 @@ class ServiceScreen extends StatefulWidget {
class _ServiceScreenState extends State<ServiceScreen> { class _ServiceScreenState extends State<ServiceScreen> {
final settingRepository = Injector.appInstance.get<SettingRepository>(); final settingRepository = Injector.appInstance.get<SettingRepository>();
SettingEntity? settings; SettingEntity? settings;
Timer? _timer;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
_loadSettings(); _loadSettings();
_startTimer();
}
@override
void dispose() {
_timer?.cancel();
super.dispose();
} }
void _loadSettings() { void _loadSettings() {
@@ -38,6 +49,12 @@ class _ServiceScreenState extends State<ServiceScreen> {
); );
} }
void _startTimer() {
_timer = Timer.periodic(const Duration(minutes: 5), (timer) {
setState(() {});
});
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return BlocProvider<ServiceBloc>( return BlocProvider<ServiceBloc>(
@@ -373,19 +390,36 @@ class _ServiceScreenState extends State<ServiceScreen> {
); );
} }
ElevatedButton customButton( Widget customButton(
ServiceEntity service, BuildContext context, MyUser userInfo) { ServiceEntity service, BuildContext context, MyUser userInfo) {
if (service.status == ServiceStatus.pending) { DateTime serviceDate = DateTime.parse(service.day);
return ElevatedButton( DateTime now = DateTime.now();
DateTime serviceDateTime = DateTime(
serviceDate.year,
serviceDate.month,
serviceDate.day,
service.range1Hour2.hour,
service.range1Hour2.minute,
);
if (now.isAfter(serviceDateTime)) {
return GeneralSecondaryButton(
label: 'Volver',
onPressed: () { onPressed: () {
final currentState = context.read<ServiceBloc>().state; Navigator.pop(context);
if (currentState is ServiceLoaded) { },
context.read<ServiceBloc>().add( );
UpdateServiceStatus( } else {
widget.serviceId, if (service.status == ServiceStatus.pending) {
ServiceStatus.cancelled, return GeneralSecondaryButton(
), label: 'Cancelar servicio',
); color: Theme.of(context).colorScheme.error,
onPressed: () {
final currentState = context.read<ServiceBloc>().state;
if (currentState is ServiceLoaded) {
context.read<ServiceBloc>().add(UpdateServiceStatus(
widget.serviceId, ServiceStatus.cancelled));
}
if (userInfo.token != null) { if (userInfo.token != null) {
LocalNotifications.sendPushNotification( LocalNotifications.sendPushNotification(
@@ -394,57 +428,52 @@ class _ServiceScreenState extends State<ServiceScreen> {
'Servicio cancelado por ${userInfo.name}', 'Servicio cancelado por ${userInfo.name}',
); );
} }
} },
}, );
style: FilledButton.styleFrom( }
backgroundColor: Theme.of(context).colorScheme.error,
padding: const EdgeInsets.symmetric(vertical: 15), if (service.status == ServiceStatus.acepted) {
shape: RoundedRectangleBorder( if (serviceDateTime.difference(now).inDays > 1) {
borderRadius: BorderRadius.circular(10), return GeneralSecondaryButton(
), label: 'Cancelar servicio',
), color: Theme.of(context).colorScheme.error,
child: Container( onPressed: () {
alignment: Alignment.center, final currentState = context.read<ServiceBloc>().state;
child: const Text( if (currentState is ServiceLoaded) {
'Cancelar servicio', context.read<ServiceBloc>().add(UpdateServiceStatus(
style: TextStyle( widget.serviceId, ServiceStatus.cancelled));
color: Colors.white, }
fontSize: 18,
), if (userInfo.token != null) {
), LocalNotifications.sendPushNotification(
), userInfo.token!,
); 'Servicio cancelado',
'Servicio cancelado por ${userInfo.name}',
);
}
},
);
}
}
if (service.status == ServiceStatus.active) {
return GeneralSecondaryButton(
label: 'Terminar servicio',
onPressed: () {
final currentState = context.read<ServiceBloc>().state;
if (currentState is ServiceLoaded) {
context.read<ServiceBloc>().add(UpdateServiceStatus(
widget.serviceId, ServiceStatus.completed));
}
});
}
} }
return ElevatedButton( return GeneralSecondaryButton(
label: 'Volver',
onPressed: () { onPressed: () {
final currentState = context.read<ServiceBloc>().state; Navigator.pop(context);
if (currentState is ServiceLoaded) {
context.read<ServiceBloc>().add(
UpdateServiceStatus(
widget.serviceId,
ServiceStatus.cancelled,
),
);
}
}, },
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,
child: const Text(
'Volver',
style: TextStyle(
color: Colors.white,
fontSize: 18,
),
),
),
); );
} }
+373 -330
View File
@@ -1,3 +1,4 @@
import 'dart:async';
import 'package:community_material_icon/community_material_icon.dart'; import 'package:community_material_icon/community_material_icon.dart';
import 'package:firebase_auth/firebase_auth.dart'; import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
@@ -7,7 +8,6 @@ import 'package:injector/injector.dart';
import 'package:intl/intl.dart'; import 'package:intl/intl.dart';
import 'package:professional_repository/professional_repository.dart'; import 'package:professional_repository/professional_repository.dart';
import 'package:prosappco/blocs/service_bloc/service_bloc.dart'; import 'package:prosappco/blocs/service_bloc/service_bloc.dart';
import 'package:prosappco/components/drawer_reputation.dart';
import 'package:prosappco/components/general_reputation.dart'; import 'package:prosappco/components/general_reputation.dart';
import 'package:prosappco/local_notifications/local_notifications.dart'; import 'package:prosappco/local_notifications/local_notifications.dart';
import 'package:prosappco/screens/chat/chat_screen.dart'; import 'package:prosappco/screens/chat/chat_screen.dart';
@@ -30,12 +30,20 @@ class UserServiceScreen extends StatefulWidget {
class _UserServiceScreenState extends State<UserServiceScreen> { class _UserServiceScreenState extends State<UserServiceScreen> {
final settingRepository = Injector.appInstance.get<SettingRepository>(); final settingRepository = Injector.appInstance.get<SettingRepository>();
SettingEntity? settings; SettingEntity? settings;
Timer? _timer;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
_loadSettings(); _loadSettings();
_startTimer();
}
@override
void dispose() {
_timer?.cancel();
super.dispose();
} }
void _loadSettings() { void _loadSettings() {
@@ -46,6 +54,12 @@ class _UserServiceScreenState extends State<UserServiceScreen> {
); );
} }
void _startTimer() {
_timer = Timer.periodic(const Duration(minutes: 5), (timer) {
setState(() {});
});
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return BlocProvider<ServiceBloc>( return BlocProvider<ServiceBloc>(
@@ -521,72 +535,58 @@ class _UserServiceScreenState extends State<UserServiceScreen> {
} }
Widget customActionButtons(ServiceEntity service, MyUser user) { Widget customActionButtons(ServiceEntity service, MyUser user) {
DateTime serviceDate = DateTime.parse(service.day);
DateTime now = DateTime.now();
DateTime serviceDateTime = DateTime(
serviceDate.year,
serviceDate.month,
serviceDate.day,
service.range1Hour2.hour,
service.range1Hour2.minute,
);
if (service.status == ServiceStatus.acepted || if (service.status == ServiceStatus.acepted ||
service.status == ServiceStatus.active) { service.status == ServiceStatus.active) {
return Wrap( if (now.isAfter(serviceDateTime)) {
alignment: WrapAlignment.center, return const SizedBox();
spacing: 15, } else {
children: [ return Wrap(
Visibility( alignment: WrapAlignment.center,
visible: user.phone == null ? false : true, spacing: 15,
child: ElevatedButton( children: [
onPressed: () => launch("tel:${user.phone}"), Visibility(
style: ElevatedButton.styleFrom( visible: user.phone == null ? false : true,
foregroundColor: const Color(0xFF2BA4EC), child: ElevatedButton(
backgroundColor: Colors.white, onPressed: () => launch("tel:${user.phone}"),
shape: const CircleBorder( style: ElevatedButton.styleFrom(
side: BorderSide( 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), 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(
ElevatedButton( onPressed: () {
onPressed: () { if (service.id != null) {
Navigator.push( Navigator.push(
context, context,
CupertinoPageRoute( CupertinoPageRoute(
builder: (context) => ChatScreen(service: service), builder: (context) => ChatScreen(service: service),
), ),
); );
},
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( style: ElevatedButton.styleFrom(
@@ -602,269 +602,81 @@ class _UserServiceScreenState extends State<UserServiceScreen> {
child: const Padding( child: const Padding(
padding: EdgeInsets.symmetric(vertical: 20, horizontal: 0), padding: EdgeInsets.symmetric(vertical: 20, horizontal: 0),
child: Icon( child: Icon(
CommunityMaterialIcons.whatsapp, Icons.message,
size: 30, size: 30,
color: Color(0xFF2BA4EC), 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(); return const SizedBox();
} }
Widget customMessageStatus(ServiceEntity service) { Widget customMessageStatus(ServiceEntity service) {
if (service.status == ServiceStatus.pending) { DateTime serviceDate = DateTime.parse(service.day);
return Stack( DateTime now = DateTime.now();
alignment: AlignmentDirectional.topCenter, DateTime serviceDateTime = DateTime(
clipBehavior: Clip.none, serviceDate.year,
children: [ serviceDate.month,
Card( serviceDate.day,
color: Colors.green.shade50, service.range1Hour2.hour,
child: const Padding( service.range1Hour2.minute,
padding: EdgeInsets.fromLTRB(32, 56, 32, 32), );
child: Text(
'Servicio enviado', if (now.isAfter(serviceDateTime)) {
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.mark_email_read_rounded,
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( return Stack(
alignment: AlignmentDirectional.topCenter, alignment: AlignmentDirectional.topCenter,
clipBehavior: Clip.none, clipBehavior: Clip.none,
children: [ children: [
Card( Card(
color: Colors.red.shade100, color: Colors.red.shade100,
child: const Padding(
padding: EdgeInsets.fromLTRB(32, 56, 32, 32),
child: Text(
'Cancelado',
style: TextStyle(fontSize: 32, color: Colors.red),
),
),
),
Positioned(
top: -40,
child: Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(color: Colors.red.shade100, width: 4),
shape: BoxShape.circle,
),
child:
const Icon(Icons.close_rounded, color: Colors.red, size: 48),
),
)
],
);
}
if (service.status == ServiceStatus.denied) {
return Stack(
alignment: AlignmentDirectional.topCenter,
clipBehavior: Clip.none,
children: [
Card(
color: Colors.red.shade100,
child: const Padding(
padding: EdgeInsets.fromLTRB(32, 56, 32, 32),
child: Text(
'Rechazado',
style: TextStyle(fontSize: 32, color: Colors.red),
),
),
),
Positioned(
top: -40,
child: Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(color: Colors.red.shade100, width: 4),
shape: BoxShape.circle,
),
child:
const Icon(Icons.close_rounded, color: Colors.red, 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 &&
service.professionalScored == 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,
),
),
);
},
style: FilledButton.styleFrom(
backgroundColor: Colors.green,
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( child: const Padding(
padding: EdgeInsets.fromLTRB(32, 56, 32, 32), padding: EdgeInsets.fromLTRB(32, 56, 32, 32),
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
Text( Text(
'Completado', 'Caducado',
style: TextStyle(fontSize: 32, color: Colors.green), style: TextStyle(fontSize: 32, color: Colors.red),
),
Text(
'Tu servicio ha excedido \n el tiempo de espera',
textAlign: TextAlign.center,
style: TextStyle(fontSize: 18, color: Colors.red),
), ),
], ],
), ),
@@ -876,18 +688,193 @@ class _UserServiceScreenState extends State<UserServiceScreen> {
padding: const EdgeInsets.all(16), padding: const EdgeInsets.all(16),
decoration: BoxDecoration( decoration: BoxDecoration(
color: Colors.white, color: Colors.white,
border: Border.all(color: Colors.green.shade50, width: 4), border: Border.all(color: Colors.red.shade100, width: 4),
shape: BoxShape.circle, shape: BoxShape.circle,
), ),
child: const Icon( child:
Icons.star, const Icon(Icons.close_rounded, color: Colors.red, size: 48),
color: Colors.green,
size: 48,
),
), ),
) )
], ],
); );
} else {
if (service.status == ServiceStatus.cancelled) {
return Stack(
alignment: AlignmentDirectional.topCenter,
clipBehavior: Clip.none,
children: [
Card(
color: Colors.red.shade100,
child: const Padding(
padding: EdgeInsets.fromLTRB(32, 56, 32, 32),
child: Text(
'Cancelado',
style: TextStyle(fontSize: 32, color: Colors.red),
),
),
),
Positioned(
top: -40,
child: Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(color: Colors.red.shade100, width: 4),
shape: BoxShape.circle,
),
child: const Icon(Icons.close_rounded,
color: Colors.red, size: 48),
),
)
],
);
}
if (service.status == ServiceStatus.denied) {
return Stack(
alignment: AlignmentDirectional.topCenter,
clipBehavior: Clip.none,
children: [
Card(
color: Colors.red.shade100,
child: const Padding(
padding: EdgeInsets.fromLTRB(32, 56, 32, 32),
child: Text(
'Rechazado',
style: TextStyle(fontSize: 32, color: Colors.red),
),
),
),
Positioned(
top: -40,
child: Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(color: Colors.red.shade100, width: 4),
shape: BoxShape.circle,
),
child: const Icon(Icons.close_rounded,
color: Colors.red, size: 48),
),
)
],
);
}
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,
),
),
);
},
style: FilledButton.styleFrom(
backgroundColor: Colors.green,
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.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(); return const SizedBox();
@@ -895,33 +882,89 @@ class _UserServiceScreenState extends State<UserServiceScreen> {
Widget customButton( Widget customButton(
ServiceEntity service, BuildContext context, MyUser userInfo) { ServiceEntity service, BuildContext context, MyUser userInfo) {
if (service.status == ServiceStatus.pending) { DateTime serviceDate = DateTime.parse(service.day);
DateTime now = DateTime.now();
DateTime serviceDateTime = DateTime(
serviceDate.year,
serviceDate.month,
serviceDate.day,
service.range1Hour2.hour,
service.range1Hour2.minute,
);
if (now.isAfter(serviceDateTime)) {
return GeneralSecondaryButton( return GeneralSecondaryButton(
label: 'Cancelar servicio',
color: Theme.of(context).colorScheme.error,
onPressed: () {
final currentState = context.read<ServiceBloc>().state;
if (currentState is ServiceLoaded) {
context.read<ServiceBloc>().add(
UpdateServiceStatus(widget.serviceId, ServiceStatus.cancelled));
}
if (userInfo.token != null) {
LocalNotifications.sendPushNotification(
userInfo.token!,
'Servicio cancelado',
'Servicio cancelado por ${userInfo.name}',
);
}
},
);
}
return GeneralSecondaryButton(
label: 'Volver', label: 'Volver',
onPressed: () { onPressed: () {
Navigator.pop(context); Navigator.pop(context);
}); },
);
} else {
if (service.status == ServiceStatus.pending) {
return GeneralSecondaryButton(
label: 'Cancelar servicio',
color: Theme.of(context).colorScheme.error,
onPressed: () {
final currentState = context.read<ServiceBloc>().state;
if (currentState is ServiceLoaded) {
context.read<ServiceBloc>().add(UpdateServiceStatus(
widget.serviceId, ServiceStatus.cancelled));
}
if (userInfo.token != null) {
LocalNotifications.sendPushNotification(
userInfo.token!,
'Servicio cancelado',
'Servicio cancelado por ${userInfo.name}',
);
}
},
);
}
if (service.status == ServiceStatus.acepted) {
if (serviceDateTime.difference(now).inDays > 1) {
return GeneralSecondaryButton(
label: 'Cancelar servicio',
color: Theme.of(context).colorScheme.error,
onPressed: () {
final currentState = context.read<ServiceBloc>().state;
if (currentState is ServiceLoaded) {
context.read<ServiceBloc>().add(UpdateServiceStatus(
widget.serviceId, ServiceStatus.cancelled));
}
if (userInfo.token != null) {
LocalNotifications.sendPushNotification(
userInfo.token!,
'Servicio cancelado',
'Servicio cancelado por ${userInfo.name}',
);
}
},
);
}
}
if (service.status == ServiceStatus.active) {
return GeneralSecondaryButton(
label: 'Terminar servicio',
onPressed: () {
final currentState = context.read<ServiceBloc>().state;
if (currentState is ServiceLoaded) {
context.read<ServiceBloc>().add(UpdateServiceStatus(
widget.serviceId, ServiceStatus.completed));
}
});
}
}
return GeneralSecondaryButton(
label: 'Volver',
onPressed: () {
Navigator.pop(context);
},
);
} }
String formatCurrency(int number) { String formatCurrency(int number) {
+314 -91
View File
@@ -1,5 +1,4 @@
import 'dart:developer'; import 'dart:async';
import 'package:firebase_auth/firebase_auth.dart'; import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@@ -8,9 +7,9 @@ import 'package:injector/injector.dart';
import 'package:intl/intl.dart'; import 'package:intl/intl.dart';
import 'package:professional_repository/professional_repository.dart'; import 'package:professional_repository/professional_repository.dart';
import 'package:prosappco/blocs/service_bloc/service_bloc.dart'; import 'package:prosappco/blocs/service_bloc/service_bloc.dart';
import 'package:prosappco/components/general_primary_button.dart';
import 'package:prosappco/components/general_secondary_button.dart'; import 'package:prosappco/components/general_secondary_button.dart';
import 'package:prosappco/local_notifications/local_notifications.dart'; import 'package:prosappco/local_notifications/local_notifications.dart';
import 'package:prosappco/screens/score/score_screen.dart';
import 'package:service_repository/service_repository.dart'; import 'package:service_repository/service_repository.dart';
import 'package:setting_repository/setting_repository.dart'; import 'package:setting_repository/setting_repository.dart';
import 'package:user_repository/user_repository.dart'; import 'package:user_repository/user_repository.dart';
@@ -27,12 +26,26 @@ class UserServiceScreen extends StatefulWidget {
class _UserServiceScreenState extends State<UserServiceScreen> { class _UserServiceScreenState extends State<UserServiceScreen> {
final settingRepository = Injector.appInstance.get<SettingRepository>(); final settingRepository = Injector.appInstance.get<SettingRepository>();
SettingEntity? settings; SettingEntity? settings;
Timer? _timer;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
_loadSettings(); _loadSettings();
_startTimer();
}
@override
void dispose() {
_timer?.cancel();
super.dispose();
}
void _startTimer() {
_timer = Timer.periodic(const Duration(minutes: 5), (timer) {
setState(() {});
});
} }
void _loadSettings() { void _loadSettings() {
@@ -277,94 +290,270 @@ class _UserServiceScreenState extends State<UserServiceScreen> {
); );
} }
Center customMessageStatus(ServiceEntity service) { Widget customMessageStatus(ServiceEntity service) {
if (service.status == ServiceStatus.cancelled) { DateTime serviceDate = DateTime.parse(service.day);
return const Center( DateTime now = DateTime.now();
child: Column( DateTime serviceDateTime = DateTime(
children: [ serviceDate.year,
Padding( serviceDate.month,
padding: EdgeInsets.symmetric(vertical: 20), serviceDate.day,
child: Icon( service.range1Hour2.hour,
CupertinoIcons.xmark_circle, service.range1Hour2.minute,
color: Color(0xFF35A8ED),
size: 70,
),
),
Text(
'Servicio cancelado exitosamente',
style: TextStyle(
color: Color(0xFF35A8ED),
fontSize: 17,
fontWeight: FontWeight.w600,
),
),
],
),
);
}
if (service.status == ServiceStatus.completed) {
return const Center(
child: Column(
children: [
Padding(
padding: EdgeInsets.symmetric(vertical: 20),
child: Icon(
Icons.favorite_outline_sharp,
color: Color(0xFF35A8ED),
size: 70,
),
),
Text(
'Servicio terminado exitosamente',
style: TextStyle(
color: Color(0xFF35A8ED),
fontSize: 17,
fontWeight: FontWeight.w600,
),
),
],
),
);
}
return const Center(
child: Column(
children: [
Padding(
padding: EdgeInsets.symmetric(vertical: 20),
child: Icon(
Icons.check_circle_outline_rounded,
color: Color(0xFF35A8ED),
size: 70,
),
),
Text(
'Servicio solicitado exitosamente',
style: TextStyle(
color: Color(0xFF35A8ED),
fontSize: 17,
fontWeight: FontWeight.w600,
),
),
],
),
); );
if (now.isAfter(serviceDateTime)) {
return Stack(
alignment: AlignmentDirectional.topCenter,
clipBehavior: Clip.none,
children: [
Card(
color: Colors.red.shade100,
child: const Padding(
padding: EdgeInsets.fromLTRB(32, 56, 32, 32),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'Caducado',
style: TextStyle(fontSize: 32, color: Colors.red),
),
Text(
'Tu servicio ha excedido \n el tiempo de espera',
textAlign: TextAlign.center,
style: TextStyle(fontSize: 18, color: Colors.red),
),
],
),
),
),
Positioned(
top: -40,
child: Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(color: Colors.red.shade100, width: 4),
shape: BoxShape.circle,
),
child:
const Icon(Icons.close_rounded, color: Colors.red, size: 48),
),
)
],
);
} else {
if (service.status == ServiceStatus.cancelled) {
return Stack(
alignment: AlignmentDirectional.topCenter,
clipBehavior: Clip.none,
children: [
Card(
color: Colors.red.shade100,
child: const Padding(
padding: EdgeInsets.fromLTRB(32, 56, 32, 32),
child: Text(
'Cancelado',
style: TextStyle(fontSize: 32, color: Colors.red),
),
),
),
Positioned(
top: -40,
child: Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(color: Colors.red.shade100, width: 4),
shape: BoxShape.circle,
),
child: const Icon(Icons.close_rounded,
color: Colors.red, size: 48),
),
)
],
);
}
if (service.status == ServiceStatus.denied) {
return Stack(
alignment: AlignmentDirectional.topCenter,
clipBehavior: Clip.none,
children: [
Card(
color: Colors.red.shade100,
child: const Padding(
padding: EdgeInsets.fromLTRB(32, 56, 32, 32),
child: Text(
'Rechazado',
style: TextStyle(fontSize: 32, color: Colors.red),
),
),
),
Positioned(
top: -40,
child: Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(color: Colors.red.shade100, width: 4),
shape: BoxShape.circle,
),
child: const Icon(Icons.close_rounded,
color: Colors.red, size: 48),
),
)
],
);
}
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,
),
),
);
},
style: FilledButton.styleFrom(
backgroundColor: Colors.green,
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.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();
} }
GeneralSecondaryButton customButton( Widget customButton(
ServiceEntity service, BuildContext context, MyUser userInfo) { ServiceEntity service, BuildContext context, MyUser userInfo) {
if (service.status == ServiceStatus.pending) { DateTime serviceDate = DateTime.parse(service.day);
DateTime now = DateTime.now();
DateTime serviceDateTime = DateTime(
serviceDate.year,
serviceDate.month,
serviceDate.day,
service.range1Hour2.hour,
service.range1Hour2.minute,
);
if (now.isAfter(serviceDateTime)) {
return GeneralSecondaryButton( return GeneralSecondaryButton(
label: 'Volver',
onPressed: () { onPressed: () {
final currentState = context.read<ServiceBloc>().state; Navigator.pop(context);
if (currentState is ServiceLoaded) { },
context.read<ServiceBloc>().add( );
UpdateServiceStatus( } else {
widget.serviceId, if (service.status == ServiceStatus.pending) {
ServiceStatus.cancelled, return GeneralSecondaryButton(
), label: 'Cancelar servicio',
); color: Theme.of(context).colorScheme.error,
onPressed: () {
final currentState = context.read<ServiceBloc>().state;
if (currentState is ServiceLoaded) {
context.read<ServiceBloc>().add(UpdateServiceStatus(
widget.serviceId, ServiceStatus.cancelled));
}
if (userInfo.token != null) { if (userInfo.token != null) {
LocalNotifications.sendPushNotification( LocalNotifications.sendPushNotification(
@@ -373,18 +562,52 @@ class _UserServiceScreenState extends State<UserServiceScreen> {
'Servicio cancelado por ${userInfo.name}', 'Servicio cancelado por ${userInfo.name}',
); );
} }
} },
}, );
color: Colors.red, }
label: 'Cancelar Servicio',
); if (service.status == ServiceStatus.acepted) {
if (serviceDateTime.difference(now).inDays > 1) {
return GeneralSecondaryButton(
label: 'Cancelar servicio',
color: Theme.of(context).colorScheme.error,
onPressed: () {
final currentState = context.read<ServiceBloc>().state;
if (currentState is ServiceLoaded) {
context.read<ServiceBloc>().add(UpdateServiceStatus(
widget.serviceId, ServiceStatus.cancelled));
}
if (userInfo.token != null) {
LocalNotifications.sendPushNotification(
userInfo.token!,
'Servicio cancelado',
'Servicio cancelado por ${userInfo.name}',
);
}
},
);
}
}
if (service.status == ServiceStatus.active) {
return GeneralSecondaryButton(
label: 'Terminar servicio',
onPressed: () {
final currentState = context.read<ServiceBloc>().state;
if (currentState is ServiceLoaded) {
context.read<ServiceBloc>().add(UpdateServiceStatus(
widget.serviceId, ServiceStatus.completed));
}
});
}
} }
return GeneralSecondaryButton( return GeneralSecondaryButton(
label: 'Volver',
onPressed: () { onPressed: () {
Navigator.pop(context); Navigator.pop(context);
}, },
label: 'Volver',
); );
} }