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,6 +755,14 @@ class _ProfessionalServiceScreenState extends State<ProfessionalServiceScreen> {
service.range1Hour2.minute, service.range1Hour2.minute,
); );
if (now.isAfter(serviceDateTime)) {
return GeneralSecondaryButton(
label: 'Volver',
onPressed: () {
Navigator.pop(context);
},
);
} else {
if (service.status == ServiceStatus.pending) { if (service.status == ServiceStatus.pending) {
return Column( return Column(
children: [ children: [
@@ -783,22 +792,27 @@ class _ProfessionalServiceScreenState extends State<ProfessionalServiceScreen> {
); );
} }
if (now.isAfter(serviceDateTime)) { if (service.status == ServiceStatus.acepted) {
if (serviceDateTime.difference(now).inHours > 1) {
return GeneralSecondaryButton( return GeneralSecondaryButton(
label: 'Volver', label: 'Cancelar servicio',
color: Theme.of(context).colorScheme.error,
onPressed: () { onPressed: () {
Navigator.pop(context); final currentState = context.read<ServiceBloc>().state;
if (currentState is ServiceLoaded) {
context.read<ServiceBloc>().add(UpdateServiceStatus(
widget.serviceId, ServiceStatus.cancelled));
}
}, },
); );
} else { } else {
if (service.status == ServiceStatus.acepted) {
return GeneralSecondaryButton( return GeneralSecondaryButton(
label: 'Iniciar servicio', label: 'Iniciar servicio',
onPressed: () { onPressed: () {
final currentState = context.read<ServiceBloc>().state; final currentState = context.read<ServiceBloc>().state;
if (currentState is ServiceLoaded) { if (currentState is ServiceLoaded) {
context.read<ServiceBloc>().add( context.read<ServiceBloc>().add(UpdateServiceStatus(
UpdateServiceStatus(widget.serviceId, ServiceStatus.active)); widget.serviceId, ServiceStatus.active));
} }
}, },
); );
@@ -816,6 +830,7 @@ class _ProfessionalServiceScreenState extends State<ProfessionalServiceScreen> {
} }
}); });
} }
}
return GeneralSecondaryButton( return GeneralSecondaryButton(
label: 'Volver', label: 'Volver',
+78 -49
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) {
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(
label: 'Volver',
onPressed: () {
Navigator.pop(context);
},
);
} else {
if (service.status == ServiceStatus.pending) { if (service.status == ServiceStatus.pending) {
return ElevatedButton( return GeneralSecondaryButton(
label: 'Cancelar servicio',
color: Theme.of(context).colorScheme.error,
onPressed: () { onPressed: () {
final currentState = context.read<ServiceBloc>().state; final currentState = context.read<ServiceBloc>().state;
if (currentState is ServiceLoaded) { if (currentState is ServiceLoaded) {
context.read<ServiceBloc>().add( context.read<ServiceBloc>().add(UpdateServiceStatus(
UpdateServiceStatus( widget.serviceId, ServiceStatus.cancelled));
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),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
),
child: Container(
alignment: Alignment.center,
child: const Text(
'Cancelar servicio',
style: TextStyle(
color: Colors.white,
fontSize: 18,
),
),
),
); );
} }
return ElevatedButton( if (service.status == ServiceStatus.acepted) {
if (serviceDateTime.difference(now).inDays > 1) {
return GeneralSecondaryButton(
label: 'Cancelar servicio',
color: Theme.of(context).colorScheme.error,
onPressed: () { onPressed: () {
final currentState = context.read<ServiceBloc>().state; final currentState = context.read<ServiceBloc>().state;
if (currentState is ServiceLoaded) { if (currentState is ServiceLoaded) {
context.read<ServiceBloc>().add( context.read<ServiceBloc>().add(UpdateServiceStatus(
UpdateServiceStatus( widget.serviceId, ServiceStatus.cancelled));
widget.serviceId, }
ServiceStatus.cancelled,
), if (userInfo.token != null) {
LocalNotifications.sendPushNotification(
userInfo.token!,
'Servicio cancelado',
'Servicio cancelado por ${userInfo.name}',
); );
} }
}, },
style: FilledButton.styleFrom( );
backgroundColor: Theme.of(context).colorScheme.primary, }
padding: const EdgeInsets.symmetric(vertical: 15), }
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10), if (service.status == ServiceStatus.active) {
), return GeneralSecondaryButton(
), label: 'Terminar servicio',
child: Container( onPressed: () {
alignment: Alignment.center, final currentState = context.read<ServiceBloc>().state;
child: const Text( if (currentState is ServiceLoaded) {
'Volver', context.read<ServiceBloc>().add(UpdateServiceStatus(
style: TextStyle( widget.serviceId, ServiceStatus.completed));
color: Colors.white, }
fontSize: 18, });
), }
), }
),
return GeneralSecondaryButton(
label: 'Volver',
onPressed: () {
Navigator.pop(context);
},
); );
} }
+126 -83
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,8 +535,21 @@ 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) {
if (now.isAfter(serviceDateTime)) {
return const SizedBox();
} else {
return Wrap( return Wrap(
alignment: WrapAlignment.center, alignment: WrapAlignment.center,
spacing: 15, spacing: 15,
@@ -553,12 +580,14 @@ class _UserServiceScreenState extends State<UserServiceScreen> {
), ),
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( style: ElevatedButton.styleFrom(
foregroundColor: const Color(0xFF2BA4EC), foregroundColor: const Color(0xFF2BA4EC),
@@ -612,23 +641,44 @@ class _UserServiceScreenState extends State<UserServiceScreen> {
], ],
); );
} }
}
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);
DateTime now = DateTime.now();
DateTime serviceDateTime = DateTime(
serviceDate.year,
serviceDate.month,
serviceDate.day,
service.range1Hour2.hour,
service.range1Hour2.minute,
);
if (now.isAfter(serviceDateTime)) {
return Stack( return Stack(
alignment: AlignmentDirectional.topCenter, alignment: AlignmentDirectional.topCenter,
clipBehavior: Clip.none, clipBehavior: Clip.none,
children: [ children: [
Card( Card(
color: Colors.green.shade50, color: Colors.red.shade100,
child: const Padding( child: const Padding(
padding: EdgeInsets.fromLTRB(32, 56, 32, 32), padding: EdgeInsets.fromLTRB(32, 56, 32, 32),
child: Text( child: Column(
'Servicio enviado', mainAxisAlignment: MainAxisAlignment.center,
style: TextStyle(fontSize: 32, color: Colors.green), 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),
),
],
), ),
), ),
), ),
@@ -638,46 +688,16 @@ 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(Icons.mark_email_read_rounded, child:
color: Colors.green, size: 48), const Icon(Icons.close_rounded, color: Colors.red, size: 48),
), ),
) )
], ],
); );
} } else {
// 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) { if (service.status == ServiceStatus.cancelled) {
return Stack( return Stack(
alignment: AlignmentDirectional.topCenter, alignment: AlignmentDirectional.topCenter,
@@ -702,8 +722,8 @@ class _UserServiceScreenState extends State<UserServiceScreen> {
border: Border.all(color: Colors.red.shade100, width: 4), border: Border.all(color: Colors.red.shade100, width: 4),
shape: BoxShape.circle, shape: BoxShape.circle,
), ),
child: child: const Icon(Icons.close_rounded,
const Icon(Icons.close_rounded, color: Colors.red, size: 48), color: Colors.red, size: 48),
), ),
) )
], ],
@@ -733,50 +753,16 @@ class _UserServiceScreenState extends State<UserServiceScreen> {
border: Border.all(color: Colors.red.shade100, width: 4), border: Border.all(color: Colors.red.shade100, width: 4),
shape: BoxShape.circle, shape: BoxShape.circle,
), ),
child: child: const Icon(Icons.close_rounded,
const Icon(Icons.close_rounded, color: Colors.red, size: 48), 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 && if (service.status == ServiceStatus.completed &&
service.professionalScored == false) { service.userScored == false) {
return Stack( return Stack(
alignment: AlignmentDirectional.topCenter, alignment: AlignmentDirectional.topCenter,
clipBehavior: Clip.none, clipBehavior: Clip.none,
@@ -851,7 +837,7 @@ class _UserServiceScreenState extends State<UserServiceScreen> {
} }
if (service.status == ServiceStatus.completed && if (service.status == ServiceStatus.completed &&
service.professionalScored == true) { service.userScored == true) {
return Stack( return Stack(
alignment: AlignmentDirectional.topCenter, alignment: AlignmentDirectional.topCenter,
clipBehavior: Clip.none, clipBehavior: Clip.none,
@@ -889,12 +875,31 @@ class _UserServiceScreenState extends State<UserServiceScreen> {
], ],
); );
} }
}
return const SizedBox(); return const SizedBox();
} }
Widget customButton( Widget customButton(
ServiceEntity service, BuildContext context, MyUser userInfo) { ServiceEntity service, BuildContext context, MyUser userInfo) {
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(
label: 'Volver',
onPressed: () {
Navigator.pop(context);
},
);
} else {
if (service.status == ServiceStatus.pending) { if (service.status == ServiceStatus.pending) {
return GeneralSecondaryButton( return GeneralSecondaryButton(
label: 'Cancelar servicio', label: 'Cancelar servicio',
@@ -902,8 +907,8 @@ class _UserServiceScreenState extends State<UserServiceScreen> {
onPressed: () { onPressed: () {
final currentState = context.read<ServiceBloc>().state; final currentState = context.read<ServiceBloc>().state;
if (currentState is ServiceLoaded) { if (currentState is ServiceLoaded) {
context.read<ServiceBloc>().add( context.read<ServiceBloc>().add(UpdateServiceStatus(
UpdateServiceStatus(widget.serviceId, ServiceStatus.cancelled)); widget.serviceId, ServiceStatus.cancelled));
} }
if (userInfo.token != null) { if (userInfo.token != null) {
@@ -917,11 +922,49 @@ class _UserServiceScreenState extends State<UserServiceScreen> {
); );
} }
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', label: 'Volver',
onPressed: () { onPressed: () {
Navigator.pop(context); Navigator.pop(context);
}); },
);
} }
String formatCurrency(int number) { String formatCurrency(int number) {
+285 -62
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) {
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 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) { if (service.status == ServiceStatus.cancelled) {
return const Center( 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( child: Column(
children: [ children: [
Padding( const Text(
padding: EdgeInsets.symmetric(vertical: 20), 'Completado',
child: Icon( style: TextStyle(fontSize: 32, color: Colors.green),
CupertinoIcons.xmark_circle, ),
color: Color(0xFF35A8ED), const Text(
size: 70, '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,
), ),
), ),
Text( );
'Servicio cancelado exitosamente', },
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( style: TextStyle(
color: Color(0xFF35A8ED), color: Colors.white,
fontSize: 17, fontSize: 18,
fontWeight: FontWeight.w600, ),
),
), ),
), ),
], ],
), ),
),
),
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) { if (service.status == ServiceStatus.completed &&
return const Center( 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( child: Column(
children: [ children: [
Padding(
padding: EdgeInsets.symmetric(vertical: 20),
child: Icon(
Icons.favorite_outline_sharp,
color: Color(0xFF35A8ED),
size: 70,
),
),
Text( Text(
'Servicio terminado exitosamente', 'Completado',
style: TextStyle( style: TextStyle(fontSize: 32, color: Colors.green),
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( Positioned(
'Servicio solicitado exitosamente', top: -40,
style: TextStyle( child: Container(
color: Color(0xFF35A8ED), padding: const EdgeInsets.all(16),
fontSize: 17, decoration: BoxDecoration(
fontWeight: FontWeight.w600, 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,
), ),
), ),
)
], ],
),
); );
} }
}
GeneralSecondaryButton customButton( return const SizedBox();
}
Widget customButton(
ServiceEntity service, BuildContext context, MyUser userInfo) { ServiceEntity service, BuildContext context, MyUser userInfo) {
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(
label: 'Volver',
onPressed: () {
Navigator.pop(context);
},
);
} else {
if (service.status == ServiceStatus.pending) { if (service.status == ServiceStatus.pending) {
return GeneralSecondaryButton( return GeneralSecondaryButton(
label: 'Cancelar servicio',
color: Theme.of(context).colorScheme.error,
onPressed: () { onPressed: () {
final currentState = context.read<ServiceBloc>().state; final currentState = context.read<ServiceBloc>().state;
if (currentState is ServiceLoaded) { if (currentState is ServiceLoaded) {
context.read<ServiceBloc>().add( context.read<ServiceBloc>().add(UpdateServiceStatus(
UpdateServiceStatus( widget.serviceId, ServiceStatus.cancelled));
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( 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: () { onPressed: () {
Navigator.pop(context); Navigator.pop(context);
}, },
label: 'Volver',
); );
} }