123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229 |
- import 'package:flutter/material.dart';
- import 'package:fast_med_flutter/ui/pages/add_event.dart';
- import 'package:fast_med_flutter/ui/pages/view_event.dart';
- import 'package:table_calendar/table_calendar.dart';
- import 'package:http/http.dart' as http;
-
- import 'package:fast_med_flutter/model/event.dart';
-
- // Dias de Citas No Disponibles
-
- final Map<DateTime, List> _holidays = {
- DateTime(2020, 11, 6): ['No Hay Citas'],
- DateTime(2020, 11, 3): ['Dia Elecciones'],
- DateTime(2020, 12, 25): ['Christmas'],
- DateTime(2020, 12, 31): ['Despedida del anyo nuevo'],
- DateTime(2021, 01, 01): ['Anyo Nuevo'],
- };
-
- //Iniciar la Seccion de las Citas
-
- void main() async{
-
- //Comunicacion con el servidor antes de iniciar el app
-
- var url = 'https://ada.uprrp.edu/~jorge.lopez19/FastMed/API/InsertEvent.php';
- WidgetsFlutterBinding.ensureInitialized();
- final data = await http.post(url, body: {
- });
- runApp(Calendario());
-
- }
-
- //Inicio del Area de las Citas Disponibles
-
- class Calendario extends StatelessWidget {
- @override
- Widget build(BuildContext context) {
- return MaterialApp(
- title: 'Citas Disponibles',
- theme: ThemeData(
- primarySwatch: Colors.blue,
- ),
- home: MyHomePage(),
- routes: {
- "add_event": (_) => AddEventPage(),
- },
- );
- }
- }
-
-
- // Define el homepage para el area de citas
-
- class MyHomePage extends StatefulWidget {
- @override
- _MyHomePageState createState() => _MyHomePageState();
- }
-
- class _MyHomePageState extends State<MyHomePage> {
- CalendarController _controller;
- Map<DateTime, List<dynamic>> _events;
- List<dynamic> _selectedEvents;
-
- @override
- void initState() {
- super.initState();
- final _selectedDay = DateTime.now();
- _controller = CalendarController();
- _events = {
- //Ejemplos de Citas Previamente Hechas de Prueba Para los Recordatorios
- _selectedDay.add(Duration(days: 3)): Set.from(
- [ 'Cita Cardiologo', 'Cita Dentista']).toList(),
- _selectedDay.add(Duration(days: 22)): [
- 'Cita Cardiologo',
- 'Cita Dentista'
- ],
- };
- _selectedEvents = _events[_selectedDay] ?? [];
- void _onDaySelected(DateTime day, List events, List holidays) {
- print('CALLBACK: _onDaySelected');
- setState(() {
- _selectedEvents = _events[_selectedDay] ?? [];
- });
- }
- }
-
- Map<String, dynamic> encodeMap(Map<DateTime, dynamic> map) {
- Map<String, dynamic> newMap = {};
- map.forEach((key, value) {
- newMap[key.toString()] = map[key];
- });
- return newMap;
- }
-
- Map<DateTime, List<dynamic>> _groupEvents(List<EventModel> events) {
- Map<DateTime, List<dynamic>> data = {};
- events.forEach((event) {
- DateTime date = DateTime(event.eventDate.year, event.eventDate.month,
- event.eventDate.day, 12);
- if (data[date] == null) data[date] = [];
- data[date].add(event);
- });
- return data;
- }
-
-
- @override
- //Marca en el calendario los dias que no esta disponibles para hacer horarios
- void _onDaySelected(DateTime day, List events, List holidays) {
- print('CALLBACK: _onDaySelected');
- setState(() {
- _selectedEvents = events;
- });
- }
-
- void _onVisibleDaysChanged(DateTime first, DateTime last,
- CalendarFormat format) {
- print('CALLBACK: _onVisibleDaysChanged');
- }
-
- void _onCalendarCreated(DateTime first, DateTime last,
- CalendarFormat format) {
- print('CALLBACK: _onCalendarCreated');
- }
-
- //Definimos los detalles del area de las citas
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- appBar: AppBar(
- title: Text('Citas Disponibles'),
- ),
- body: StreamBuilder<List<EventModel>>(
- // stream: eventDBS.streamList(),
- builder: (context, snapshot) {
- if (snapshot.hasData) {
- List<EventModel> allEvents = snapshot.data;
- if (allEvents.isNotEmpty) {
- _events = _groupEvents(allEvents);
- }
- }
-
- return SingleChildScrollView(
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: <Widget>[
- TableCalendar(
- events: _events,
- holidays: _holidays,
- initialCalendarFormat: CalendarFormat.month,
- calendarStyle: CalendarStyle(
- canEventMarkersOverflow: true,
- todayColor: Colors.orange,
- selectedColor: Theme
- .of(context)
- .primaryColor,
- todayStyle: TextStyle(
- fontWeight: FontWeight.bold,
- fontSize: 18.0,
- color: Colors.white)),
- headerStyle: HeaderStyle(
- centerHeaderTitle: true,
- formatButtonDecoration: BoxDecoration(
- color: Colors.orange,
- borderRadius: BorderRadius.circular(20.0),
- ),
- formatButtonTextStyle: TextStyle(color: Colors.white),
- formatButtonShowsNext: false,
- ),
- startingDayOfWeek: StartingDayOfWeek.monday,
- onVisibleDaysChanged: _onVisibleDaysChanged,
- onCalendarCreated: _onCalendarCreated,
-
- builders: CalendarBuilders(
- selectedDayBuilder: (context, date, events) =>
- Container(
- margin: const EdgeInsets.all(4.0),
- alignment: Alignment.center,
- decoration: BoxDecoration(
- color: Theme
- .of(context)
- .primaryColor,
- borderRadius: BorderRadius.circular(10.0)),
- child: Text(
- date.day.toString(),
- style: TextStyle(color: Colors.white),
- )),
- todayDayBuilder: (context, date, events) =>
- Container(
- margin: const EdgeInsets.all(4.0),
- alignment: Alignment.center,
- decoration: BoxDecoration(
- color: Colors.orange,
- borderRadius: BorderRadius.circular(10.0)),
- child: Text(
- date.day.toString(),
- style: TextStyle(color: Colors.white),
- )),
- ),
- calendarController: _controller,
- ),
- ..._selectedEvents.map((event) =>
- ListTile(
- title: Text(event.title),
- onTap: () {
- Navigator.push(
- context,
- MaterialPageRoute(
- builder: (_) =>
- EventDetailsPage(
- event: event,
- )));
- },
- )),
- ],
- ),
- );
- }
- ),
- floatingActionButton: FloatingActionButton(
- child: Icon(Icons.add),
- onPressed: () => Navigator.pushNamed(context, 'add_event'),
- ),
- );
- }
- }
-
-
|