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
+87 -58
View File
@@ -1,3 +1,5 @@
import 'dart:async';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
@@ -6,6 +8,7 @@ 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_secondary_button.dart';
import 'package:prosappco/local_notifications/local_notifications.dart';
import 'package:service_repository/service_repository.dart';
import 'package:setting_repository/setting_repository.dart';
@@ -22,12 +25,20 @@ class ServiceScreen extends StatefulWidget {
class _ServiceScreenState extends State<ServiceScreen> {
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 _loadSettings() {
@@ -38,6 +49,12 @@ class _ServiceScreenState extends State<ServiceScreen> {
);
}
void _startTimer() {
_timer = Timer.periodic(const Duration(minutes: 5), (timer) {
setState(() {});
});
}
@override
Widget build(BuildContext context) {
return BlocProvider<ServiceBloc>(
@@ -373,19 +390,36 @@ class _ServiceScreenState extends State<ServiceScreen> {
);
}
ElevatedButton customButton(
Widget customButton(
ServiceEntity service, BuildContext context, MyUser userInfo) {
if (service.status == ServiceStatus.pending) {
return ElevatedButton(
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(
@@ -394,57 +428,52 @@ class _ServiceScreenState extends State<ServiceScreen> {
'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,
),
),
),
);
},
);
}
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 ElevatedButton(
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);
},
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,
),
),
),
);
}