feat(ui): port web UI/UX improvements to mobile app
Port the 3 redesigned views from prosappweb to prosappco: - Solicitudes: modern cards with 4px colored left strip, status badge with icon+border, avatar with status-colored ring, date/time row, empty state - Calendario: card-wrapped TableCalendar with custom CalendarStyle (blue selected/ring today), day header card with date box + occupied/available stat pills, slot cards with colored strip and time badge instead of gradient circles - Perfil profesional: gradient banner header with profession pill + camera overlay, section cards with icon+title, payment method chips (animated) instead of checkboxes, schedule rows with colored active/inactive dots, theme-aware colors throughout (respects dark/light mode) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
1e962af6e8
commit
a65e671603
@@ -1,22 +1,33 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
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/screens/service/professional_service_screen.dart';
|
||||
import 'package:prosappco/utils/time_of_day_extension.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:table_calendar/table_calendar.dart';
|
||||
import 'package:injector/injector.dart';
|
||||
import 'package:professional_repository/professional_repository.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:prosappco/utils/time_of_day_utils.dart';
|
||||
import 'package:service_repository/service_repository.dart';
|
||||
import 'package:setting_repository/setting_repository.dart';
|
||||
import 'package:table_calendar/table_calendar.dart';
|
||||
|
||||
const _kPrimary = Color(0xFF1565C0);
|
||||
const _kAvailable = Color(0xFF16A34A);
|
||||
const _kOccupied = Color(0xFFDC2626);
|
||||
|
||||
extension _Th on BuildContext {
|
||||
ThemeData get _t => Theme.of(this);
|
||||
Color get bg => _t.scaffoldBackgroundColor;
|
||||
Color get card => _t.cardColor;
|
||||
Color get onSurface => _t.colorScheme.onSurface;
|
||||
Color get muted => _t.colorScheme.onSurface.withOpacity(0.55);
|
||||
Color get subtle => _t.colorScheme.onSurface.withOpacity(0.35);
|
||||
bool get isDark => _t.brightness == Brightness.dark;
|
||||
Color get shadow => isDark ? Colors.transparent : Colors.black.withOpacity(0.07);
|
||||
Color get shadowSm => isDark ? Colors.transparent : Colors.black.withOpacity(0.04);
|
||||
}
|
||||
|
||||
class ProfessionalCalendarScreen extends StatefulWidget {
|
||||
final ProfessionalEntity userProfessional;
|
||||
|
||||
const ProfessionalCalendarScreen({super.key, required this.userProfessional});
|
||||
|
||||
@override
|
||||
@@ -24,49 +35,28 @@ class ProfessionalCalendarScreen extends StatefulWidget {
|
||||
_ProfessionalCalendarScreenState();
|
||||
}
|
||||
|
||||
class _ProfessionalCalendarScreenState extends State<ProfessionalCalendarScreen> {
|
||||
final settingRepository = Injector.appInstance.get<SettingRepository>();
|
||||
final serviceRepository =
|
||||
Injector.appInstance.get<ApiServiceRepository>();
|
||||
SettingEntity? settings;
|
||||
class _ProfessionalCalendarScreenState
|
||||
extends State<ProfessionalCalendarScreen> {
|
||||
final serviceRepository = Injector.appInstance.get<ApiServiceRepository>();
|
||||
|
||||
DateTime today = DateTime.now();
|
||||
DateTime now = DateTime.now();
|
||||
late int numDay;
|
||||
|
||||
List<ServiceEntity>? _services;
|
||||
|
||||
CalendarFormat _calendarFormat = CalendarFormat.month;
|
||||
|
||||
bool isLoading = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
today = DateTime.utc(today.year, today.month, today.day);
|
||||
numDay = today.weekday;
|
||||
|
||||
_loadSettings();
|
||||
_loadServices();
|
||||
}
|
||||
|
||||
void _loadSettings() {
|
||||
settingRepository.getSettings().then(
|
||||
(value) => setState(() {
|
||||
settings = value;
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
void _loadServices() {
|
||||
serviceRepository
|
||||
.getServicesForProfessionalforCalendar(widget.userProfessional.id)
|
||||
.then((services) {
|
||||
setState(() {
|
||||
_services = services;
|
||||
});
|
||||
});
|
||||
.then((services) => setState(() => _services = services));
|
||||
}
|
||||
|
||||
void _onDaySelected(DateTime day, DateTime focusedDay) {
|
||||
@@ -76,86 +66,39 @@ class _ProfessionalCalendarScreenState extends State<ProfessionalCalendarScreen>
|
||||
});
|
||||
}
|
||||
|
||||
void _onFormatChange(CalendarFormat format) {
|
||||
setState(() {
|
||||
_calendarFormat = format;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
DateTime lastDay = today.add(const Duration(days: 365));
|
||||
final schedule = _scheduleFromDay(numDay);
|
||||
final slots = _buildSlots(schedule);
|
||||
final occupied =
|
||||
slots.where((t) => _isOccupied(t, _services, today)).length;
|
||||
final available = slots.length - occupied;
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: context.bg,
|
||||
appBar: AppBar(
|
||||
title: const Text('Calendario'),
|
||||
backgroundColor: _kPrimary,
|
||||
foregroundColor: Colors.white,
|
||||
elevation: 0,
|
||||
),
|
||||
floatingActionButtonLocation: kIsWeb
|
||||
? FloatingActionButtonLocation.startFloat
|
||||
: FloatingActionButtonLocation.endFloat,
|
||||
resizeToAvoidBottomInset: false,
|
||||
body: BlocProvider<ServiceBloc>(
|
||||
create: (context) => Injector.appInstance.get<ServiceBloc>(),
|
||||
child: BlocConsumer<ServiceBloc, ServiceState>(
|
||||
listener: (context, serviceState) {
|
||||
if (serviceState is CreateServiceLoading) {
|
||||
isLoading = true;
|
||||
}
|
||||
if (serviceState is CreateServiceFailure) {
|
||||
isLoading = false;
|
||||
}
|
||||
listener: (context, state) {
|
||||
if (state is CreateServiceLoading) isLoading = true;
|
||||
if (state is CreateServiceFailure) isLoading = false;
|
||||
},
|
||||
builder: (context, state) {
|
||||
return Column(
|
||||
return ListView(
|
||||
padding: const EdgeInsets.only(bottom: 32),
|
||||
children: [
|
||||
Container(
|
||||
color: const Color.fromARGB(255, 224, 247, 255),
|
||||
child: TableCalendar(
|
||||
locale: 'es_MX',
|
||||
firstDay: DateTime.now(),
|
||||
lastDay: lastDay,
|
||||
focusedDay: today,
|
||||
availableGestures: AvailableGestures.all,
|
||||
onDaySelected: _onDaySelected,
|
||||
selectedDayPredicate: (day) => isSameDay(day, today),
|
||||
calendarFormat: _calendarFormat,
|
||||
onFormatChanged: _onFormatChange,
|
||||
availableCalendarFormats: const {
|
||||
CalendarFormat.month: 'Mes',
|
||||
CalendarFormat.week: 'Semana',
|
||||
CalendarFormat.twoWeeks: '2 Semanas',
|
||||
},
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: Padding(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 15, vertical: 8),
|
||||
child: Text(
|
||||
DateFormat('dd MMMM yyyy', 'es').format(today),
|
||||
style: const TextStyle(
|
||||
color: Colors.black,
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const Divider(
|
||||
height: 0,
|
||||
),
|
||||
Expanded(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.only(bottom: 15),
|
||||
child: Column(
|
||||
children: [
|
||||
..._rangesItems(
|
||||
_getScheduleFromNumDay(numDay), context),
|
||||
],
|
||||
),
|
||||
),
|
||||
)
|
||||
_calendarCard(context),
|
||||
_dayHeader(context, schedule, slots.length, occupied, available),
|
||||
if (slots.isEmpty)
|
||||
_emptyState(context)
|
||||
else
|
||||
..._slotCards(context, slots, state),
|
||||
],
|
||||
);
|
||||
},
|
||||
@@ -164,244 +107,400 @@ class _ProfessionalCalendarScreenState extends State<ProfessionalCalendarScreen>
|
||||
);
|
||||
}
|
||||
|
||||
ScheduleEntity? _getScheduleFromNumDay(int numDay) {
|
||||
switch (numDay) {
|
||||
case 1:
|
||||
return widget.userProfessional.schedules.monday;
|
||||
case 2:
|
||||
return widget.userProfessional.schedules.tuesday;
|
||||
case 3:
|
||||
return widget.userProfessional.schedules.wednesday;
|
||||
case 4:
|
||||
return widget.userProfessional.schedules.thursday;
|
||||
case 5:
|
||||
return widget.userProfessional.schedules.friday;
|
||||
case 6:
|
||||
return widget.userProfessional.schedules.saturday;
|
||||
case 7:
|
||||
return widget.userProfessional.schedules.sunday;
|
||||
default:
|
||||
return null;
|
||||
Widget _calendarCard(BuildContext context) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.fromLTRB(16, 16, 16, 0),
|
||||
decoration: BoxDecoration(
|
||||
color: context.card,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: context.shadow,
|
||||
blurRadius: 16,
|
||||
offset: const Offset(0, 4))
|
||||
],
|
||||
),
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
child: TableCalendar(
|
||||
locale: 'es_MX',
|
||||
firstDay: DateTime.now(),
|
||||
lastDay: today.add(const Duration(days: 365)),
|
||||
focusedDay: today,
|
||||
availableGestures: AvailableGestures.all,
|
||||
onDaySelected: _onDaySelected,
|
||||
selectedDayPredicate: (day) => isSameDay(day, today),
|
||||
calendarFormat: _calendarFormat,
|
||||
onFormatChanged: (f) => setState(() => _calendarFormat = f),
|
||||
availableCalendarFormats: const {
|
||||
CalendarFormat.month: 'Mes',
|
||||
CalendarFormat.week: 'Semana',
|
||||
CalendarFormat.twoWeeks: '2 Semanas',
|
||||
},
|
||||
calendarStyle: CalendarStyle(
|
||||
todayDecoration: BoxDecoration(
|
||||
border: Border.all(color: _kPrimary, width: 2),
|
||||
shape: BoxShape.circle),
|
||||
todayTextStyle: const TextStyle(
|
||||
color: _kPrimary, fontWeight: FontWeight.w700),
|
||||
selectedDecoration: const BoxDecoration(
|
||||
color: _kPrimary, shape: BoxShape.circle),
|
||||
selectedTextStyle: const TextStyle(
|
||||
color: Colors.white, fontWeight: FontWeight.w700),
|
||||
weekendTextStyle: TextStyle(color: Colors.red.shade400),
|
||||
defaultTextStyle: TextStyle(color: context.onSurface),
|
||||
outsideDaysVisible: false,
|
||||
),
|
||||
headerStyle: HeaderStyle(
|
||||
formatButtonDecoration: BoxDecoration(
|
||||
border: Border.all(color: _kPrimary.withOpacity(0.4)),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
formatButtonTextStyle:
|
||||
const TextStyle(color: _kPrimary, fontSize: 12),
|
||||
titleCentered: true,
|
||||
titleTextStyle: TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: context.onSurface),
|
||||
leftChevronIcon:
|
||||
const Icon(Icons.chevron_left, color: _kPrimary),
|
||||
rightChevronIcon:
|
||||
const Icon(Icons.chevron_right, color: _kPrimary),
|
||||
),
|
||||
daysOfWeekStyle: DaysOfWeekStyle(
|
||||
weekdayStyle: TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: context.muted),
|
||||
weekendStyle: const TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Color(0xFFEF4444)),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _dayHeader(BuildContext context, ScheduleEntity? schedule, int total,
|
||||
int occupied, int available) {
|
||||
final dayName = DateFormat('EEEE', 'es').format(today);
|
||||
final dateStr = DateFormat('d MMMM yyyy', 'es').format(today);
|
||||
final hasSchedule = schedule != null && schedule.enabled && total > 0;
|
||||
|
||||
return Container(
|
||||
margin: const EdgeInsets.fromLTRB(16, 12, 16, 0),
|
||||
padding: const EdgeInsets.fromLTRB(16, 14, 16, 14),
|
||||
decoration: BoxDecoration(
|
||||
color: context.card,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: context.shadowSm,
|
||||
blurRadius: 12,
|
||||
offset: const Offset(0, 2))
|
||||
],
|
||||
),
|
||||
child: Row(children: [
|
||||
Container(
|
||||
width: 48,
|
||||
height: 52,
|
||||
decoration:
|
||||
BoxDecoration(color: _kPrimary, borderRadius: BorderRadius.circular(12)),
|
||||
child: Column(mainAxisAlignment: MainAxisAlignment.center, children: [
|
||||
Text(DateFormat('d').format(today),
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.w800,
|
||||
height: 1)),
|
||||
Text(DateFormat('MMM', 'es').format(today).toUpperCase(),
|
||||
style: const TextStyle(
|
||||
color: Colors.white70,
|
||||
fontSize: 10,
|
||||
fontWeight: FontWeight.w600)),
|
||||
]),
|
||||
),
|
||||
const SizedBox(width: 14),
|
||||
Expanded(
|
||||
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
||||
Text(_capitalize(dayName),
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: context.onSurface)),
|
||||
Text(dateStr, style: TextStyle(fontSize: 12, color: context.subtle)),
|
||||
]),
|
||||
),
|
||||
if (hasSchedule) ...[
|
||||
_StatPill(label: '$occupied', sublabel: 'ocupadas', color: _kOccupied),
|
||||
const SizedBox(width: 8),
|
||||
_StatPill(
|
||||
label: '$available', sublabel: 'libres', color: _kAvailable),
|
||||
],
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
List<Widget> _slotCards(
|
||||
BuildContext context, List<TimeOfDay> slots, ServiceState state) {
|
||||
return slots.map((time) {
|
||||
final occ = _isOccupied(time, _services, today);
|
||||
final color = occ ? _kOccupied : _kAvailable;
|
||||
|
||||
return Container(
|
||||
margin: const EdgeInsets.fromLTRB(16, 8, 16, 0),
|
||||
decoration: BoxDecoration(
|
||||
color: context.card,
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: context.shadowSm,
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 2))
|
||||
],
|
||||
),
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
child: InkWell(
|
||||
onTap: () => occ ? _onOccupied(time) : _onAvailable(context, time, state),
|
||||
child: IntrinsicHeight(
|
||||
child: Row(children: [
|
||||
Container(width: 4, color: color),
|
||||
Expanded(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 14, vertical: 12),
|
||||
child: Row(children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 12, vertical: 6),
|
||||
decoration: BoxDecoration(
|
||||
color: color.withOpacity(0.08),
|
||||
borderRadius: BorderRadius.circular(8)),
|
||||
child: Text(
|
||||
ScheduleEntity.getFormatTime(time) ?? '',
|
||||
style: TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w800,
|
||||
color: color),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 14),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(occ ? 'Ocupado' : 'Disponible',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: color)),
|
||||
Text(
|
||||
occ
|
||||
? 'Toca para ver el servicio'
|
||||
: 'Horario libre · toca para reservar',
|
||||
style: TextStyle(
|
||||
fontSize: 11, color: context.subtle),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Container(
|
||||
width: 32,
|
||||
height: 32,
|
||||
decoration: BoxDecoration(
|
||||
color: color.withOpacity(0.1),
|
||||
shape: BoxShape.circle),
|
||||
child: Icon(
|
||||
occ
|
||||
? Icons.event_busy_outlined
|
||||
: Icons.event_available_outlined,
|
||||
size: 17,
|
||||
color: color),
|
||||
),
|
||||
]),
|
||||
),
|
||||
),
|
||||
]),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList();
|
||||
}
|
||||
|
||||
void _onOccupied(TimeOfDay time) {
|
||||
if (_services == null) return;
|
||||
for (final event in _services!) {
|
||||
if (today.toString() == event.day && time == event.range1Hour1) {
|
||||
if (event.userId == event.professionalId) {
|
||||
ScaffoldMessenger.of(context).clearSnackBars();
|
||||
ScaffoldMessenger.of(context)
|
||||
.showSnackBar(const SnackBar(content: Text('Horario ocupado por ti')));
|
||||
} else {
|
||||
Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (_) =>
|
||||
ProfessionalServiceScreen(serviceId: event.id!)),
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<Widget> _rangesItems(ScheduleEntity? schedule, BuildContext context) {
|
||||
if (schedule == null ||
|
||||
schedule.enabled == false ||
|
||||
schedule.range1Hour1 == null ||
|
||||
schedule.range2Hour2 == null) {
|
||||
return [
|
||||
const Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 25),
|
||||
child: Text("No hay horarios disponibles"),
|
||||
)
|
||||
];
|
||||
}
|
||||
|
||||
if (schedule.continuousDay) {
|
||||
List<TimeOfDay> ranges = TimeOfDayUtils.genRanges(
|
||||
schedule.range1Hour1!,
|
||||
schedule.range2Hour2!,
|
||||
);
|
||||
|
||||
return rangesItemList(ranges, _services, today, context);
|
||||
}
|
||||
|
||||
List<TimeOfDay> ranges1 = TimeOfDayUtils.genRanges(
|
||||
schedule.range1Hour1!,
|
||||
schedule.range1Hour2!,
|
||||
);
|
||||
List<TimeOfDay> ranges2 = TimeOfDayUtils.genRanges(
|
||||
schedule.range2Hour1!,
|
||||
schedule.range2Hour2!,
|
||||
void _onAvailable(BuildContext context, TimeOfDay time, ServiceState state) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (dialogContext) => AlertDialog(
|
||||
title: const Text('Reservar hora'),
|
||||
content: Column(mainAxisSize: MainAxisSize.min, children: [
|
||||
Text(
|
||||
'¿Reservar a las ${ScheduleEntity.getFormatTime(time)} '
|
||||
'del ${DateFormat('dd-MM-yyyy').format(today)}?',
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
const Text('⚠️ Esta acción no se puede deshacer',
|
||||
style: TextStyle(fontWeight: FontWeight.bold)),
|
||||
]),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(dialogContext),
|
||||
child: const Text('Cancelar'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(dialogContext);
|
||||
Navigator.pop(context);
|
||||
context.read<ServiceBloc>().add(CreateService(
|
||||
professionalId: widget.userProfessional.id,
|
||||
userId: widget.userProfessional.id,
|
||||
address: widget.userProfessional.address,
|
||||
aditionalAddress: '',
|
||||
latitude: 0,
|
||||
longitude: 0,
|
||||
day: today.toString(),
|
||||
createdAt: DateTime.now().toIso8601String(),
|
||||
description: '',
|
||||
range1Hour1: time,
|
||||
range1Hour2: time.replacing(hour: time.hour + 2),
|
||||
rate: '0',
|
||||
location: ServiceLocationPreferences.office,
|
||||
status: ServiceStatus.selfBooked,
|
||||
));
|
||||
},
|
||||
child: const Text('Reservar'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _emptyState(BuildContext context) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.fromLTRB(16, 12, 16, 0),
|
||||
padding: const EdgeInsets.symmetric(vertical: 40, horizontal: 24),
|
||||
decoration: BoxDecoration(
|
||||
color: context.card,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: context.shadowSm,
|
||||
blurRadius: 12,
|
||||
offset: const Offset(0, 2))
|
||||
],
|
||||
),
|
||||
child: Column(children: [
|
||||
Container(
|
||||
width: 64,
|
||||
height: 64,
|
||||
decoration: BoxDecoration(
|
||||
color: context.subtle.withOpacity(0.1), shape: BoxShape.circle),
|
||||
child: Icon(Icons.event_busy_outlined, size: 32, color: context.subtle),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text('Sin horario este día',
|
||||
style: TextStyle(
|
||||
fontSize: 15, fontWeight: FontWeight.w700, color: context.muted)),
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
'No tienes horario de atención configurado\npara este día de la semana.',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(fontSize: 13, color: context.subtle, height: 1.5)),
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
ScheduleEntity? _scheduleFromDay(int day) {
|
||||
switch (day) {
|
||||
case 1: return widget.userProfessional.schedules.monday;
|
||||
case 2: return widget.userProfessional.schedules.tuesday;
|
||||
case 3: return widget.userProfessional.schedules.wednesday;
|
||||
case 4: return widget.userProfessional.schedules.thursday;
|
||||
case 5: return widget.userProfessional.schedules.friday;
|
||||
case 6: return widget.userProfessional.schedules.saturday;
|
||||
default: return widget.userProfessional.schedules.sunday;
|
||||
}
|
||||
}
|
||||
|
||||
List<TimeOfDay> _buildSlots(ScheduleEntity? s) {
|
||||
if (s == null || !s.enabled || s.range1Hour1 == null || s.range2Hour2 == null) {
|
||||
return [];
|
||||
}
|
||||
if (s.continuousDay) {
|
||||
return TimeOfDayUtils.genRanges(s.range1Hour1!, s.range2Hour2!);
|
||||
}
|
||||
if (s.range1Hour2 == null || s.range2Hour1 == null) return [];
|
||||
return [
|
||||
...rangesItemList(ranges1, _services, today, context),
|
||||
...rangesItemList(ranges2, _services, today, context),
|
||||
...TimeOfDayUtils.genRanges(s.range1Hour1!, s.range1Hour2!),
|
||||
...TimeOfDayUtils.genRanges(s.range2Hour1!, s.range2Hour2!),
|
||||
];
|
||||
}
|
||||
|
||||
bool _isHora1Ocupada(
|
||||
TimeOfDay hora1, List<ServiceEntity>? events, DateTime selectedDay) {
|
||||
if (events != null) {
|
||||
for (ServiceEntity event in events) {
|
||||
if (selectedDay.toString() == event.day) {
|
||||
if (hora1 == event.range1Hour1) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
bool _isOccupied(
|
||||
TimeOfDay time, List<ServiceEntity>? services, DateTime day) {
|
||||
if (services == null) return false;
|
||||
return services
|
||||
.any((s) => day.toString() == s.day && s.range1Hour1 == time);
|
||||
}
|
||||
|
||||
List<Widget> rangesItemList(List<TimeOfDay> ranges, List<ServiceEntity>? events, DateTime selectedDay, BuildContext context) {
|
||||
return ranges.map((time) {
|
||||
if (_isHora1Ocupada(time, events, selectedDay)) {
|
||||
return Card(
|
||||
elevation: 4,
|
||||
margin: const EdgeInsets.symmetric(vertical: 5, horizontal: 10),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: ListTile(
|
||||
onTap: () {
|
||||
if (events != null) {
|
||||
for (ServiceEntity event in events) {
|
||||
if (selectedDay.toString() == event.day) {
|
||||
if (time == event.range1Hour1) {
|
||||
if (event.userId == event.professionalId) {
|
||||
ScaffoldMessenger.of(context).clearSnackBars();
|
||||
ScaffoldMessenger.of(context)
|
||||
.showSnackBar(const SnackBar(
|
||||
content: Text('Horario ocupado por ti'),
|
||||
));
|
||||
} else {
|
||||
Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => ProfessionalServiceScreen(
|
||||
serviceId: event.id!,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
contentPadding: const EdgeInsets.all(16),
|
||||
leading: Container(
|
||||
width: 40,
|
||||
height: 40,
|
||||
decoration: const BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
colors: [Colors.yellow, Colors.red, Colors.red],
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: const Center(
|
||||
child: Icon(
|
||||
Icons.access_time,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
title: Text(
|
||||
ScheduleEntity.getFormatTime(time) ?? '',
|
||||
style: const TextStyle(fontSize: 15, fontWeight: FontWeight.bold),
|
||||
),
|
||||
subtitle: const Text(
|
||||
'Ocupado',
|
||||
style: TextStyle(
|
||||
color: Colors.red, fontSize: 13, fontWeight: FontWeight.bold),
|
||||
),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return Card(
|
||||
elevation: 4,
|
||||
margin: const EdgeInsets.symmetric(vertical: 5, horizontal: 10),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: ListTile(
|
||||
onTap: () {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext dialogContext) {
|
||||
return AlertDialog(
|
||||
title: const Text('Reservar hora'),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
'¿Estás seguro de que deseas reservar a las ${ScheduleEntity.getFormatTime(time)} del ${DateFormat('dd-MM-yyyy').format(today)}?',
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
const Text(
|
||||
'⚠️ Esta accion no se puede deshacer ⚠️',
|
||||
style: TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(dialogContext);
|
||||
},
|
||||
child: const Text('No, cancelar'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(dialogContext);
|
||||
String _capitalize(String s) =>
|
||||
s.isEmpty ? s : s[0].toUpperCase() + s.substring(1);
|
||||
}
|
||||
|
||||
Navigator.pop(context);
|
||||
class _StatPill extends StatelessWidget {
|
||||
final String label;
|
||||
final String sublabel;
|
||||
final Color color;
|
||||
const _StatPill(
|
||||
{required this.label, required this.sublabel, required this.color});
|
||||
|
||||
context.read<ServiceBloc>().add(
|
||||
CreateService(
|
||||
professionalId: widget.userProfessional.id,
|
||||
userId: widget.userProfessional.id,
|
||||
address: widget.userProfessional.address,
|
||||
aditionalAddress: '',
|
||||
latitude: 0,
|
||||
longitude: 0,
|
||||
day: today.toString(),
|
||||
createdAt: DateTime.now().toIso8601String(),
|
||||
description: '',
|
||||
range1Hour1: time,
|
||||
range1Hour2: time.add(hour: 2),
|
||||
rate: '0',
|
||||
location: ServiceLocationPreferences.office,
|
||||
status: ServiceStatus.selfBooked,
|
||||
),
|
||||
);
|
||||
},
|
||||
child: const Text('Si, reservar'),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
contentPadding: const EdgeInsets.all(16),
|
||||
leading: Container(
|
||||
width: 40,
|
||||
height: 40,
|
||||
decoration: const BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
colors: [Colors.blue, Colors.green],
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: const Center(
|
||||
child: Icon(
|
||||
Icons.access_time,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
title: Text(
|
||||
ScheduleEntity.getFormatTime(time) ?? '',
|
||||
style: const TextStyle(fontSize: 15, fontWeight: FontWeight.bold),
|
||||
),
|
||||
subtitle: const Text(
|
||||
'Disponible',
|
||||
style: TextStyle(
|
||||
color: Colors.green,
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}).toList();
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 6),
|
||||
decoration: BoxDecoration(
|
||||
color: color.withOpacity(0.08),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(color: color.withOpacity(0.25)),
|
||||
),
|
||||
child: Column(mainAxisSize: MainAxisSize.min, children: [
|
||||
Text(label,
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w800,
|
||||
color: color,
|
||||
height: 1)),
|
||||
Text(sublabel,
|
||||
style: TextStyle(
|
||||
fontSize: 9,
|
||||
color: color.withOpacity(0.8),
|
||||
fontWeight: FontWeight.w600)),
|
||||
]),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user