citas
This commit is contained in:
@@ -4,15 +4,76 @@ import 'package:prosappco/src/authentication/authentication_repository.dart';
|
|||||||
final uid = AuthenticationRepository.instance.getCurrentUserUid();
|
final uid = AuthenticationRepository.instance.getCurrentUserUid();
|
||||||
|
|
||||||
class EventoService {
|
class EventoService {
|
||||||
Future<void> createEvent(String title, String description, String day) async {
|
Future<void> createEvent(
|
||||||
|
String title,
|
||||||
|
String description,
|
||||||
|
String day,
|
||||||
|
String range1Hour1,
|
||||||
|
String range1Hour2,
|
||||||
|
) async {
|
||||||
try {
|
try {
|
||||||
await FirebaseFirestore.instance.collection('services').add({
|
await FirebaseFirestore.instance.collection('services').add({
|
||||||
|
'profesional_id': uid,
|
||||||
'title': title,
|
'title': title,
|
||||||
'description': description,
|
'description': description,
|
||||||
'day': day,
|
'day': day,
|
||||||
|
'range1Hour1': range1Hour1,
|
||||||
|
'range1Hour2': range1Hour2
|
||||||
|
}).then((value) {
|
||||||
|
FirebaseFirestore.instance.collection('users').doc(uid).update({
|
||||||
|
'services': FieldValue.arrayUnion([value.id])
|
||||||
|
});
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('Evento $e');
|
print('Evento $e');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<List<Event>> getByProId() async {
|
||||||
|
try {
|
||||||
|
var snapshot = await FirebaseFirestore.instance
|
||||||
|
.collection('services')
|
||||||
|
.where('profesional_id', isEqualTo: uid)
|
||||||
|
.get();
|
||||||
|
|
||||||
|
List<Event> eventos = [];
|
||||||
|
for (var element in snapshot.docs) {
|
||||||
|
eventos.add(Event.fromJson(element.data()));
|
||||||
|
}
|
||||||
|
print('Error getByProId $eventos');
|
||||||
|
return eventos;
|
||||||
|
} catch (e) {
|
||||||
|
print('Error getByProId $e');
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Event {
|
||||||
|
String? title;
|
||||||
|
String? description;
|
||||||
|
String? day;
|
||||||
|
String? range1Hour1;
|
||||||
|
String? range1Hour2;
|
||||||
|
String? profesionalId;
|
||||||
|
|
||||||
|
Event({
|
||||||
|
this.title,
|
||||||
|
this.description,
|
||||||
|
this.day,
|
||||||
|
this.range1Hour1,
|
||||||
|
this.range1Hour2,
|
||||||
|
this.profesionalId,
|
||||||
|
});
|
||||||
|
|
||||||
|
factory Event.fromJson(Map<String, dynamic> json) {
|
||||||
|
return Event(
|
||||||
|
title: json['title'],
|
||||||
|
description: json['description'],
|
||||||
|
day: json['day'],
|
||||||
|
range1Hour1: json['range1Hour1'],
|
||||||
|
range1Hour2: json['range1Hour2'],
|
||||||
|
profesionalId: json['profesional_id'],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:prosappco/src/components/pop_appbar.dart';
|
import 'package:prosappco/src/components/pop_appbar.dart';
|
||||||
|
import 'package:prosappco/src/components/primary_btn.dart';
|
||||||
import 'package:prosappco/src/models/event_model.dart';
|
import 'package:prosappco/src/models/event_model.dart';
|
||||||
import 'package:table_calendar/table_calendar.dart';
|
import 'package:table_calendar/table_calendar.dart';
|
||||||
|
import 'package:intl/intl.dart';
|
||||||
|
|
||||||
class CalendarScreen extends StatefulWidget {
|
class CalendarScreen extends StatefulWidget {
|
||||||
const CalendarScreen({super.key});
|
const CalendarScreen({super.key});
|
||||||
@@ -11,9 +13,40 @@ class CalendarScreen extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _CalendarScreenState extends State<CalendarScreen> {
|
class _CalendarScreenState extends State<CalendarScreen> {
|
||||||
|
final _titleController = TextEditingController();
|
||||||
|
final _descriptionController = TextEditingController();
|
||||||
|
|
||||||
EventoService eventoService = EventoService();
|
EventoService eventoService = EventoService();
|
||||||
CalendarFormat _calendarFormat = CalendarFormat.month;
|
CalendarFormat _calendarFormat = CalendarFormat.month;
|
||||||
DateTime today = DateTime.now();
|
DateTime today = DateTime.now();
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@@ -45,7 +78,7 @@ class _CalendarScreenState extends State<CalendarScreen> {
|
|||||||
},
|
},
|
||||||
label: 'Calendario',
|
label: 'Calendario',
|
||||||
),
|
),
|
||||||
body: SingleChildScrollView(
|
body: Container(
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
Container(
|
Container(
|
||||||
@@ -67,18 +100,206 @@ class _CalendarScreenState extends State<CalendarScreen> {
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Text(today.toString())
|
_eventList()
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
floatingActionButton: FloatingActionButton(
|
floatingActionButton: FloatingActionButton(
|
||||||
onPressed: () async {
|
onPressed: _showDialog,
|
||||||
await eventoService.createEvent(
|
|
||||||
'Hola', 'Saludarnois', today.toString());
|
|
||||||
},
|
|
||||||
child: const Icon(Icons.add),
|
child: const Icon(Icons.add),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _showDialog() {
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (BuildContext context) {
|
||||||
|
return AlertDialog(
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(15),
|
||||||
|
),
|
||||||
|
content: StatefulBuilder(
|
||||||
|
builder: (BuildContext context, StateSetter setStateDialog) {
|
||||||
|
return SizedBox(
|
||||||
|
height: 350,
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(
|
||||||
|
horizontal: 0, vertical: 15),
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.end,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
_selectedTime1 == null
|
||||||
|
? ''
|
||||||
|
: _selectedTime1!.format(context),
|
||||||
|
style: TextStyle(
|
||||||
|
color: Colors.grey[500],
|
||||||
|
fontSize: 12,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
_selectedTime2 != null && _selectedTime1 != null
|
||||||
|
? Text(
|
||||||
|
' - ',
|
||||||
|
style: TextStyle(
|
||||||
|
color: Colors.grey[500],
|
||||||
|
fontSize: 12,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: const SizedBox(),
|
||||||
|
Text(
|
||||||
|
_selectedTime2 == null
|
||||||
|
? ''
|
||||||
|
: _selectedTime2!.format(context),
|
||||||
|
style: TextStyle(
|
||||||
|
color: Colors.grey[500],
|
||||||
|
fontSize: 12,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Text(
|
||||||
|
' | ',
|
||||||
|
style: TextStyle(
|
||||||
|
color: Colors.grey[500],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Text(
|
||||||
|
DateFormat('dd MMMM yyyy', 'es').format(today),
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 13,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 10),
|
||||||
|
child: TextFormField(
|
||||||
|
controller: _titleController,
|
||||||
|
decoration: const InputDecoration(hintText: 'Titulo'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(
|
||||||
|
horizontal: 10, vertical: 20),
|
||||||
|
child: TextFormField(
|
||||||
|
controller: _descriptionController,
|
||||||
|
decoration:
|
||||||
|
const InputDecoration(hintText: 'Descripción'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(bottom: 40),
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
SizedBox(
|
||||||
|
width: 80,
|
||||||
|
child: TextFormField(
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
onTap: () async {
|
||||||
|
var value = await _selectTime1(context);
|
||||||
|
setStateDialog(() {
|
||||||
|
_selectedTime1 = value;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
readOnly: true,
|
||||||
|
decoration: const InputDecoration(
|
||||||
|
hintText: 'Hora',
|
||||||
|
),
|
||||||
|
controller: TextEditingController(
|
||||||
|
text: _selectedTime1 == null
|
||||||
|
? ''
|
||||||
|
: ' ${_selectedTime1!.format(context)}'),
|
||||||
|
style: const TextStyle(fontSize: 15),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const Text(' - '),
|
||||||
|
SizedBox(
|
||||||
|
width: 80,
|
||||||
|
child: TextFormField(
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
onTap: () async {
|
||||||
|
var value = await _selectTime2(context);
|
||||||
|
setStateDialog(() {
|
||||||
|
_selectedTime2 = value;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
readOnly: true,
|
||||||
|
decoration: const InputDecoration(
|
||||||
|
hintText: 'Hora',
|
||||||
|
),
|
||||||
|
controller: TextEditingController(
|
||||||
|
text: _selectedTime2 == null
|
||||||
|
? ''
|
||||||
|
: ' ${_selectedTime2!.format(context)}'),
|
||||||
|
style: const TextStyle(fontSize: 15),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
PrimaryButtom(
|
||||||
|
onPressed: () async {
|
||||||
|
await eventoService
|
||||||
|
.createEvent(
|
||||||
|
_titleController.text,
|
||||||
|
_descriptionController.text,
|
||||||
|
today.toString(),
|
||||||
|
_selectedTime1!.format(context).toString(),
|
||||||
|
_selectedTime2!.format(context).toString(),
|
||||||
|
)
|
||||||
|
.then((value) {
|
||||||
|
Navigator.pop(context);
|
||||||
|
_titleController.text = '';
|
||||||
|
_descriptionController.text = '';
|
||||||
|
});
|
||||||
|
},
|
||||||
|
label: 'Añadir evento',
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _eventList() {
|
||||||
|
return FutureBuilder(
|
||||||
|
future: getByProId(),
|
||||||
|
builder: (BuildContext context, AsyncSnapshot<List<Event>> snapshot) {
|
||||||
|
if (!snapshot.hasData) {
|
||||||
|
return const Text('No tiene citas');
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Event> eventos = [];
|
||||||
|
|
||||||
|
try {
|
||||||
|
eventos.addAll(snapshot.data!);
|
||||||
|
} catch (e) {
|
||||||
|
print("SAPOAAAA" + e.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (eventos.isEmpty) {
|
||||||
|
return const Text('No tiene citas');
|
||||||
|
}
|
||||||
|
return Column(
|
||||||
|
children: [
|
||||||
|
...eventos.map(
|
||||||
|
(e) => ListTile(
|
||||||
|
leading: Text('${e.range1Hour1}'),
|
||||||
|
title: Text('${e.title}'),
|
||||||
|
trailing: Text('${e.day}'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user