horario pro

This commit is contained in:
Felipe
2024-03-19 22:00:48 -05:00
parent 10536be873
commit f37f8c89c2
14 changed files with 751 additions and 62 deletions
@@ -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<ScheduleEntity> 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(),
),
),
);
}
}
@@ -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<ProfessionalCalendarScreen> createState() =>
_ProfessionalCalendarScreenState();
}
class _ProfessionalCalendarScreenState
extends State<ProfessionalCalendarScreen> {
TextEditingController _titleController = TextEditingController();
TextEditingController _descriptionController = TextEditingController();
DateTime today = DateTime.now();
DateTime now = DateTime.now();
CalendarFormat _calendarFormat = CalendarFormat.month;
TimeOfDay? _selectedTime1;
TimeOfDay? _selectedTime2;
Future<TimeOfDay?> _selectTime1(BuildContext context) async {
final TimeOfDay? pickedTime1 = await showTimePicker(
context: context,
initialTime: TimeOfDay.now(),
);
if (pickedTime1 != null) {
setState(() {
_selectedTime1 = pickedTime1;
});
}
return pickedTime1;
}
Future<TimeOfDay?> _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),
),
);
}
}
@@ -41,6 +41,9 @@ class _ProfessionalProfileScreenState extends State<ProfessionalProfileScreen> {
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<ProfessionalProfileScreen> {
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<ProfessionalProfileScreen> {
),
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<ProfessionalProfileScreen> {
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<ProfessionalProfileBloc>().add(
@@ -453,4 +576,25 @@ class _ProfessionalProfileScreenState extends State<ProfessionalProfileScreen> {
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()}';
}
}
}
@@ -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<ProfessionalScheduleScreen> createState() =>
@@ -10,6 +17,13 @@ class ProfessionalScheduleScreen extends StatefulWidget {
class _ProfessionalScheduleScreenState
extends State<ProfessionalScheduleScreen> {
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),
],
),
),
@@ -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'),
),
);
}
}
@@ -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'),
),
);
}
}