puntos base de datos
This commit is contained in:
@@ -42,7 +42,7 @@ Future<List<Event>> getByProId(String day) async {
|
|||||||
for (var element in snapshot.docs) {
|
for (var element in snapshot.docs) {
|
||||||
eventos.add(Event.fromJson(element.data()));
|
eventos.add(Event.fromJson(element.data()));
|
||||||
}
|
}
|
||||||
print('Error getByProId 1 $eventos');
|
print('eventos $eventos');
|
||||||
return eventos;
|
return eventos;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('Error getByProId $e');
|
print('Error getByProId $e');
|
||||||
@@ -77,4 +77,23 @@ class Event {
|
|||||||
profesionalId: json['profesional_id'],
|
profesionalId: json['profesional_id'],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Future<List<Event>> getEventsAllById(String uid) 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('eventos $eventos');
|
||||||
|
return eventos;
|
||||||
|
} catch (e) {
|
||||||
|
print('Error getByProId $e');
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
|
import 'dart:ffi';
|
||||||
|
|
||||||
|
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:prosappco/src/authentication/authentication_repository.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/components/primary_btn.dart';
|
||||||
import 'package:prosappco/src/models/event_model.dart';
|
import 'package:prosappco/src/models/event_model.dart';
|
||||||
@@ -13,6 +17,9 @@ class CalendarScreen extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _CalendarScreenState extends State<CalendarScreen> {
|
class _CalendarScreenState extends State<CalendarScreen> {
|
||||||
|
final uid = AuthenticationRepository.instance.getCurrentUserUid();
|
||||||
|
List<Event>? _events;
|
||||||
|
|
||||||
final _titleController = TextEditingController();
|
final _titleController = TextEditingController();
|
||||||
final _descriptionController = TextEditingController();
|
final _descriptionController = TextEditingController();
|
||||||
|
|
||||||
@@ -51,6 +58,12 @@ class _CalendarScreenState extends State<CalendarScreen> {
|
|||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
|
||||||
|
if (_events == null) {
|
||||||
|
Event.getEventsAllById(uid ?? "").then((value) => setState(() {
|
||||||
|
_events = value;
|
||||||
|
}));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onDaySelected(DateTime day, DateTime focusedDay) {
|
void _onDaySelected(DateTime day, DateTime focusedDay) {
|
||||||
@@ -67,11 +80,19 @@ class _CalendarScreenState extends State<CalendarScreen> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
if (_events == null) {
|
||||||
|
return const Center(
|
||||||
|
child: CircularProgressIndicator(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
var events = _events!;
|
||||||
// DateTime firstDay = today.subtract(Duration(days: 365));
|
// DateTime firstDay = today.subtract(Duration(days: 365));
|
||||||
DateTime lastDay = today.add(const Duration(days: 365));
|
DateTime lastDay = today.add(const Duration(days: 365));
|
||||||
|
|
||||||
return SafeArea(
|
return SafeArea(
|
||||||
child: Scaffold(
|
child: Scaffold(
|
||||||
|
resizeToAvoidBottomInset: false,
|
||||||
appBar: PopAppbar(
|
appBar: PopAppbar(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
@@ -92,6 +113,17 @@ class _CalendarScreenState extends State<CalendarScreen> {
|
|||||||
selectedDayPredicate: (day) => isSameDay(day, today),
|
selectedDayPredicate: (day) => isSameDay(day, today),
|
||||||
calendarFormat: _calendarFormat,
|
calendarFormat: _calendarFormat,
|
||||||
onFormatChanged: _onFormatChange,
|
onFormatChanged: _onFormatChange,
|
||||||
|
eventLoader: (date) {
|
||||||
|
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 {
|
availableCalendarFormats: const {
|
||||||
CalendarFormat.month: 'Mes',
|
CalendarFormat.month: 'Mes',
|
||||||
CalendarFormat.week: 'Semana',
|
CalendarFormat.week: 'Semana',
|
||||||
@@ -264,6 +296,12 @@ class _CalendarScreenState extends State<CalendarScreen> {
|
|||||||
_titleController.text = '';
|
_titleController.text = '';
|
||||||
_descriptionController.text = '';
|
_descriptionController.text = '';
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Event.getEventsAllById(uid ?? "").then(
|
||||||
|
(value) => setState(() {
|
||||||
|
_events = value;
|
||||||
|
}),
|
||||||
|
);
|
||||||
},
|
},
|
||||||
label: 'Añadir evento',
|
label: 'Añadir evento',
|
||||||
),
|
),
|
||||||
@@ -314,7 +352,7 @@ class _CalendarScreenState extends State<CalendarScreen> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
TextSpan(
|
TextSpan(
|
||||||
text: DateFormat('dd MMMM yyyy', 'es')
|
text: DateFormat('dd MMM', 'es')
|
||||||
.format(DateTime.parse(e.day!)),
|
.format(DateTime.parse(e.day!)),
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: Colors.grey[400],
|
color: Colors.grey[400],
|
||||||
|
|||||||
Reference in New Issue
Block a user