botones etc
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import 'dart:developer';
|
||||
|
||||
import 'dart:async';
|
||||
import 'package:firebase_auth/firebase_auth.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -8,9 +7,9 @@ import 'package:injector/injector.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:professional_repository/professional_repository.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/local_notifications/local_notifications.dart';
|
||||
import 'package:prosappco/screens/score/score_screen.dart';
|
||||
import 'package:service_repository/service_repository.dart';
|
||||
import 'package:setting_repository/setting_repository.dart';
|
||||
import 'package:user_repository/user_repository.dart';
|
||||
@@ -27,12 +26,26 @@ class UserServiceScreen extends StatefulWidget {
|
||||
class _UserServiceScreenState extends State<UserServiceScreen> {
|
||||
final settingRepository = Injector.appInstance.get<SettingRepository>();
|
||||
SettingEntity? settings;
|
||||
Timer? _timer;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
_loadSettings();
|
||||
_startTimer();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_timer?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _startTimer() {
|
||||
_timer = Timer.periodic(const Duration(minutes: 5), (timer) {
|
||||
setState(() {});
|
||||
});
|
||||
}
|
||||
|
||||
void _loadSettings() {
|
||||
@@ -277,94 +290,270 @@ class _UserServiceScreenState extends State<UserServiceScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
Center customMessageStatus(ServiceEntity service) {
|
||||
if (service.status == ServiceStatus.cancelled) {
|
||||
return const Center(
|
||||
child: Column(
|
||||
children: [
|
||||
Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 20),
|
||||
child: Icon(
|
||||
CupertinoIcons.xmark_circle,
|
||||
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,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
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) {
|
||||
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) {
|
||||
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(
|
||||
label: 'Volver',
|
||||
onPressed: () {
|
||||
final currentState = context.read<ServiceBloc>().state;
|
||||
if (currentState is ServiceLoaded) {
|
||||
context.read<ServiceBloc>().add(
|
||||
UpdateServiceStatus(
|
||||
widget.serviceId,
|
||||
ServiceStatus.cancelled,
|
||||
),
|
||||
);
|
||||
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(
|
||||
@@ -373,18 +562,52 @@ class _UserServiceScreenState extends State<UserServiceScreen> {
|
||||
'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(
|
||||
label: 'Volver',
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
label: 'Volver',
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user