diff --git a/lib/app_view.dart b/lib/app_view.dart index dc43765..34fe204 100644 --- a/lib/app_view.dart +++ b/lib/app_view.dart @@ -17,7 +17,7 @@ class MyAppView extends StatelessWidget { theme: ThemeData( colorScheme: const ColorScheme.light( background: Colors.white, - onBackground: Colors.grey, + onBackground: Colors.black12, primary: Color.fromRGBO(66, 164, 239, 1), onPrimary: Colors.white, secondary: Colors.white, diff --git a/lib/blocs/professional_profile_bloc/professional_profile_bloc.dart b/lib/blocs/professional_profile_bloc/professional_profile_bloc.dart index 0026e61..13244d1 100644 --- a/lib/blocs/professional_profile_bloc/professional_profile_bloc.dart +++ b/lib/blocs/professional_profile_bloc/professional_profile_bloc.dart @@ -42,7 +42,9 @@ class ProfessionalProfileBloc event.locationPreferences, event.latitude, event.longitude, + event.schedules, event.paymentMethods, + ); emit(const UpdateProfessionalInfoSuccess()); diff --git a/lib/blocs/professional_profile_bloc/professional_profile_event.dart b/lib/blocs/professional_profile_bloc/professional_profile_event.dart index 220ad49..6390874 100644 --- a/lib/blocs/professional_profile_bloc/professional_profile_event.dart +++ b/lib/blocs/professional_profile_bloc/professional_profile_event.dart @@ -25,7 +25,7 @@ class UpdateProfessionalProfileInfo extends ProfessionalProfileEvent { final LocationPreferences locationPreferences; final double latitude; final double longitude; - // final Schedules schedules; + final Schedules schedules; final PaymentMethodEntity paymentMethods; const UpdateProfessionalProfileInfo({ @@ -35,7 +35,7 @@ class UpdateProfessionalProfileInfo extends ProfessionalProfileEvent { required this.locationPreferences, required this.latitude, required this.longitude, - // required this.schedules, + required this.schedules, required this.paymentMethods, }); @@ -47,7 +47,7 @@ class UpdateProfessionalProfileInfo extends ProfessionalProfileEvent { locationPreferences, latitude, longitude, - // schedules, + schedules, paymentMethods ]; } diff --git a/lib/components/general_drawer.dart b/lib/components/general_drawer.dart index 7a36721..ed79d44 100644 --- a/lib/components/general_drawer.dart +++ b/lib/components/general_drawer.dart @@ -8,10 +8,13 @@ import 'package:prosappco/components/general_drawer_header.dart'; import 'package:prosappco/components/general_drawer_item.dart'; import 'package:prosappco/screens/configuration/configuration_screen.dart'; import 'package:prosappco/screens/configuration/configuration_support_screen.dart'; +import 'package:prosappco/screens/professional/professional_calendar_screen.dart'; import 'package:prosappco/screens/professional/professional_denied_screen.dart'; import 'package:prosappco/screens/professional/professional_form_screen.dart'; import 'package:prosappco/screens/professional/professional_pending_screen.dart'; import 'package:prosappco/screens/professional/professional_profile_screen.dart'; +import 'package:prosappco/screens/user/user_history_services_screen.dart'; +import 'package:prosappco/screens/user/user_services_screen.dart'; import 'package:prosappco/screens/web/web_view_screen.dart'; import 'package:url_launcher/url_launcher.dart'; import 'package:user_repository/user_repository.dart'; @@ -71,12 +74,46 @@ class GeneralDrawer extends StatelessWidget { ) : const SizedBox(), GeneralDrawerItem( - leading: Icons.history, + leading: Icons.checklist_outlined, label: 'Mis servicios', onTap: () { - Navigator.pop(context); + Navigator.push( + context, + CupertinoPageRoute( + builder: (context) => + const UserServicesScreen(), + ), + ); }, ), + GeneralDrawerItem( + leading: Icons.access_time_outlined, + label: 'Historial', + onTap: () { + Navigator.push( + context, + CupertinoPageRoute( + builder: (context) => + const UserHistoryServicesScreen(), + ), + ); + }, + ), + shouldProModeActive(context, professionalState) + ? GeneralDrawerItem( + onTap: () { + Navigator.push( + context, + CupertinoPageRoute( + builder: (context) => + const ProfessionalCalendarScreen(), + ), + ); + }, + label: 'Calendario', + leading: Icons.calendar_month_outlined, + ) + : const SizedBox(), GeneralDrawerItem( leading: Icons.settings_outlined, label: 'Configuración', @@ -124,12 +161,40 @@ class GeneralDrawer extends StatelessWidget { } }, ), - shouldProModeActive(context, professionalState) - ? const GeneralDrawerItem( - label: 'Calendario', - leading: Icons.calendar_month_outlined, - ) - : const SizedBox(), + Container( + color: const Color(0xFF2BA4EC), + child: ListTile( + onTap: () { + shouldProModeActive(context, professionalState) + ? Navigator.pop(context) + : Navigator.pop(context); + }, + trailing: const Icon( + Icons.keyboard_arrow_right, + color: Colors.white, + ), + title: Text( + shouldProModeActive(context, professionalState) + ? 'Solicitudes' + : 'Solicitar servicio', + style: const TextStyle( + fontSize: 16, + color: Colors.white, + fontWeight: FontWeight.bold, + ), + ), + ), + ), + Padding( + padding: const EdgeInsets.only(top: 10), + child: Text( + 'Prosapp ® todos los derechos reservados', + style: TextStyle( + fontSize: 10, + color: Colors.grey[700], + ), + ), + ), ], ), ), diff --git a/lib/screens/professional/components/schedule_item.dart b/lib/screens/professional/components/schedule_item.dart new file mode 100644 index 0000000..3b522b5 --- /dev/null +++ b/lib/screens/professional/components/schedule_item.dart @@ -0,0 +1,161 @@ +import 'package:flutter/material.dart'; +import 'package:professional_repository/professional_repository.dart'; + +class ScheduleItem extends StatelessWidget { + ScheduleEntity schedule; + String label; + final ValueChanged onChanged; + + ScheduleItem( + {super.key, + required this.label, + required this.schedule, + required this.onChanged}); + + @override + Widget build(BuildContext context) { + return Column( + children: [ + Row( + children: [ + Expanded( + child: Text( + label, + style: const TextStyle( + fontSize: 17, + fontWeight: FontWeight.w500, + color: Colors.black, + ), + ), + ), + Switch( + value: schedule.enabled, + onChanged: (value) { + onChanged.call(schedule.copyWith(enabled: value)); + }, + ), + ], + ), + Visibility( + visible: schedule.enabled, + child: Row( + children: [ + const Expanded( + child: Text( + 'Jornada continua', + style: TextStyle( + fontSize: 17, + fontWeight: FontWeight.w500, + color: Colors.black, + ), + ), + ), + Switch( + value: schedule.continuousDay, + onChanged: (value) { + onChanged.call(schedule.copyWith(continuousDay: value)); + }, + ), + ], + )), + Visibility( + visible: schedule.enabled, + child: hoursRangesBody(context), + ), + ], + ); + } + + hoursRangesBody(BuildContext context) { + return Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + timePickerField( + context: context, + text: schedule.getFormatTime(schedule.range1Hour1), + onPick: (pickedTime) { + onChanged.call(schedule.copyWith(range1Hour1: pickedTime)); + }, + ), + Center( + child: Container( + width: 10, + height: 1, + color: Colors.black, + ), + ), + Visibility( + visible: !schedule.continuousDay, + child: timePickerField( + context: context, + text: schedule.getFormatTime(schedule.range1Hour2), + onPick: (pickedTime) { + onChanged.call(schedule.copyWith(range1Hour2: pickedTime)); + }, + ), + ), + Visibility( + visible: !schedule.continuousDay, + child: const SizedBox( + width: 10, + ), + ), + Visibility( + visible: !schedule.continuousDay, + child: timePickerField( + context: context, + text: schedule.getFormatTime(schedule.range2Hour1), + onPick: (pickedTime) { + onChanged.call(schedule.copyWith(range2Hour1: pickedTime)); + }, + ), + ), + Visibility( + visible: !schedule.continuousDay, + child: Center( + child: Container( + width: 10, + height: 1, + color: Colors.black, + ), + ), + ), + timePickerField( + context: context, + text: schedule.getFormatTime(schedule.range2Hour2), + onPick: (pickedTime) { + onChanged.call(schedule.copyWith(range2Hour2: pickedTime)); + }, + ), + ], + ); + } + + timePickerField( + {required BuildContext context, + required String? text, + required Function(TimeOfDay) onPick}) { + return Expanded( + child: TextField( + readOnly: true, + controller: TextEditingController( + text: text, + ), + textAlign: TextAlign.center, + onTap: () async { + final TimeOfDay? pickedTime = await showTimePicker( + context: context, + initialTime: TimeOfDay.now(), + ); + if (pickedTime != null) { + onPick.call(pickedTime); + } + }, + decoration: const InputDecoration( + hintText: 'Hora', + border: UnderlineInputBorder(), + ), + ), + ); + } +} diff --git a/lib/screens/professional/professional_calendar_screen.dart b/lib/screens/professional/professional_calendar_screen.dart new file mode 100644 index 0000000..b6254ca --- /dev/null +++ b/lib/screens/professional/professional_calendar_screen.dart @@ -0,0 +1,141 @@ +import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart'; +import 'package:table_calendar/table_calendar.dart'; + +class ProfessionalCalendarScreen extends StatefulWidget { + const ProfessionalCalendarScreen({super.key}); + + @override + State createState() => + _ProfessionalCalendarScreenState(); +} + +class _ProfessionalCalendarScreenState + extends State { + TextEditingController _titleController = TextEditingController(); + TextEditingController _descriptionController = TextEditingController(); + + DateTime today = DateTime.now(); + DateTime now = DateTime.now(); + + CalendarFormat _calendarFormat = CalendarFormat.month; + + TimeOfDay? _selectedTime1; + TimeOfDay? _selectedTime2; + + Future _selectTime1(BuildContext context) async { + final TimeOfDay? pickedTime1 = await showTimePicker( + context: context, + initialTime: TimeOfDay.now(), + ); + if (pickedTime1 != null) { + setState(() { + _selectedTime1 = pickedTime1; + }); + } + return pickedTime1; + } + + Future _selectTime2(BuildContext context) async { + final TimeOfDay? pickedTime2 = await showTimePicker( + context: context, + initialTime: TimeOfDay.now(), + ); + if (pickedTime2 != null) { + setState(() { + _selectedTime2 = pickedTime2; + }); + } + + return pickedTime2; + } + + void _onDaySelected(DateTime day, DateTime focusedDay) { + setState(() { + today = day; + }); + } + + void _onFormatChange(CalendarFormat format) { + setState(() { + _calendarFormat = format; + }); + } + + @override + Widget build(BuildContext context) { + DateTime lastDay = today.add(const Duration(days: 365)); + return Scaffold( + appBar: AppBar( + title: const Text('Calendario'), + ), + floatingActionButtonLocation: kIsWeb + ? FloatingActionButtonLocation.startFloat + : FloatingActionButtonLocation.endFloat, + resizeToAvoidBottomInset: false, + body: Column( + children: [ + Container( + color: const Color.fromARGB(255, 224, 247, 255), + child: TableCalendar( + // locale: 'es_MX', + firstDay: DateTime.utc(2010, 10, 16), + lastDay: lastDay, + focusedDay: today, + availableGestures: AvailableGestures.all, + onDaySelected: _onDaySelected, + selectedDayPredicate: (day) => isSameDay(day, today), + calendarFormat: _calendarFormat, + onFormatChanged: _onFormatChange, + eventLoader: (date) { + return []; + // return events + // .where((element) { + // DateTime day = DateTime.parse(element.day); + // return (date.year == day.year && + // date.month == day.month && + // date.day == day.day); + // }) + // .map((e) => e.description) + // .toList(); + }, + 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: const [], + ), + ), + ), + ], + ), + floatingActionButton: FloatingActionButton( + onPressed: () {}, + // onPressed: _showDialog, + child: const Icon(Icons.add), + ), + ); + } +} diff --git a/lib/screens/professional/professional_profile_screen.dart b/lib/screens/professional/professional_profile_screen.dart index f4240bc..7645506 100644 --- a/lib/screens/professional/professional_profile_screen.dart +++ b/lib/screens/professional/professional_profile_screen.dart @@ -41,6 +41,9 @@ class _ProfessionalProfileScreenState extends State { TextEditingController(); final TextEditingController _rateController = TextEditingController(); + Schedules schedules = Schedules.empty; + bool isInit = false; + double _longitudeController = 0; double _latitudeController = 0; @@ -96,6 +99,11 @@ class _ProfessionalProfileScreenState extends State { if (state.proInfo == null) { return const Text('Loading...'); } else { + if (!isInit) { + schedules = state.proInfo!.schedules; + isInit = true; + } + return body(state.proInfo!); } } @@ -340,15 +348,138 @@ class _ProfessionalProfileScreenState extends State { ), const Divider(height: 0), GestureDetector( - onTap: () { - Navigator.push( + onTap: () async { + Schedules? schedules = await Navigator.push( context, CupertinoPageRoute( - builder: (context) => const ProfessionalScheduleScreen(), + builder: (context) => + ProfessionalScheduleScreen(schedules: this.schedules), ), ); + + if (schedules != null) { + setState(() { + this.schedules = schedules; + }); + } }, - child: Text(proInfo.schedules.toString()), + child: Table( + defaultColumnWidth: const IntrinsicColumnWidth(), + children: [ + TableRow( + children: [ + TableCell( + child: Container( + padding: const EdgeInsets.all(8.0), + child: const Text('Lunes'), + ), + ), + TableCell( + child: Container( + padding: const EdgeInsets.all(8.0), + child: Text(timeList(schedules.monday, context)), + ), + ), + ], + ), + TableRow( + children: [ + TableCell( + child: Container( + padding: const EdgeInsets.all(8.0), + child: const Text('Martes'), + ), + ), + TableCell( + child: Container( + padding: const EdgeInsets.all(8.0), + child: Text(timeList(schedules.tuesday, context)), + ), + ), + ], + ), + TableRow( + children: [ + TableCell( + child: Container( + padding: const EdgeInsets.all(8.0), + child: const Text('Miercoles'), + ), + ), + TableCell( + child: Container( + padding: const EdgeInsets.all(8.0), + child: Text(timeList(schedules.wednesday, context)), + ), + ), + ], + ), + TableRow( + children: [ + TableCell( + child: Container( + padding: const EdgeInsets.all(8.0), + child: const Text('Jueves'), + ), + ), + TableCell( + child: Container( + padding: const EdgeInsets.all(8.0), + child: Text(timeList(schedules.thursday, context)), + ), + ), + ], + ), + TableRow( + children: [ + TableCell( + child: Container( + padding: const EdgeInsets.all(8.0), + child: const Text('Viernes'), + ), + ), + TableCell( + child: Container( + padding: const EdgeInsets.all(8.0), + child: Text(timeList(schedules.friday, context)), + ), + ), + ], + ), + TableRow( + children: [ + TableCell( + child: Container( + padding: const EdgeInsets.all(8.0), + child: const Text('Sabado'), + ), + ), + TableCell( + child: Container( + padding: const EdgeInsets.all(8.0), + child: Text(timeList(schedules.saturday, context)), + ), + ), + ], + ), + TableRow( + children: [ + TableCell( + child: Container( + padding: const EdgeInsets.all(8.0), + child: const Text('Domingo'), + ), + ), + TableCell( + child: Container( + padding: const EdgeInsets.all(8.0), + child: Text(timeList(schedules.sunday, context)), + ), + ), + ], + ), + ], + ), ), const Divider(height: 0), const SizedBox(height: 20), @@ -372,16 +503,8 @@ class _ProfessionalProfileScreenState extends State { nequi: isNequiActive, transferencia: isTransferActive, ), + schedules: schedules, rate: _rateController.text, - // schedules: Schedules( - // monday: monday, - // tuesday: tuesday, - // wednesday: wednesday, - // thursday: thursday, - // friday: friday, - // saturday: saturday, - // sunday: sunday, - // ), ), ); context.read().add( @@ -453,4 +576,25 @@ class _ProfessionalProfileScreenState extends State { child: widget, ); } + + String timeList(ScheduleEntity? schedule, BuildContext context) { + if (schedule == null) { + return 'N/A'; + } + if (!schedule.enabled) { + return 'N/A'; + } + if (schedule.range1Hour1 == null || schedule.range2Hour2 == null) { + return 'N/A'; + } + if (schedule.continuousDay) { + return '${schedule.range1Hour1?.format(context).toString()} - ${schedule.range2Hour2?.format(context).toString()}'; + } else { + if (schedule.range1Hour2 == null || schedule.range2Hour1 == null) { + return 'N/A'; + } + + return '${schedule.range1Hour1?.format(context).toString()} - ${schedule.range1Hour2?.format(context).toString()}; ${schedule.range2Hour1?.format(context).toString()} - ${schedule.range2Hour2?.format(context).toString()}'; + } + } } diff --git a/lib/screens/professional/professional_schedule_screen.dart b/lib/screens/professional/professional_schedule_screen.dart index 42787ab..ab60541 100644 --- a/lib/screens/professional/professional_schedule_screen.dart +++ b/lib/screens/professional/professional_schedule_screen.dart @@ -1,7 +1,14 @@ import 'package:flutter/material.dart'; +import 'package:professional_repository/professional_repository.dart'; +import 'package:prosappco/components/general_primary_button.dart'; +import 'package:prosappco/screens/professional/components/schedule_item.dart'; class ProfessionalScheduleScreen extends StatefulWidget { - const ProfessionalScheduleScreen({super.key}); + Schedules schedules; + ProfessionalScheduleScreen({ + super.key, + required this.schedules, + }); @override State createState() => @@ -10,6 +17,13 @@ class ProfessionalScheduleScreen extends StatefulWidget { class _ProfessionalScheduleScreenState extends State { + Schedules schedules = Schedules.empty; + @override + void initState() { + super.initState(); + schedules = widget.schedules; + } + @override Widget build(BuildContext context) { return Scaffold( @@ -19,26 +33,63 @@ class _ProfessionalScheduleScreenState body: SingleChildScrollView( child: Column( children: [ - Row( - children: [ - Expanded( - child: Text( - 'Lunes', - style: TextStyle( - fontSize: 17, - fontWeight: FontWeight.w500, - color: Colors.black, - ), - ), - ), - Switch( - value: false, - onChanged: (value) { - setState(() {}); - }, - ), - ], + ScheduleItem( + label: "Lunes", + schedule: schedules.monday, + onChanged: (s) { + setState(() => schedules = schedules.copyWith(monday: s)); + }, ), + ScheduleItem( + label: "Martes", + schedule: schedules.thursday, + onChanged: (s) { + setState(() => schedules = schedules.copyWith(thursday: s)); + }, + ), + ScheduleItem( + label: "Miercoles", + schedule: schedules.wednesday, + onChanged: (s) { + setState(() => schedules = schedules.copyWith(wednesday: s)); + }, + ), + ScheduleItem( + label: "Jueves", + schedule: schedules.tuesday, + onChanged: (s) { + setState(() => schedules = schedules.copyWith(tuesday: s)); + }, + ), + ScheduleItem( + label: "Viernes", + schedule: schedules.friday, + onChanged: (s) { + setState(() => schedules = schedules.copyWith(friday: s)); + }, + ), + ScheduleItem( + label: "Sabado", + schedule: schedules.saturday, + onChanged: (s) { + setState(() => schedules = schedules.copyWith(saturday: s)); + }, + ), + ScheduleItem( + label: "Domingo", + schedule: schedules.sunday, + onChanged: (s) { + setState(() => schedules = schedules.copyWith(sunday: s)); + }, + ), + const SizedBox(height: 20), + GeneralPrimaryButton( + label: "Guardar", + onPressed: () { + Navigator.of(context).pop(schedules); + }, + ), + const SizedBox(height: 20), ], ), ), diff --git a/lib/screens/user/user_history_services_screen.dart b/lib/screens/user/user_history_services_screen.dart new file mode 100644 index 0000000..452a529 --- /dev/null +++ b/lib/screens/user/user_history_services_screen.dart @@ -0,0 +1,17 @@ +import 'package:flutter/material.dart'; + +class UserHistoryServicesScreen extends StatelessWidget { + const UserHistoryServicesScreen({super.key}); + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: const Text('Historial de servicios'), + ), + body: const Center( + child: Text('Historial de servicios'), + ), + ); + } +} diff --git a/lib/screens/user/user_services_screen.dart b/lib/screens/user/user_services_screen.dart new file mode 100644 index 0000000..3d726a3 --- /dev/null +++ b/lib/screens/user/user_services_screen.dart @@ -0,0 +1,17 @@ +import 'package:flutter/material.dart'; + +class UserServicesScreen extends StatelessWidget { + const UserServicesScreen({super.key}); + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: const Text('Mis servicios'), + ), + body: const Center( + child: Text('Servicios'), + ), + ); + } +} diff --git a/packages/professional_repository/lib/src/entities/professional_entity.dart b/packages/professional_repository/lib/src/entities/professional_entity.dart index 6272ab3..cff0a4d 100644 --- a/packages/professional_repository/lib/src/entities/professional_entity.dart +++ b/packages/professional_repository/lib/src/entities/professional_entity.dart @@ -53,13 +53,54 @@ class ProfessionalEntity extends Equatable { latitude: double.parse(doc['latitude'].toString()), longitude: double.parse(doc['longitude'].toString()), specializations: List.from(doc['specializations']), - specializationsPictures: - List.from(doc['specializations_pictures']), + specializationsPictures: List.from(doc['specializations_pictures']), schedules: Schedules.fromDocument(doc['schedules']), paymentMethods: PaymentMethodEntity.fromDocument(doc['payment_methods']), ); } + // copy func + + ProfessionalEntity copyWith({ + String? id, + String? identification, + String? address, + String? aditionalAddress, + String? profession, + String? rate, + LocationPreferences? locationPreferences, + String? bannerPicture, + String? identificationPicture, + String? certificatePicture, + double? latitude, + double? longitude, + List? specializations, + List? specializationsPictures, + Schedules? schedules, + PaymentMethodEntity? paymentMethods, + }) { + return ProfessionalEntity( + id: id ?? this.id, + identification: identification ?? this.identification, + address: address ?? this.address, + aditionalAddress: aditionalAddress ?? this.aditionalAddress, + profession: profession ?? this.profession, + rate: rate ?? this.rate, + locationPreferences: locationPreferences ?? this.locationPreferences, + bannerPicture: bannerPicture ?? this.bannerPicture, + identificationPicture: + identificationPicture ?? this.identificationPicture, + certificatePicture: certificatePicture ?? this.certificatePicture, + latitude: latitude ?? this.latitude, + longitude: longitude ?? this.longitude, + specializations: specializations ?? this.specializations, + specializationsPictures: + specializationsPictures ?? this.specializationsPictures, + schedules: schedules ?? this.schedules, + paymentMethods: paymentMethods ?? this.paymentMethods, + ); + } + Map toDocument() { return { 'id': id, diff --git a/packages/professional_repository/lib/src/entities/schedule_entity.dart b/packages/professional_repository/lib/src/entities/schedule_entity.dart index 143d6e4..7e0fd19 100644 --- a/packages/professional_repository/lib/src/entities/schedule_entity.dart +++ b/packages/professional_repository/lib/src/entities/schedule_entity.dart @@ -28,6 +28,25 @@ class ScheduleEntity extends Equatable { range2Hour2: null, ); + // copy func + ScheduleEntity copyWith({ + bool? enabled, + bool? continuousDay, + TimeOfDay? range1Hour1, + TimeOfDay? range1Hour2, + TimeOfDay? range2Hour1, + TimeOfDay? range2Hour2, + }) { + return ScheduleEntity( + enabled: enabled ?? this.enabled, + continuousDay: continuousDay ?? this.continuousDay, + range1Hour1: range1Hour1 ?? this.range1Hour1, + range1Hour2: range1Hour2 ?? this.range1Hour2, + range2Hour1: range2Hour1 ?? this.range2Hour1, + range2Hour2: range2Hour2 ?? this.range2Hour2, + ); + } + static ScheduleEntity fromDocument(Map doc) { return ScheduleEntity( enabled: doc['habilitado'] as bool, @@ -40,17 +59,18 @@ class ScheduleEntity extends Equatable { } static TimeOfDay? _parseTime(String? time) { - if (time == null) return null; - final components = time.split(' '); - final hourMinutes = components[0].split(':'); - final hour = int.parse(hourMinutes[0]); - final minutes = int.parse(hourMinutes[1]); - if (components[1] == 'PM' && hour < 12) { - return TimeOfDay(hour: hour + 12, minute: minutes); - } else if (components[1] == 'AM' && hour == 12) { - return TimeOfDay(hour: 0, minute: minutes); + try { + if (time == null) return null; + final components = time.split(':'); + if (components.length != 2) { + return null; + } + final hour = int.parse(components[0]); + final minutes = int.parse(components[1]); + return TimeOfDay(hour: hour, minute: minutes); + } catch (e) { + return null; } - return TimeOfDay(hour: hour, minute: minutes); } Map toJson() { @@ -66,15 +86,22 @@ class ScheduleEntity extends Equatable { String? formatTimeOfDay(TimeOfDay? time) { if (time != null) { - final now = DateTime.now(); - final dateTime = - DateTime(now.year, now.month, now.day, time.hour, time.minute); - final format = DateFormat.jm(); - return format.format(dateTime); + return "${time.hour.toString()}:${time.minute.toString()}"; } return null; } + String? getFormatTime(TimeOfDay? time) { + if (time == null) { + return null; + } + final now = DateTime.now(); + final dateTime = + DateTime(now.year, now.month, now.day, time.hour, time.minute); + final format = DateFormat.jm(); + return format.format(dateTime); + } + @override List get props => [ enabled, diff --git a/packages/professional_repository/lib/src/entities/schedules.dart b/packages/professional_repository/lib/src/entities/schedules.dart index 98a20b3..e1e3df5 100644 --- a/packages/professional_repository/lib/src/entities/schedules.dart +++ b/packages/professional_repository/lib/src/entities/schedules.dart @@ -29,6 +29,27 @@ class Schedules extends Equatable { sunday: ScheduleEntity.empty, ); + // Copy function + Schedules copyWith({ + ScheduleEntity? monday, + ScheduleEntity? tuesday, + ScheduleEntity? wednesday, + ScheduleEntity? thursday, + ScheduleEntity? friday, + ScheduleEntity? saturday, + ScheduleEntity? sunday, + }) { + return Schedules( + monday: monday ?? this.monday, + tuesday: tuesday ?? this.tuesday, + wednesday: wednesday ?? this.wednesday, + thursday: thursday ?? this.thursday, + friday: friday ?? this.friday, + saturday: saturday ?? this.saturday, + sunday: sunday ?? this.sunday, + ); + } + factory Schedules.fromDocument(Map doc) { return Schedules( monday: ScheduleEntity.fromDocument(doc['monday']), diff --git a/packages/professional_repository/lib/src/repositories/firebase_professional_repository.dart b/packages/professional_repository/lib/src/repositories/firebase_professional_repository.dart index a308e67..6fd54e1 100644 --- a/packages/professional_repository/lib/src/repositories/firebase_professional_repository.dart +++ b/packages/professional_repository/lib/src/repositories/firebase_professional_repository.dart @@ -89,6 +89,7 @@ class FirebaseProfessionalRepository { LocationPreferences locationPreferences, double latitude, double longitude, + Schedules schedules, PaymentMethodEntity paymentMethods, ) async { if (_proInfo == null) { @@ -102,6 +103,7 @@ class FirebaseProfessionalRepository { 'location_preferences': enumToInt(locationPreferences), 'latitude': latitude, 'longitude': longitude, + 'schedules': schedules.toJson(), 'payment_methods': paymentMethods.toDocument(), }); }