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 'dart:convert'; import 'package:shared_preferences/shared_preferences.dart'; //import 'package:firebase_core/firebase_core.dart'; import 'dart:async'; import 'package:http/http.dart' as http; import 'model/event.dart'; void main() async{ var url = 'https://ada.uprrp.edu/~jorge.lopez19/FastMed/API/InsertEvent.php'; WidgetsFlutterBinding.ensureInitialized(); //==final data = await http.post(url, body: { //"name": name.text, //"reason": reason.text, //"date": date.text, //"time": time.text, // } //); runApp(Calendario()); } 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(), }, ); } } class MyHomePage extends StatefulWidget { @override _MyHomePageState createState() => _MyHomePageState(); } class _MyHomePageState extends State { CalendarController _controller; Map> _events; List _selectedEvents; @override void initState() { super.initState(); _controller = CalendarController(); _events = {}; _selectedEvents = []; } Map> _groupEvents(List events) { Map> 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 Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('Citas Disponibles'), ), body: StreamBuilder>( // stream: eventDBS.streamList(), builder: (context, snapshot) { if (snapshot.hasData) { List allEvents = snapshot.data; if (allEvents.isNotEmpty) { _events = _groupEvents(allEvents); } } return SingleChildScrollView( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ TableCalendar( events: _events, 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, 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'), ), ); } }